Skip to content

Commit 20b170f

Browse files
committed
Fixes 2
1 parent f150fa4 commit 20b170f

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

plugwise/devices.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def update_from_dict(self, data: dict[str, Any]) -> None:
5757
class Gateway(DeviceBase):
5858
"""Plugwise Gateway class."""
5959

60-
super().__init__()
6160
binary_sensors: GatewayBinarySensors | None = None
6261
gateway_modes: list[str] | None = None
6362
hardware: str | None = None
@@ -68,25 +67,31 @@ class Gateway(DeviceBase):
6867
sensors: Weather | None = None
6968
zigbee_mac_address: str | None = None
7069

70+
def __init__(self) -> None:
71+
"""Init Gateway class and inherited functions."""
72+
super().__init__()
73+
7174
def update_from_dict(self, data: dict[str, Any]) -> None:
7275
"""Update this Gateway object with data from a dictionary."""
7376

7477
super().update_from_dict(data)
75-
self.binary_sensors.update_from_dict(data)
78+
if self.binary_sensors:
79+
self.binary_sensors.update_from_dict(data)
7680
self.gateway_modes = process_key(data, "gateway_mode")
7781
self.hardware = process_key(data, "gateway_mode")
7882
self.model_id = process_key(data, "gateway_mode")
7983
self.regulation_modes = process_key(data, "gateway_mode")
8084
self.select_gateway_mode = process_key(data, "gateway_mode")
81-
self.sensors.update_from_dict(data)
85+
if self.sensors:
86+
self.sensors.update_from_dict(data)
8287
self.zigbee_mac_address = process_key(data, "gateway_mode")
8388

8489

8590
@dataclass
8691
class GatewayBinarySensors:
8792
"""Gateway binary_sensors class."""
8893

89-
plugwise_notification: bool = False
94+
plugwise_notification: bool | None = None
9095

9196
def update_from_dict(self, data: dict[str, Any]) -> None:
9297
"""Update this GatewayBinarySensors object with data from a dictionary."""
@@ -285,8 +290,12 @@ class ZoneSensors:
285290
def update_from_dict(self, data: dict[str, Any]) -> None:
286291
"""Update this ZoneSensors object with data from a dictionary."""
287292

288-
self.electricity_consumed = process_dict(data, "sensors", "electricity_consumed")
289-
self.electricity_produced = process_dict(data, "sensors", "electricity_produced")
293+
self.electricity_consumed = process_dict(
294+
data, "sensors", "electricity_consumed"
295+
)
296+
self.electricity_produced = process_dict(
297+
data, "sensors", "electricity_produced"
298+
)
290299
self.temperature = process_dict(data, "sensors", "temperature")
291300

292301

@@ -405,7 +414,9 @@ def update_from_dict(self, data: dict[str, Any]) -> None:
405414
super().update_from_dict(data)
406415
self.available = process_key(data, "available")
407416
self.binary_sensors.update_from_dict(data)
408-
self.maximum_boiler_temperature = process_key(data, "maximum_boiler_temperature")
417+
self.maximum_boiler_temperature = process_key(
418+
data, "maximum_boiler_temperature"
419+
)
409420
self.max_dhw_temperature = process_key(data, "max_dhw_temperature")
410421
self.model_id = process_key(data, "model_id")
411422
self.sensors.update_from_dict(data)

0 commit comments

Comments
 (0)