Skip to content

Commit

Permalink
Fix Hydrawise zone addressing (home-assistant#97333)
Browse files Browse the repository at this point in the history
  • Loading branch information
dknowles2 authored Jul 27, 2023
1 parent cd1a99a commit 2542c5f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/hydrawise/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ def _handle_coordinator_update(self) -> None:
if self.entity_description.key == "status":
self._attr_is_on = self.coordinator.api.status == "All good!"
elif self.entity_description.key == "is_watering":
relay_data = self.coordinator.api.relays[self.data["relay"] - 1]
relay_data = self.coordinator.api.relays_by_zone_number[self.data["relay"]]
self._attr_is_on = relay_data["timestr"] == "Now"
super()._handle_coordinator_update()
2 changes: 1 addition & 1 deletion homeassistant/components/hydrawise/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HydrawiseSensor(HydrawiseEntity, SensorEntity):
def _handle_coordinator_update(self) -> None:
"""Get the latest data and updates the states."""
LOGGER.debug("Updating Hydrawise sensor: %s", self.name)
relay_data = self.coordinator.api.relays[self.data["relay"] - 1]
relay_data = self.coordinator.api.relays_by_zone_number[self.data["relay"]]
if self.entity_description.key == "watering_time":
if relay_data["timestr"] == "Now":
self._attr_native_value = int(relay_data["run"] / 60)
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/hydrawise/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ def __init__(

def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
relay_data = self.data["relay"] - 1
zone_number = self.data["relay"]
if self.entity_description.key == "manual_watering":
self.coordinator.api.run_zone(self._default_watering_timer, relay_data)
self.coordinator.api.run_zone(self._default_watering_timer, zone_number)
elif self.entity_description.key == "auto_watering":
self.coordinator.api.suspend_zone(0, relay_data)
self.coordinator.api.suspend_zone(0, zone_number)

def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""
relay_data = self.data["relay"] - 1
zone_number = self.data["relay"]
if self.entity_description.key == "manual_watering":
self.coordinator.api.run_zone(0, relay_data)
self.coordinator.api.run_zone(0, zone_number)
elif self.entity_description.key == "auto_watering":
self.coordinator.api.suspend_zone(365, relay_data)
self.coordinator.api.suspend_zone(365, zone_number)

@callback
def _handle_coordinator_update(self) -> None:
"""Update device state."""
relay_data = self.data["relay"] - 1
zone_number = self.data["relay"]
LOGGER.debug("Updating Hydrawise switch: %s", self.name)
timestr = self.coordinator.api.relays[relay_data]["timestr"]
timestr = self.coordinator.api.relays_by_zone_number[zone_number]["timestr"]
if self.entity_description.key == "manual_watering":
self._attr_is_on = timestr == "Now"
elif self.entity_description.key == "auto_watering":
Expand Down

0 comments on commit 2542c5f

Please sign in to comment.