Skip to content

Commit c09ae37

Browse files
authored
Merge pull request #687 from plugwise/more-improvin-II
More improvements
2 parents 82a7e0c + 2cec443 commit c09ae37

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

plugwise/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
class Smile(SmileComm):
41-
"""The Plugwise SmileConnect class."""
41+
"""The main Plugwise Smile API class."""
4242

4343
# pylint: disable=too-many-instance-attributes, too-many-public-methods
4444

@@ -91,7 +91,7 @@ def __init__(
9191
self.smile_zigbee_mac_address: str | None = None
9292

9393
async def connect(self) -> Version | None:
94-
"""Connect to Plugwise device and determine its name, type and version."""
94+
"""Connect to the Plugwise Gateway and determine its name, type, version, and other data."""
9595
result = await self._request(DOMAIN_OBJECTS)
9696
# Work-around for Stretch fw 2.7.18
9797
if not (vendor_names := result.findall("./module/vendor_name")):
@@ -186,7 +186,7 @@ async def connect(self) -> Version | None:
186186
async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
187187
"""Helper-function for connect().
188188
189-
Detect which type of Smile is connected.
189+
Detect which type of Plugwise Gateway is being connected.
190190
"""
191191
model: str = "Unknown"
192192
if (gateway := result.find("./gateway")) is not None:
@@ -260,7 +260,10 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
260260
async def _smile_detect_legacy(
261261
self, result: etree, dsmrmain: etree, model: str
262262
) -> str:
263-
"""Helper-function for _smile_detect()."""
263+
"""Helper-function for _smile_detect().
264+
265+
Detect which type of legacy Plugwise Gateway is being connected.
266+
"""
264267
return_model = model
265268
# Stretch: find the MAC of the zigbee master_controller (= Stick)
266269
if (network := result.find("./module/protocols/master_controller")) is not None:
@@ -305,15 +308,15 @@ async def _smile_detect_legacy(
305308
return return_model
306309

307310
async def full_xml_update(self) -> None:
308-
"""Helper-function used for testing."""
311+
"""Perform a first fetch of the Plugwise server XML data."""
309312
await self._smile_api.full_xml_update()
310313

311314
def get_all_gateway_entities(self) -> None:
312-
"""Helper-function used for testing."""
315+
"""Collect the Plugwise Gateway entities and their data and states from the received raw XML-data."""
313316
self._smile_api.get_all_gateway_entities()
314317

315318
async def async_update(self) -> PlugwiseData:
316-
"""Update the various entities and their states."""
319+
"""Update the Plughwise Gateway entities and their data and states."""
317320
data = PlugwiseData(devices={}, gateway={})
318321
try:
319322
data = await self._smile_api.async_update()

plugwise/helper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ def __init__(self) -> None:
275275
self.smile_type: str
276276
self.smile_version: version.Version | None
277277
self.smile_zigbee_mac_address: str | None
278-
self.therms_with_offset_func: list[str] = []
279278
self._zones: dict[str, GwEntityData] = {}
280279
SmileCommon.__init__(self)
281280

plugwise/legacy/smile.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
class SmileLegacyAPI(SmileLegacyData):
37-
"""The Plugwise SmileLegacyAPI class."""
37+
"""The Plugwise SmileLegacyAPI helper class for actual Plugwise legacy devices."""
3838

3939
# pylint: disable=too-many-instance-attributes, too-many-public-methods
4040

@@ -83,7 +83,7 @@ def __init__(
8383
self._previous_day_number: str = "0"
8484

8585
async def full_xml_update(self) -> None:
86-
"""Perform a first fetch of all XML data, needed for initialization."""
86+
"""Perform a first fetch of the Plugwise server XML data."""
8787
self._domain_objects = await self.request(DOMAIN_OBJECTS)
8888
self._locations = await self.request(LOCATIONS)
8989
self._modules = await self.request(MODULES)
@@ -92,24 +92,23 @@ async def full_xml_update(self) -> None:
9292
self._appliances = await self.request(APPLIANCES)
9393

9494
def get_all_gateway_entities(self) -> None:
95-
"""Collect the gateway entities from the received raw XML-data.
95+
"""Collect the Plugwise gateway entities and their data and states from the received raw XML-data.
9696
97-
Run this functions once to gather the initial device configuration,
98-
then regularly run async_update() to refresh the device data.
97+
First, collect all the connected entities and their initial data.
98+
Collect and add switching- and/or pump-group entities.
99+
Finally, collect the data and states for each entity.
99100
"""
100-
# Gather all the devices and their initial data
101101
self._all_appliances()
102-
103-
# Collect and add switching- and/or pump-group devices
104102
if group_data := self._get_group_switches():
105103
self.gw_entities.update(group_data)
106104

107-
# Collect the remaining data for all entities
108105
self._all_entity_data()
109106

110107
async def async_update(self) -> PlugwiseData:
111-
"""Perform an incremental update for updating the various device states."""
112-
# Perform a full update at day-change
108+
"""Perform an full update update at day-change: re-collect all gateway entities and their data and states.
109+
110+
Otherwise perform an incremental update: only collect the entities updated data and states.
111+
"""
113112
day_number = dt.datetime.now().strftime("%w")
114113
if (
115114
day_number # pylint: disable=consider-using-assignment-expr
@@ -129,7 +128,6 @@ async def async_update(self) -> PlugwiseData:
129128
raise DataMissingError(
130129
"No (full) Plugwise legacy data received"
131130
) from err
132-
# Otherwise perform an incremental update
133131
else:
134132
try:
135133
self._domain_objects = await self.request(DOMAIN_OBJECTS)

plugwise/smile.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,45 +93,47 @@ def __init__(
9393
self.smile_name = smile_name
9494
self.smile_type = smile_type
9595
self.smile_version = smile_version
96+
self.therms_with_offset_func: list[str] = []
9697
SmileData.__init__(self)
9798

9899
async def full_xml_update(self) -> None:
99-
"""Perform a first fetch of all XML data, needed for initialization."""
100+
"""Perform a first fetch of the Plugwise server XML data."""
100101
self._domain_objects = await self.request(DOMAIN_OBJECTS)
101102
self._get_plugwise_notifications()
102103

103104
def get_all_gateway_entities(self) -> None:
104-
"""Collect the gateway entities from the received raw XML-data.
105+
"""Collect the Plugwise gateway entities and their data and states from the received raw XML-data.
105106
106-
Run this functions once to gather the initial configuration,
107-
then regularly run async_update() to refresh the entity data.
107+
First, collect all the connected entities and their initial data.
108+
If a thermostat-gateway, collect a list of thermostats with offset-capability.
109+
Collect and add switching- and/or pump-group entities.
110+
Finally, collect the data and states for each entity.
108111
"""
109-
# Gather all the entities and their initial data
110112
self._all_appliances()
111113
if self._is_thermostat:
112-
if self.smile(ADAM):
113-
self._scan_thermostats()
114-
# Collect a list of thermostats with offset-capability
115114
self.therms_with_offset_func = (
116115
self._get_appliances_with_offset_functionality()
117116
)
117+
if self.smile(ADAM):
118+
self._scan_thermostats()
118119

119-
# Collect and add switching- and/or pump-group devices
120120
if group_data := self._get_group_switches():
121121
self.gw_entities.update(group_data)
122122

123-
# Collect the remaining data for all entities
124123
self._all_entity_data()
125124

126125
async def async_update(self) -> PlugwiseData:
127-
"""Perform an incremental update for updating the various device states."""
126+
"""Perform an full update: re-collect all gateway entities and their data and states.
127+
128+
Any change in the connected entities will be detected immediately.
129+
"""
128130
self.gw_data: GatewayData = {}
129131
self.gw_entities: dict[str, GwEntityData] = {}
130132
self._zones: dict[str, GwEntityData] = {}
131133
try:
132134
await self.full_xml_update()
133135
self.get_all_gateway_entities()
134-
# Set self._cooling_enabled - required for set_temperature,
136+
# Set self._cooling_enabled - required for set_temperature(),
135137
# also, check for a failed data-retrieval
136138
if "heater_id" in self.gw_data:
137139
heat_cooler = self.gw_entities[self.gw_data["heater_id"]]

0 commit comments

Comments
 (0)