Skip to content

Commit

Permalink
add laststoptime sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
dscao authored May 20, 2023
1 parent b17d0cf commit 1a3e71b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
14 changes: 8 additions & 6 deletions custom_components/autoamap/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CONF_SENSORS,
KEY_QUERYTIME,
KEY_PARKING_TIME,
KEY_LASTSTOPTIME,
KEY_ADDRESS,
)

Expand Down Expand Up @@ -154,13 +155,14 @@ async def async_step_user(self, user_input=None):
CONF_SENSORS,
default=self.config_entry.options.get(CONF_SENSORS)
): SelectSelector(
SelectSelectorConfig(
options=[
{"value": KEY_PARKING_TIME, "label": "parkingtime"}
],
multiple=True,translation_key=CONF_SENSORS
)
SelectSelectorConfig(
options=[
{"value": KEY_PARKING_TIME, "label": "parkingtime"},
{"value": KEY_LASTSTOPTIME, "label": "laststoptime"}
],
multiple=True,translation_key=CONF_SENSORS
)
)

}
),
Expand Down
1 change: 1 addition & 0 deletions custom_components/autoamap/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
KEY_ADDRESS = "address"
KEY_QUERYTIME = "querytime"
KEY_PARKING_TIME = "parkingtime"
KEY_LASTSTOPTIME = "laststoptime"

ATTR_SPEED = "speed"
ATTR_COURSE = "course"
Expand Down
11 changes: 11 additions & 0 deletions custom_components/autoamap/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
CONF_SENSORS,
ATTR_ADDRESS,
ATTR_PARKING_TIME,
ATTR_LASTSTOPTIME,
ATTR_QUERYTIME,
KEY_ADDRESS,
KEY_LASTSTOPTIME,
KEY_PARKING_TIME,
)

Expand All @@ -46,6 +48,11 @@
key=KEY_PARKING_TIME,
name="parkingtime",
icon="mdi:timer-stop-outline"
),
SensorEntityDescription(
key=KEY_LASTSTOPTIME,
name="laststoptime",
icon="mdi:timer-stop"
)
)

Expand Down Expand Up @@ -93,6 +100,8 @@ def __init__(self, device_name, description, coordinator):
self._attr_translation_key = f"{self.entity_description.name}"
if self.entity_description.key == KEY_PARKING_TIME:
self._state = self.coordinator.data.get(ATTR_PARKING_TIME)
elif self.entity_description.key == KEY_LASTSTOPTIME:
self._state = self.coordinator.data.get(ATTR_LASTSTOPTIME)
elif self.entity_description.key == KEY_ADDRESS:
if self.coordinator.data.get(ATTR_ADDRESS):
self._state = self.coordinator.data.get(ATTR_ADDRESS)
Expand Down Expand Up @@ -155,6 +164,8 @@ async def async_update(self):

if self.entity_description.key == KEY_PARKING_TIME:
self._state = self.coordinator.data.get(ATTR_PARKING_TIME)
elif self.entity_description.key == KEY_LASTSTOPTIME:
self._state = self.coordinator.data.get(ATTR_LASTSTOPTIME)
elif self.entity_description.key == KEY_ADDRESS:
if self.coordinator.data.get(ATTR_ADDRESS):
self._state = self.coordinator.data.get(ATTR_ADDRESS)
Expand Down
8 changes: 4 additions & 4 deletions custom_components/autoamap/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"selector": {
"sensors": {
"options": {
"last_update": "Last_update",
"laststoptime": "Last stop time",
"parkingtime": "Parking Time"
}
}
Expand Down Expand Up @@ -113,15 +113,15 @@
},
"sensor": {
"parkingtime": {
"name": "parking time",
"name": "Parking time",
"state_attributes": {
"querytime": {
"name": "query time"
}
}
},
"last_update": {
"name": "last_update"
"laststoptime": {
"name": "Last Stop time"
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions custom_components/autoamap/translations/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"selector": {
"sensors": {
"options": {
"last_update": "最后更新",
"laststoptime": "上次停止时间",
"parkingtime": "停车时长"
}
}
Expand Down Expand Up @@ -120,9 +120,9 @@
}
}
},
"last_update": {
"name": "最后更新"
"laststoptime": {
"name": "上次停止时间"
}
}
}
}
}

0 comments on commit 1a3e71b

Please sign in to comment.