Skip to content

Commit

Permalink
Add status minor refactor on attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Feb 19, 2021
1 parent d159f5b commit cfeed1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions custom_components/irrigation_unlimited/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,22 +132,24 @@ 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

@property
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:
Expand Down
4 changes: 2 additions & 2 deletions examples/card.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,7 +89,7 @@ entities:
secondary_info:
attribute: enabled
entities:
- attribute: schedules
- attribute: schedule_count
name: Schedules
- attribute: adjustment
name: Adjustment
Expand Down

0 comments on commit cfeed1f

Please sign in to comment.