From f08017f52f3bc898cf3bb3569e05c7ed9c3433b7 Mon Sep 17 00:00:00 2001 From: SLaks Date: Tue, 19 Mar 2024 11:47:14 -0400 Subject: [PATCH] Roborock: Specify additional sensor attributes Using enum with options shows a dropdown of available values when building conditions or triggers in HA. --- .../roborock/vacuum/vacuumcontainers.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/miio/integrations/roborock/vacuum/vacuumcontainers.py b/miio/integrations/roborock/vacuum/vacuumcontainers.py index 1783ad332..7af2afce8 100644 --- a/miio/integrations/roborock/vacuum/vacuumcontainers.py +++ b/miio/integrations/roborock/vacuum/vacuumcontainers.py @@ -186,7 +186,12 @@ def state_code(self) -> int: return int(self.data["state"]) @property - @sensor("State", entity_category="diagnostic") + @sensor( + "State", + device_class="enum", + entity_category="diagnostic", + options=list(STATE_CODE_TO_STRING.values()), + ) def state(self) -> str: """Human readable state description, see also :func:`state_code`.""" return STATE_CODE_TO_STRING.get( @@ -327,7 +332,12 @@ def clean_time(self) -> timedelta: return pretty_seconds(self.data["clean_time"]) @property - @sensor("Current clean area", unit="m²", icon="mdi:texture-box") + @sensor( + "Current clean area", + unit="m²", + icon="mdi:texture-box", + suggested_display_precision=2, + ) def clean_area(self) -> float: """Cleaned area in m2.""" return pretty_area(self.data["clean_area"]) @@ -502,6 +512,7 @@ def total_duration(self) -> timedelta: unit="m²", icon="mdi:texture-box", entity_category="diagnostic", + suggested_display_precision=2, ) def total_area(self) -> float: """Total cleaned area.""" @@ -598,6 +609,7 @@ def duration(self) -> timedelta: unit="m²", icon="mdi:texture-box", entity_category="diagnostic", + suggested_display_precision=2, ) def area(self) -> float: """Total cleaned area."""