Skip to content

Commit 45c0b04

Browse files
authored
Merge pull request #305 from plugwise/typing_again
Retry fixing #231
2 parents 620cb6d + 64aa8a4 commit 45c0b04

File tree

7 files changed

+89
-71
lines changed

7 files changed

+89
-71
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ fixtures/*
1515
!fixtures/.keep
1616
*.sedbck
1717
tmp
18+
.mypy_cache

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Changelog
22

3+
## v0.31.2: Introduce strict-typing (py.typed)
4+
35
## v0.31.1: Legacy Anna - read and process system-xml data
46

57
- Add support for reading the system-xml data from the legacy Smile T

plugwise/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
ActuatorData,
3636
ApplianceData,
3737
DeviceData,
38-
GatewayData,
38+
PlugwiseData,
3939
SmileBinarySensors,
4040
SmileSensors,
4141
SmileSwitches,
@@ -52,12 +52,8 @@
5252
class SmileData(SmileHelper):
5353
"""The Plugwise Smile main class."""
5454

55-
def update_for_cooling(self, device: DeviceData) -> None:
55+
def update_for_cooling(self, device: DeviceData) -> DeviceData:
5656
"""Helper-function for adding/updating various cooling-related values."""
57-
# Add setpoint_low and setpoint_high when cooling is enabled
58-
if device["dev_class"] not in ZONE_THERMOSTATS:
59-
return
60-
6157
# For heating + cooling, replace setpoint with setpoint_high/_low
6258
if self._cooling_present:
6359
thermostat = device["thermostat"]
@@ -85,6 +81,8 @@ def update_for_cooling(self, device: DeviceData) -> None:
8581
sensors["setpoint_low"] = temp_dict["setpoint_low"]
8682
sensors["setpoint_high"] = temp_dict["setpoint_high"]
8783

84+
return device
85+
8886
def _all_device_data(self) -> None:
8987
"""Helper-function for get_all_devices().
9088
@@ -100,7 +98,8 @@ def _all_device_data(self) -> None:
10098
)
10199

102100
# Update for cooling
103-
self.update_for_cooling(self.gw_devices[device_id])
101+
if self.gw_devices[device_id]["dev_class"] in ZONE_THERMOSTATS:
102+
self.update_for_cooling(self.gw_devices[device_id])
104103

105104
self.gw_data.update(
106105
{"smile_name": self.smile_name, "gateway_id": self.gateway_id}
@@ -237,7 +236,7 @@ def _device_data_climate(
237236

238237
def _check_availability(
239238
self, details: ApplianceData, device_data: DeviceData
240-
) -> None:
239+
) -> DeviceData:
241240
"""Helper-function for _get_device_data().
242241
243242
Provide availability status for the wired-commected devices.
@@ -258,6 +257,8 @@ def _check_availability(
258257
if "P1 does not seem to be connected to a smart meter" in msg:
259258
device_data["available"] = False
260259

260+
return device_data
261+
261262
def _get_device_data(self, dev_id: str) -> DeviceData:
262263
"""Helper-function for _all_device_data() and async_update().
263264
@@ -452,7 +453,7 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
452453
)
453454
raise UnsupportedDeviceError
454455

455-
ver = semver.VersionInfo.parse(self.smile_fw_version)
456+
ver = semver.version.Version.parse(self.smile_fw_version)
456457
target_smile = f"{model}_v{ver.major}"
457458
LOGGER.debug("Plugwise identified as %s", target_smile)
458459
if target_smile not in SMILES:
@@ -509,7 +510,7 @@ async def _update_domain_objects(self) -> None:
509510
f"{self._endpoint}{DOMAIN_OBJECTS}",
510511
)
511512

512-
async def async_update(self) -> tuple[GatewayData, dict[str, DeviceData]]:
513+
async def async_update(self) -> PlugwiseData:
513514
"""Perform an incremental update for updating the various device states."""
514515
if self.smile_type != "power":
515516
await self._update_domain_objects()
@@ -547,9 +548,10 @@ async def async_update(self) -> tuple[GatewayData, dict[str, DeviceData]]:
547548
)
548549

549550
# Update for cooling
550-
self.update_for_cooling(dev_dict)
551+
if dev_dict["dev_class"] in ZONE_THERMOSTATS:
552+
self.update_for_cooling(dev_dict)
551553

552-
return (self.gw_data, self.gw_devices)
554+
return PlugwiseData(self.gw_data, self.gw_devices)
553555

554556
async def _set_schedule_state_legacy(
555557
self, loc_id: str, name: str, status: str

plugwise/constants.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
from collections import namedtuple
5+
from dataclasses import dataclass
56
import datetime as dt
67
import logging
78
from typing import Final, TypedDict
@@ -359,7 +360,7 @@ class ModelData(TypedDict):
359360
hardware_version: str | None
360361
firmware_version: str | None
361362
zigbee_mac_address: str | None
362-
available: bool | None
363+
reachable: bool | None
363364

364365

365366
class SmileBinarySensors(TypedDict, total=False):
@@ -460,10 +461,15 @@ class ActuatorData(TypedDict, total=False):
460461
upper_bound: float
461462

462463

463-
class DeviceDataPoints(
464-
SmileBinarySensors, SmileSensors, SmileSwitches, TypedDict, total=False
464+
class DeviceData(
465+
ApplianceData,
466+
SmileBinarySensors,
467+
SmileSensors,
468+
SmileSwitches,
469+
TypedDict,
470+
total=False,
465471
):
466-
"""The class covering all possible collected data points."""
472+
"""The Device Data class, covering the collected and ordered output-data per device."""
467473

468474
# Loria
469475
dhw_mode: str
@@ -487,19 +493,23 @@ class DeviceDataPoints(
487493
control_state: str | bool
488494

489495
# For temporary use
490-
c_heating_state: str
496+
c_heating_state: bool
491497
modified: str
492498

493499
# Device availability
494500
available: bool | None
495501

496-
497-
class DeviceData(ApplianceData, DeviceDataPoints, TypedDict, total=False):
498-
"""The Device Data class, covering the collected and ordere output-data per device."""
499-
500502
binary_sensors: SmileBinarySensors
501503
domestic_hot_water_setpoint: ActuatorData | float
502504
maximum_boiler_temperature: ActuatorData | float
503505
sensors: SmileSensors
504506
switches: SmileSwitches
505507
thermostat: ActuatorData
508+
509+
510+
@dataclass
511+
class PlugwiseData:
512+
"""Plugwise data provided as output."""
513+
514+
gateway: GatewayData
515+
devices: dict[str, DeviceData]

0 commit comments

Comments
 (0)