Skip to content

Commit c1c186d

Browse files
committed
Add devices property, replacing the PlugwiseData output
1 parent 3be6b1c commit c1c186d

File tree

9 files changed

+32
-41
lines changed

9 files changed

+32
-41
lines changed

plugwise/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
SMILES,
1818
STATUS,
1919
SYSTEM,
20-
PlugwiseData,
20+
GwEntityData,
2121
SmileProps,
2222
ThermoLoc,
2323
)
@@ -63,6 +63,7 @@ def __init__(
6363
)
6464

6565
self._cooling_present = False
66+
self._devices: dict[str, GwEntityData] = {}
6667
self._elga = False
6768
self._is_thermostat = False
6869
self._last_active: dict[str, str | None] = {}
@@ -92,6 +93,11 @@ def cooling_present(self) -> bool:
9293
return self._smile_props["cooling_present"]
9394
return False
9495

96+
@property
97+
def devices(self) -> dict[str, GwEntityData]:
98+
"""Return all devices and their data."""
99+
return self._devices
100+
95101
@property
96102
def gateway_id(self) -> str:
97103
"""Return the gateway-id."""
@@ -338,16 +344,13 @@ def get_all_gateway_entities(self) -> None:
338344
"""Collect the Plugwise Gateway entities and their data and states from the received raw XML-data."""
339345
self._smile_api.get_all_gateway_entities()
340346

341-
async def async_update(self) -> PlugwiseData:
347+
async def async_update(self) -> None:
342348
"""Update the Plughwise Gateway entities and their data and states."""
343-
data = PlugwiseData(devices={}, gateway={})
344349
try:
345-
data = await self._smile_api.async_update()
350+
self._devices = await self._smile_api.async_update()
346351
except (DataMissingError, KeyError) as err:
347352
raise PlugwiseError("No Plugwise data received") from err
348353

349-
return data
350-
351354
########################################################################################################
352355
### API Set and HA Service-related Functions ###
353356
########################################################################################################

plugwise/constants.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from collections import namedtuple
6-
from dataclasses import dataclass
76
import logging
87
from typing import Final, Literal, TypedDict, get_args
98

@@ -577,11 +576,3 @@ class GwEntityData(TypedDict, total=False):
577576
switches: SmileSwitches
578577
temperature_offset: ActuatorData
579578
thermostat: ActuatorData
580-
581-
582-
@dataclass
583-
class PlugwiseData:
584-
"""Plugwise data provided as output."""
585-
586-
devices: dict[str, GwEntityData]
587-
gateway: SmileProps

plugwise/data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SmileData(SmileHelper):
2828
def __init__(self) -> None:
2929
"""Init."""
3030
self._smile_props: SmileProps
31+
self.gw_entities: dict[str, GwEntityData]
3132
SmileHelper.__init__(self)
3233

3334
def _all_entity_data(self) -> None:

plugwise/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(self) -> None:
109109
self._cooling_active = False
110110
self._cooling_enabled = False
111111

112-
self.gw_entities: dict[str, GwEntityData] = {}
112+
self.gw_entities: dict[str, GwEntityData]
113113
self.smile_hw_version: str | None
114114
self.smile_mac_address: str | None
115115
self.smile_model: str
@@ -118,7 +118,7 @@ def __init__(self) -> None:
118118
self.smile_type: str
119119
self.smile_version: version.Version | None
120120
self.smile_zigbee_mac_address: str | None
121-
self._zones: dict[str, GwEntityData] = {}
121+
self._zones: dict[str, GwEntityData]
122122
SmileCommon.__init__(self)
123123

124124
def _all_appliances(self) -> None:

plugwise/legacy/smile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
REQUIRE_APPLIANCES,
2020
RULES,
2121
GwEntityData,
22-
PlugwiseData,
2322
SmileProps,
2423
ThermoLoc,
2524
)
@@ -98,7 +97,7 @@ def get_all_gateway_entities(self) -> None:
9897

9998
self._all_entity_data()
10099

101-
async def async_update(self) -> PlugwiseData:
100+
async def async_update(self) -> dict[str, GwEntityData]:
102101
"""Perform an full update update at day-change: re-collect all gateway entities and their data and states.
103102
104103
Otherwise perform an incremental update: only collect the entities updated data and states.
@@ -137,10 +136,7 @@ async def async_update(self) -> PlugwiseData:
137136
raise DataMissingError("No legacy Plugwise data received") from err
138137

139138
self._previous_day_number = day_number
140-
return PlugwiseData(
141-
devices=self.gw_entities,
142-
gateway=self._smile_props,
143-
)
139+
return self.gw_entities
144140

145141
########################################################################################################
146142
### API Set and HA Service-related Functions ###

plugwise/smile.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
OFF,
2424
RULES,
2525
GwEntityData,
26-
PlugwiseData,
2726
SmileProps,
2827
ThermoLoc,
2928
)
@@ -114,7 +113,7 @@ def get_all_gateway_entities(self) -> None:
114113

115114
self._all_entity_data()
116115

117-
async def async_update(self) -> PlugwiseData:
116+
async def async_update(self) -> dict[str, GwEntityData]:
118117
"""Perform an full update: re-collect all gateway entities and their data and states.
119118
120119
Any change in the connected entities will be detected immediately.
@@ -140,10 +139,7 @@ async def async_update(self) -> PlugwiseData:
140139
except KeyError as err:
141140
raise DataMissingError("No Plugwise actual data received") from err
142141

143-
return PlugwiseData(
144-
devices=self.gw_entities,
145-
gateway=self._smile_props,
146-
)
142+
return self.gw_entities
147143

148144
########################################################################################################
149145
### API Set and HA Service-related Functions ###

tests/test_adam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async def test_connect_adam_plus_anna_new(self):
5252
"f2bf9048bef64cc5b6d5110154e33c81",
5353
"f871b8c4d63549319221e294e4f88074",
5454
]
55+
assert smile.reboot
5556

5657
result = await self.tinker_thermostat(
5758
smile,

tests/test_init.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,19 @@ def test_and_assert(test_dict, data, header):
608608
if smile.smile_legacy:
609609
await smile.full_xml_update()
610610
smile.get_all_gateway_entities()
611-
data = await smile.async_update()
611+
await smile.async_update()
612612
assert smile._timeout == 30
613613
else:
614-
data = await smile.async_update()
614+
await smile.async_update()
615615
assert smile._timeout == 10
616616
else:
617617
_LOGGER.info("Asserting updated testdata:")
618-
data = await smile.async_update()
618+
await smile.async_update()
619+
620+
_LOGGER.info("Gateway id = %s", smile.gateway_id)
621+
_LOGGER.info("Heater id = %s", smile.heater_id)
622+
_LOGGER.info("Hostname = %s", smile.smile_hostname)
623+
_LOGGER.info("Entities list = %s", smile.devices)
619624

620625
self.cooling_present = smile.cooling_present
621626
self.notifications = smile.notifications
@@ -624,7 +629,7 @@ def test_and_assert(test_dict, data, header):
624629
self._cooling_active = False
625630
self._cooling_enabled = False
626631
if smile.heater_id != "None":
627-
heat_cooler = data.devices[smile.heater_id]
632+
heat_cooler = smile.devices[smile.heater_id]
628633
if "binary_sensors" in heat_cooler:
629634
if "cooling_enabled" in heat_cooler["binary_sensors"]:
630635
self._cooling_enabled = heat_cooler["binary_sensors"][
@@ -635,27 +640,24 @@ def test_and_assert(test_dict, data, header):
635640
"cooling_state"
636641
]
637642

638-
self._write_json("all_data", {"devices": data.devices, "gateway": data.gateway})
643+
self._write_json("all_data", {"devices": smile.devices})
639644

640645
if "FIXTURES" in os.environ:
641646
_LOGGER.info("Skipping tests: Requested fixtures only") # pragma: no cover
642647
return # pragma: no cover
643648

644-
self.entity_list = list(data.devices.keys())
649+
self.entity_list = list(smile.devices.keys())
645650
location_list = smile._loc_data
646651

647-
_LOGGER.info("Gateway id = %s", smile.gateway_id)
648-
_LOGGER.info("Hostname = %s", smile.smile_hostname)
649-
_LOGGER.info("Gateway data = %s", data.gateway)
650-
_LOGGER.info("Entities list = %s", data.devices)
651-
self.show_setup(location_list, data.devices)
652+
653+
self.show_setup(location_list, smile.devices)
652654

653655
if skip_testing:
654656
return
655657

656658
# Perform tests and asserts in two steps: devices and zones
657659
for header, data_dict in testdata.items():
658-
test_and_assert(data_dict, data.devices, header)
660+
test_and_assert(data_dict, smile.devices, header)
659661

660662
# pragma warning restore S3776
661663

tests/test_legacy_anna.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async def test_connect_legacy_anna(self):
3131
await self.device_test(smile, "2020-03-22 00:00:01", testdata)
3232
assert smile.gateway_id == "0000aaaa0000aaaa0000aaaa0000aa00"
3333
assert self.entity_items == 41
34+
assert not smile.reboot
3435

3536
result = await self.tinker_legacy_thermostat(smile, schedule_on=False)
3637
assert result

0 commit comments

Comments
 (0)