mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add Roomba last mission sensor (#123048)
* Roomba: add last mission sensor * Set sensor as unavailable if last mission timestamp is 0 Previously, if the `mssnStrtTm` was 0, the function would return a 1970-01-01 (Unix epoch start date). With this change, the function will return None if the timestamp is 0 and the sensor will become unavailable. * Update last_mission property to use dt_util.utc_from_timestamp
This commit is contained in:
parent
2d0ccf84f9
commit
8324360045
@ -32,6 +32,9 @@
|
||||
},
|
||||
"total_cleaned_area": {
|
||||
"default": "mdi:texture-box"
|
||||
},
|
||||
"last_mission": {
|
||||
"default": "mdi:calendar-clock"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +118,15 @@ class IRobotEntity(Entity):
|
||||
"""Return the battery stats."""
|
||||
return self.vacuum_state.get("bbchg3", {})
|
||||
|
||||
@property
|
||||
def last_mission(self):
|
||||
"""Return last mission start time."""
|
||||
if (
|
||||
ts := self.vacuum_state.get("cleanMissionStatus", {}).get("mssnStrtTm")
|
||||
) is None or ts == 0:
|
||||
return None
|
||||
return dt_util.utc_from_timestamp(ts)
|
||||
|
||||
@property
|
||||
def _robot_state(self):
|
||||
"""Return the state of the vacuum cleaner."""
|
||||
|
@ -116,6 +116,14 @@ SENSORS: list[RoombaSensorEntityDescription] = [
|
||||
suggested_display_precision=0,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
RoombaSensorEntityDescription(
|
||||
key="last_mission",
|
||||
translation_key="last_mission",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda self: self.last_mission,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
@ -87,6 +87,9 @@
|
||||
},
|
||||
"total_cleaned_area": {
|
||||
"name": "Total cleaned area"
|
||||
},
|
||||
"last_mission": {
|
||||
"name": "Last mission start time"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user