From cfeed1fd2434c3f4709815cac42d6dd67df7be62 Mon Sep 17 00:00:00 2001 From: rgc99 Date: Fri, 19 Feb 2021 00:22:30 +0000 Subject: [PATCH] Add status minor refactor on attributes --- .../irrigation_unlimited/binary_sensor.py | 21 +++++++++++-------- examples/card.yaml | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/custom_components/irrigation_unlimited/binary_sensor.py b/custom_components/irrigation_unlimited/binary_sensor.py index 5cb9078..7933876 100644 --- a/custom_components/irrigation_unlimited/binary_sensor.py +++ b/custom_components/irrigation_unlimited/binary_sensor.py @@ -79,7 +79,8 @@ def device_state_attributes(self): """Return the state attributes of the device.""" attr = {} attr["enabled"] = self._controller.enabled - attr["zones"] = len(self._controller._zones) + attr["zone_count"] = len(self._controller._zones) + attr["zones"] = "" current = self._controller.runs.current_run if current is not None: attr["current_zone"] = current.index + 1 @@ -131,13 +132,13 @@ def should_poll(self): def icon(self): """Return the icon to use in the frontend.""" if self._controller.enabled: - if self._zone.enabled: - if self._zone.is_on: - return ICON_ON + if self._zone.enabled: + if self._zone.is_on: + return ICON_ON + else: + return ICON_OFF else: - return ICON_OFF - else: - return ICON_DISABLED + return ICON_DISABLED else: return ICON_BLOCKED @@ -145,8 +146,10 @@ def icon(self): def device_state_attributes(self): """Return the state attributes of the device.""" attr = {} - attr["enabled"] = self._zone.enabled - attr["schedules"] = len(self._zone.schedules) + attr["enabled"] = self._zone.enabled and self._controller.enabled + attr["status"] = self._zone.status + attr["schedule_count"] = len(self._zone.schedules) + attr["schedules"] = "" attr["adjustment"] = self._zone.adjustment.as_string current = self._zone.runs.current_run if current is not None: diff --git a/examples/card.yaml b/examples/card.yaml index db5db0d..a08f36e 100644 --- a/examples/card.yaml +++ b/examples/card.yaml @@ -35,7 +35,7 @@ entities: secondary_info: attribute: enabled entities: - - attribute: zones + - attribute: zone_count name: Zones - type: 'custom:multiple-entity-row' entity: binary_sensor.irrigation_unlimited_c1_m @@ -89,7 +89,7 @@ entities: secondary_info: attribute: enabled entities: - - attribute: schedules + - attribute: schedule_count name: Schedules - attribute: adjustment name: Adjustment