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:
Krzysztof Dąbrowski 2024-09-10 17:04:25 +02:00 committed by GitHub
parent 2d0ccf84f9
commit 8324360045
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View File

@ -32,6 +32,9 @@
},
"total_cleaned_area": {
"default": "mdi:texture-box"
},
"last_mission": {
"default": "mdi:calendar-clock"
}
}
}

View File

@ -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."""

View File

@ -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,
),
]

View File

@ -87,6 +87,9 @@
},
"total_cleaned_area": {
"name": "Total cleaned area"
},
"last_mission": {
"name": "Last mission start time"
}
}
}