Skip to content

Commit 417f4d5

Browse files
authored
Merge pull request #716 from plugwise/inheritance
Further improvements: - Properly init subclasses. - Replace use of SmileProps dict by defining properties at relevant subclasses. These properties can be reached via `_smile_api`. - Remove use of pylint_per_file_ignores plugin
2 parents 5ad6992 + 5803c17 commit 417f4d5

File tree

11 files changed

+65
-80
lines changed

11 files changed

+65
-80
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Ongoing
44

55
- Improve readability of xml-data in POST/PUT requests via [#707](https://github.com/plugwise/python-plugwise/pull/707), [#708](https://github.com/plugwise/python-plugwise/pull/708) and [#715](https://github.com/plugwise/python-plugwise/pull/715)
6-
- Continuous improvements via [#711](https://github.com/plugwise/python-plugwise/pull/711) and [#713](https://github.com/plugwise/python-plugwise/pull/713)
6+
- Continuous improvements via [#711](https://github.com/plugwise/python-plugwise/pull/711), [#713](https://github.com/plugwise/python-plugwise/pull/713) and [#716](https://github.com/plugwise/python-plugwise/pull/716)
77

88
## v1.7.2
99

plugwise/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
STATUS,
1919
SYSTEM,
2020
GwEntityData,
21-
SmileProps,
2221
ThermoLoc,
2322
)
2423
from plugwise.exceptions import (
@@ -69,7 +68,6 @@ def __init__(
6968
self._opentherm_device = False
7069
self._schedule_old_states: dict[str, dict[str, str]] = {}
7170
self._smile_api: SmileAPI | SmileLegacyAPI
72-
self._smile_props: SmileProps = {}
7371
self._stretch_v2 = False
7472
self._target_smile: str = NONE
7573
self.smile_hostname: str = NONE
@@ -86,26 +84,22 @@ def __init__(
8684
@property
8785
def cooling_present(self) -> bool:
8886
"""Return the cooling capability."""
89-
if "cooling_present" in self._smile_props:
90-
return self._smile_props["cooling_present"]
91-
return False
87+
return self._smile_api.cooling_present
9288

9389
@property
9490
def gateway_id(self) -> str:
9591
"""Return the gateway-id."""
96-
return self._smile_props["gateway_id"]
92+
return self._smile_api.gateway_id
9793

9894
@property
9995
def heater_id(self) -> str:
10096
"""Return the heater-id."""
101-
if "heater_id" in self._smile_props:
102-
return self._smile_props["heater_id"]
103-
return NONE
97+
return self._smile_api.heater_id
10498

10599
@property
106100
def item_count(self) -> int:
107101
"""Return the item-count."""
108-
return self._smile_props["item_count"]
102+
return self._smile_api.item_count
109103

110104
@property
111105
def reboot(self) -> bool:
@@ -162,7 +156,6 @@ async def connect(self) -> Version:
162156
self._opentherm_device,
163157
self._request,
164158
self._schedule_old_states,
165-
self._smile_props,
166159
self.smile_hostname,
167160
self.smile_hw_version,
168161
self.smile_mac_address,
@@ -179,7 +172,6 @@ async def connect(self) -> Version:
179172
self._on_off_device,
180173
self._opentherm_device,
181174
self._request,
182-
self._smile_props,
183175
self._stretch_v2,
184176
self._target_smile,
185177
self.smile_hostname,

plugwise/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def __init__(self) -> None:
5858
self.smile_name: str
5959
self.smile_type: str
6060

61+
@property
62+
def heater_id(self) -> str:
63+
"""Return the heater-id."""
64+
return self._heater_id
65+
6166
def smile(self, name: str) -> bool:
6267
"""Helper-function checking the smile-name."""
6368
return self.smile_name == name

plugwise/constants.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,6 @@
393393
)
394394

395395

396-
class SmileProps(TypedDict, total=False):
397-
"""The SmileProps Data class."""
398-
399-
cooling_present: bool
400-
gateway_id: str
401-
heater_id: str
402-
item_count: int
403-
reboot: bool
404-
smile_name: str
405-
406-
407396
class ModuleData(TypedDict):
408397
"""The Module data class."""
409398

plugwise/data.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
OFF,
1717
ActuatorData,
1818
GwEntityData,
19-
SmileProps,
2019
)
2120
from plugwise.helper import SmileHelper
2221
from plugwise.util import remove_empty_platform_dicts
@@ -27,28 +26,19 @@ class SmileData(SmileHelper):
2726

2827
def __init__(self) -> None:
2928
"""Init."""
30-
self._smile_props: SmileProps
29+
super().__init__()
3130
self._zones: dict[str, GwEntityData] = {}
32-
SmileHelper.__init__(self)
3331

3432
def _all_entity_data(self) -> None:
3533
"""Helper-function for get_all_gateway_entities().
3634
37-
Collect data for each entity and add to self._smile_props and self.gw_entities.
35+
Collect data for each entity and add to self.gw_entities.
3836
"""
3937
self._update_gw_entities()
4038
if self.smile(ADAM):
4139
self._update_zones()
4240
self.gw_entities.update(self._zones)
4341

44-
self._smile_props["gateway_id"] = self._gateway_id
45-
self._smile_props["item_count"] = self._count
46-
self._smile_props["reboot"] = True
47-
self._smile_props["smile_name"] = self.smile_name
48-
if self._is_thermostat:
49-
self._smile_props["heater_id"] = self._heater_id
50-
self._smile_props["cooling_present"] = self._cooling_present
51-
5242
def _update_zones(self) -> None:
5343
"""Helper-function for _all_entity_data() and async_update().
5444

plugwise/helper.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class SmileHelper(SmileCommon):
7575

7676
def __init__(self) -> None:
7777
"""Set the constructor for this class."""
78+
super().__init__()
7879
self._endpoint: str
7980
self._elga: bool
8081
self._is_thermostat: bool
@@ -89,7 +90,16 @@ def __init__(self) -> None:
8990
self.smile_model: str
9091
self.smile_model_id: str | None
9192
self.smile_version: version.Version
92-
SmileCommon.__init__(self)
93+
94+
@property
95+
def gateway_id(self) -> str:
96+
"""Return the gateway-id."""
97+
return self._gateway_id
98+
99+
@property
100+
def item_count(self) -> int:
101+
"""Return the item-count."""
102+
return self._count
93103

94104
def _all_appliances(self) -> None:
95105
"""Collect all appliances with relevant info.
@@ -233,7 +243,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch
233243
appliance, "domestic_hot_water_mode_control_functionality"
234244
)
235245
# Skip orphaned heater_central (Core Issue #104433)
236-
if appl.entity_id != self._heater_id:
246+
if appl.entity_id != self.heater_id:
237247
return Munch()
238248
return appl
239249
case _ as s if s.endswith("_plug"):
@@ -344,7 +354,7 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
344354

345355
# Get non-P1 data from APPLIANCES
346356
measurements = DEVICE_MEASUREMENTS
347-
if self._is_thermostat and entity_id == self._heater_id:
357+
if self._is_thermostat and entity_id == self.heater_id:
348358
measurements = HEATER_CENTRAL_MEASUREMENTS
349359
# Show the allowed dhw_modes (Loria only)
350360
if self._dhw_allowed_modes:
@@ -619,7 +629,7 @@ def _update_anna_cooling(self, entity_id: str, data: GwEntityData) -> None:
619629
620630
Support added for Techneco Elga and Thercon Loria/Thermastage.
621631
"""
622-
if entity_id != self._heater_id:
632+
if entity_id != self.heater_id:
623633
return
624634

625635
if "elga_status_code" in data:

plugwise/legacy/data.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,20 @@
77

88
# Dict as class
99
# Version detection
10-
from plugwise.constants import NONE, OFF, GwEntityData, SmileProps
10+
from plugwise.constants import NONE, OFF, GwEntityData
1111
from plugwise.legacy.helper import SmileLegacyHelper
1212
from plugwise.util import remove_empty_platform_dicts
1313

1414

1515
class SmileLegacyData(SmileLegacyHelper):
1616
"""The Plugwise Smile main class."""
1717

18-
def __init__(self) -> None:
19-
"""Init."""
20-
self._smile_props: SmileProps
21-
SmileLegacyHelper.__init__(self)
22-
2318
def _all_entity_data(self) -> None:
2419
"""Helper-function for get_all_gateway_entities().
2520
26-
Collect data for each entity and add to self._smile_props and self.gw_entities.
21+
Collect data for each entity and add to self.gw_entities.
2722
"""
2823
self._update_gw_entities()
29-
self._smile_props["gateway_id"] = self.gateway_id
30-
self._smile_props["item_count"] = self._count
31-
self._smile_props["smile_name"] = self.smile_name
32-
if self._is_thermostat:
33-
self._smile_props["heater_id"] = self._heater_id
3424

3525
def _update_gw_entities(self) -> None:
3626
"""Helper-function for _all_entity_data() and async_update().

plugwise/legacy/helper.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class SmileLegacyHelper(SmileCommon):
6464

6565
def __init__(self) -> None:
6666
"""Set the constructor for this class."""
67+
super().__init__()
6768
self._appliances: etree.Element
69+
self._gateway_id: str = NONE
6870
self._is_thermostat: bool
6971
self._loc_data: dict[str, ThermoLoc]
7072
self._locations: etree.Element
@@ -75,7 +77,16 @@ def __init__(self) -> None:
7577
self.smile_model: str
7678
self.smile_version: Version
7779
self.smile_zigbee_mac_address: str | None
78-
SmileCommon.__init__(self)
80+
81+
@property
82+
def gateway_id(self) -> str:
83+
"""Return the gateway-id."""
84+
return self._gateway_id
85+
86+
@property
87+
def item_count(self) -> int:
88+
"""Return the item-count."""
89+
return self._count
7990

8091
def _all_appliances(self) -> None:
8192
"""Collect all appliances with relevant info."""
@@ -125,7 +136,7 @@ def _all_appliances(self) -> None:
125136
continue
126137

127138
# Skip orphaned heater_central (Core Issue #104433)
128-
if appl.pwclass == "heater_central" and appl.entity_id != self._heater_id:
139+
if appl.pwclass == "heater_central" and appl.entity_id != self.heater_id:
129140
continue # pragma: no cover
130141

131142
self._create_gw_entities(appl)
@@ -173,11 +184,11 @@ def _create_legacy_gateway(self) -> None:
173184
174185
Use the home_location or FAKE_APPL as entity id.
175186
"""
176-
self.gateway_id = self._home_loc_id
187+
self._gateway_id = self._home_loc_id
177188
if self.smile_type == "power":
178-
self.gateway_id = FAKE_APPL
189+
self._gateway_id = FAKE_APPL
179190

180-
self.gw_entities[self.gateway_id] = {"dev_class": "gateway"}
191+
self.gw_entities[self._gateway_id] = {"dev_class": "gateway"}
181192
self._count += 1
182193
for key, value in {
183194
"firmware": str(self.smile_version),
@@ -190,7 +201,7 @@ def _create_legacy_gateway(self) -> None:
190201
}.items():
191202
if value is not None:
192203
gw_key = cast(ApplianceType, key)
193-
self.gw_entities[self.gateway_id][gw_key] = value
204+
self.gw_entities[self._gateway_id][gw_key] = value
194205
self._count += 1
195206

196207
def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
@@ -268,7 +279,7 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
268279
return data
269280

270281
measurements = DEVICE_MEASUREMENTS
271-
if self._is_thermostat and entity_id == self._heater_id:
282+
if self._is_thermostat and entity_id == self.heater_id:
272283
measurements = HEATER_CENTRAL_MEASUREMENTS
273284

274285
if (
@@ -282,7 +293,7 @@ def _get_measurement_data(self, entity_id: str) -> GwEntityData:
282293

283294
# Anna: the Smile outdoor_temperature is present in the Home location
284295
# For some Anna's LOCATIONS is empty, falling back to domain_objects!
285-
if self._is_thermostat and entity_id == self.gateway_id:
296+
if self._is_thermostat and entity_id == self._gateway_id:
286297
locator = f"./location[@id='{self._home_loc_id}']/logs/point_log[type='outdoor_temperature']/period/measurement"
287298
if (found := self._domain_objects.find(locator)) is not None:
288299
value = format_measure(found.text, NONE)

plugwise/legacy/smile.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
REQUIRE_APPLIANCES,
2020
RULES,
2121
GwEntityData,
22-
SmileProps,
2322
ThermoLoc,
2423
)
2524
from plugwise.exceptions import ConnectionFailedError, DataMissingError, PlugwiseError
@@ -41,7 +40,6 @@ def __init__(
4140
_on_off_device: bool,
4241
_opentherm_device: bool,
4342
_request: Callable[..., Awaitable[Any]],
44-
_smile_props: SmileProps,
4543
_stretch_v2: bool,
4644
_target_smile: str,
4745
smile_hostname: str,
@@ -54,13 +52,13 @@ def __init__(
5452
smile_zigbee_mac_address: str | None,
5553
) -> None:
5654
"""Set the constructor for this class."""
55+
super().__init__()
5756
self._cooling_present = False
5857
self._is_thermostat = _is_thermostat
5958
self._loc_data = _loc_data
6059
self._on_off_device = _on_off_device
6160
self._opentherm_device = _opentherm_device
6261
self._request = _request
63-
self._smile_props = _smile_props
6462
self._stretch_v2 = _stretch_v2
6563
self._target_smile = _target_smile
6664
self.smile_hostname = smile_hostname
@@ -71,11 +69,15 @@ def __init__(
7169
self.smile_type = smile_type
7270
self.smile_version = smile_version
7371
self.smile_zigbee_mac_address = smile_zigbee_mac_address
74-
SmileLegacyData.__init__(self)
7572

7673
self._first_update = True
7774
self._previous_day_number: str = "0"
7875

76+
@property
77+
def cooling_present(self) -> bool:
78+
"""Return the cooling capability."""
79+
return False
80+
7981
async def full_xml_update(self) -> None:
8082
"""Perform a first fetch of the Plugwise server XML data."""
8183
self._domain_objects = await self._request(DOMAIN_OBJECTS)

0 commit comments

Comments
 (0)