From 4d2a426d7494d05be72425e4c4f2f8eff943bec3 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 11 Jan 2025 09:59:48 +0100 Subject: [PATCH 1/3] Revert "More docstring improvements" This reverts commit 61ef70fb8b18e9367335f165ba7129fa5869da8b. --- plugwise/__init__.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index f3ec837cb..98109bf88 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -186,7 +186,7 @@ async def connect(self) -> Version | None: async def _smile_detect(self, result: etree, dsmrmain: etree) -> None: """Helper-function for connect(). - Detect which type of Plugwise Gateway is being connected. + Detect which type of Smile is connected. """ model: str = "Unknown" if (gateway := result.find("./gateway")) is not None: @@ -260,10 +260,7 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None: async def _smile_detect_legacy( self, result: etree, dsmrmain: etree, model: str ) -> str: - """Helper-function for _smile_detect(). - - Detect which type of legacy Plugwise Gateway is being connected. - """ + """Helper-function for _smile_detect().""" return_model = model # Stretch: find the MAC of the zigbee master_controller (= Stick) if (network := result.find("./module/protocols/master_controller")) is not None: From c724add948c0db34862570a03669865c0d788e5a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 11 Jan 2025 09:59:58 +0100 Subject: [PATCH 2/3] Revert "Improve main function docstrings" This reverts commit 925ac8d857c4cc972ab863c7328c570525516ee6. --- plugwise/__init__.py | 6 +++--- plugwise/legacy/smile.py | 20 +++++++++++--------- plugwise/smile.py | 25 ++++++++++++------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 98109bf88..0139bba0d 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -305,15 +305,15 @@ async def _smile_detect_legacy( return return_model async def full_xml_update(self) -> None: - """Perform a first fetch of the Plugwise server XML data.""" + """Helper-function used for testing.""" await self._smile_api.full_xml_update() def get_all_gateway_entities(self) -> None: - """Collect the Plugwise gateway entities and their data and states from the received raw XML-data.""" + """Helper-function used for testing.""" self._smile_api.get_all_gateway_entities() async def async_update(self) -> PlugwiseData: - """Update the Plughwise gateway entities and their data and states.""" + """Update the various entities and their states.""" data = PlugwiseData(devices={}, gateway={}) try: data = await self._smile_api.async_update() diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index e0ff4d21f..d5be6832e 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -83,7 +83,7 @@ def __init__( self._previous_day_number: str = "0" async def full_xml_update(self) -> None: - """Perform a first fetch of the Plugwise server XML data.""" + """Perform a first fetch of all XML data, needed for initialization.""" self._domain_objects = await self.request(DOMAIN_OBJECTS) self._locations = await self.request(LOCATIONS) self._modules = await self.request(MODULES) @@ -92,23 +92,24 @@ async def full_xml_update(self) -> None: self._appliances = await self.request(APPLIANCES) def get_all_gateway_entities(self) -> None: - """Collect the Plugwise gateway entities and their data and states from the received raw XML-data. + """Collect the gateway entities from the received raw XML-data. - First, collect all the connected entities and their initial data. - Collect and add switching- and/or pump-group entities. - Finally, collect the data and states for each entity. + Run this functions once to gather the initial device configuration, + then regularly run async_update() to refresh the device data. """ + # Gather all the devices and their initial data self._all_appliances() + + # Collect and add switching- and/or pump-group devices if group_data := self._get_group_switches(): self.gw_entities.update(group_data) + # Collect the remaining data for all entities self._all_entity_data() async def async_update(self) -> PlugwiseData: - """Perform an full update update at day-change: re-collect all gateway entities and their data and states. - - Otherwise perform an incremental update: only collect the entities updated data and states. - """ + """Perform an incremental update for updating the various device states.""" + # Perform a full update at day-change day_number = dt.datetime.now().strftime("%w") if ( day_number # pylint: disable=consider-using-assignment-expr @@ -128,6 +129,7 @@ async def async_update(self) -> PlugwiseData: raise DataMissingError( "No (full) Plugwise legacy data received" ) from err + # Otherwise perform an incremental update else: try: self._domain_objects = await self.request(DOMAIN_OBJECTS) diff --git a/plugwise/smile.py b/plugwise/smile.py index cd2ed0dca..26b31fb97 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -97,43 +97,42 @@ def __init__( SmileData.__init__(self) async def full_xml_update(self) -> None: - """Perform a first fetch of the Plugwise server XML data.""" + """Perform a first fetch of all XML data, needed for initialization.""" self._domain_objects = await self.request(DOMAIN_OBJECTS) self._get_plugwise_notifications() def get_all_gateway_entities(self) -> None: - """Collect the Plugwise gateway entities and their data and states from the received raw XML-data. + """Collect the gateway entities from the received raw XML-data. - First, collect all the connected entities and their initial data. - If a thermostat-gateway, collect a list of thermostats with offset-capability. - Collect and add switching- and/or pump-group entities. - Finally, collect the data and states for each entity. + Run this functions once to gather the initial configuration, + then regularly run async_update() to refresh the entity data. """ + # Gather all the entities and their initial data self._all_appliances() if self._is_thermostat: + if self.smile(ADAM): + self._scan_thermostats() + # Collect a list of thermostats with offset-capability self.therms_with_offset_func = ( self._get_appliances_with_offset_functionality() ) - if self.smile(ADAM): - self._scan_thermostats() + # Collect and add switching- and/or pump-group devices if group_data := self._get_group_switches(): self.gw_entities.update(group_data) + # Collect the remaining data for all entities self._all_entity_data() async def async_update(self) -> PlugwiseData: - """Perform an full update: re-collect all gateway entities and their data and states. - - Any change in the connected entities will be detected immediately. - """ + """Perform an incremental update for updating the various device states.""" self.gw_data: GatewayData = {} self.gw_entities: dict[str, GwEntityData] = {} self._zones: dict[str, GwEntityData] = {} try: await self.full_xml_update() self.get_all_gateway_entities() - # Set self._cooling_enabled - required for set_temperature(), + # Set self._cooling_enabled - required for set_temperature, # also, check for a failed data-retrieval if "heater_id" in self.gw_data: heat_cooler = self.gw_entities[self.gw_data["heater_id"]] From 6fd9fdcd2a4ffab36be84f92a8c5b8a4aa9ed775 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sat, 11 Jan 2025 10:00:07 +0100 Subject: [PATCH 3/3] Revert "Move self.therms_with_offset_func init" This reverts commit a9ae3bd5bf4959be31f42343268665d3225b731f. --- plugwise/helper.py | 1 + plugwise/smile.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index a51ae02ea..7281730e5 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -275,6 +275,7 @@ def __init__(self) -> None: self.smile_type: str self.smile_version: version.Version | None self.smile_zigbee_mac_address: str | None + self.therms_with_offset_func: list[str] = [] self._zones: dict[str, GwEntityData] = {} SmileCommon.__init__(self) diff --git a/plugwise/smile.py b/plugwise/smile.py index 26b31fb97..94bfebcfb 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -93,7 +93,6 @@ def __init__( self.smile_name = smile_name self.smile_type = smile_type self.smile_version = smile_version - self.therms_with_offset_func: list[str] = [] SmileData.__init__(self) async def full_xml_update(self) -> None: