Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
bouwew committed Oct 7, 2024
1 parent 84c5245 commit bcce9cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions plugwise/smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ async def async_update(self) -> PlugwiseData:
await self.full_update_device()
self.get_all_devices()
if "heater_id" in self.gw_data:
self._heater_id = self.gw_data["heater_id"]
heat_cooler = self.gw_devices[self.gw_data["heater_id"]]
if (
"binary_sensors" in self.gw_devices[self._heater_id]
and "cooling_enabled" in self.gw_devices[self._heater_id]["binary_sensors"]
"binary_sensors" in heat_cooler
and "cooling_enabled" in heat_cooler["binary_sensors"]
):
self._cooling_enabled = self.gw_devices[self._heater_id]["binary_sensors"]["cooling_enabled"]
self._cooling_enabled = heat_cooler["binary_sensors"]["cooling_enabled"]
except KeyError as err:
raise DataMissingError("No Plugwise data received") from err

Expand Down
12 changes: 6 additions & 6 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,12 +574,12 @@ async def device_test(
self._cooling_active = False
self._cooling_enabled = False
if "heater_id" in data.gateway:
heater_id = data.gateway["heater_id"]
if "binary_sensors" in data.devices[heater_id]:
if "cooling_enabled" in data.devices[heater_id]["binary_sensors"]:
self._cooling_enabled = data.devices[heater_id]["binary_sensors"]["cooling_enabled"]
if "cooling_state" in data.devices[heater_id]["binary_sensors"]:
self._cooling_active = data.devices[heater_id]["binary_sensors"]["cooling_state"]
heat_cooler = data.devices[data.gateway["heater_id"]]
if "binary_sensors" in heat_cooler:
if "cooling_enabled" in heat_cooler["binary_sensors"]:
self._cooling_enabled = heat_cooler["binary_sensors"]["cooling_enabled"]
if "cooling_state" in heat_cooler["binary_sensors"]:
self._cooling_active = heat_cooler["binary_sensors"]["cooling_state"]

self._write_json("all_data", {"gateway": data.gateway, "devices": data.devices})

Expand Down

0 comments on commit bcce9cb

Please sign in to comment.