Skip to content

Commit 495fb96

Browse files
committed
Smile.py typing updates
1 parent 086ed17 commit 495fb96

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

plugwise/smile.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _all_device_data(self) -> None:
6464

6565
def get_all_devices(self) -> None:
6666
"""Determine the devices present from the obtained XML-data."""
67-
self._devices: dict[str, dict[str, Any]] = {}
67+
self._devices = {}
6868
self._scan_thermostats()
6969

7070
for appliance, details in self._appl_data.items():
@@ -76,9 +76,9 @@ def get_all_devices(self) -> None:
7676
details["location"] = self._home_location
7777

7878
# Override slave thermostat class
79-
if (loc_id := details.get("location")) in self._thermo_locs:
80-
tl_loc_id = self._thermo_locs.get(loc_id)
81-
if "slaves" in tl_loc_id and appliance in tl_loc_id.get("slaves"):
79+
if (loc_id := details["location"]) in self._thermo_locs:
80+
tl_loc_id = self._thermo_locs[loc_id]
81+
if "slaves" in tl_loc_id and appliance in tl_loc_id["slaves"]:
8282
details["class"] = "thermo_sensor"
8383

8484
# Next, filter for thermostat-devices without a location
@@ -120,9 +120,9 @@ def _device_data_switching_group(
120120
"""Helper-function for _get_device_data().
121121
Determine switching group device data.
122122
"""
123-
if details.get("class") in SWITCH_GROUP_TYPES:
123+
if details["class"] in SWITCH_GROUP_TYPES:
124124
counter = 0
125-
for member in details.get("members"):
125+
for member in details["members"]:
126126
member_data = self._get_appliance_data(member)
127127
if member_data.get("relay"):
128128
counter += 1
@@ -151,7 +151,7 @@ def _device_data_climate(
151151
"""Helper-function for _get_device_data().
152152
Determine climate-control device data.
153153
"""
154-
loc_id = details.get("location")
154+
loc_id = details["location"]
155155

156156
# Presets
157157
device_data["preset_modes"] = None
@@ -190,11 +190,11 @@ def _get_device_data(self, dev_id: str) -> dict[str, Any]:
190190
"""Helper-function for _all_device_data() and async_update().
191191
Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
192192
"""
193-
details = self._devices.get(dev_id)
193+
details = self._devices[dev_id]
194194
device_data = self._get_appliance_data(dev_id)
195195

196196
# Generic
197-
if details.get("class") == "gateway" or dev_id == self.gateway_id:
197+
if details["class"] == "gateway" or dev_id == self.gateway_id:
198198
if self.smile_type == "thermostat":
199199
# Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS - under Home
200200
# The outdoor_temperature present in APPLIANCES is a local sensor connected to the active device
@@ -209,7 +209,7 @@ def _get_device_data(self, dev_id: str) -> dict[str, Any]:
209209
device_data["regulation_modes"] = self._allowed_modes
210210

211211
# Get P1 data from LOCATIONS
212-
power_data = self._power_data_from_location(details.get("location"))
212+
power_data = self._power_data_from_location(details["location"])
213213
if power_data is not None:
214214
device_data.update(power_data)
215215

@@ -218,7 +218,7 @@ def _get_device_data(self, dev_id: str) -> dict[str, Any]:
218218
# Specific, not generic Adam data
219219
device_data = self._device_data_adam(details, device_data)
220220
# No need to obtain thermostat data when the device is not a thermostat
221-
if details.get("class") not in THERMOSTAT_CLASSES:
221+
if details["class"] not in THERMOSTAT_CLASSES:
222222
return device_data
223223

224224
# Thermostat data (presets, temperatures etc)
@@ -237,9 +237,9 @@ def __init__(
237237
host: str,
238238
password: str,
239239
username: str = DEFAULT_USERNAME,
240-
port: str = DEFAULT_PORT,
241-
timeout: str = DEFAULT_TIMEOUT,
242-
websession: aiohttp.ClientSession = None,
240+
port: int = DEFAULT_PORT,
241+
timeout: float = DEFAULT_TIMEOUT,
242+
websession: aiohttp.ClientSession | None = None,
243243
) -> None:
244244
"""Set the constructor for this class."""
245245
super().__init__(
@@ -299,9 +299,7 @@ async def connect(self) -> bool:
299299

300300
return True
301301

302-
async def _smile_detect_legacy(
303-
self, result: etree, dsmrmain: etree
304-
) -> tuple[str, str]:
302+
async def _smile_detect_legacy(self, result: etree, dsmrmain: etree) -> str:
305303
"""Helper-function for _smile_detect()."""
306304
# Stretch: find the MAC of the zigbee master_controller (= Stick)
307305
if network := result.find("./module/protocols/master_controller"):
@@ -390,8 +388,8 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
390388
)
391389
raise UnsupportedDeviceError
392390

393-
self.smile_name = SMILES[target_smile].get("friendly_name")
394-
self.smile_type = SMILES[target_smile].get("type")
391+
self.smile_name = SMILES[target_smile]["friendly_name"]
392+
self.smile_type = SMILES[target_smile]["type"]
395393
self.smile_version = (self.smile_fw_version, ver)
396394

397395
if "legacy" in SMILES[target_smile]:
@@ -437,7 +435,7 @@ async def _update_domain_objects(self) -> None:
437435
f"{self._endpoint}{DOMAIN_OBJECTS}",
438436
)
439437

440-
async def async_update(self) -> dict[str, Any]:
438+
async def async_update(self) -> list[dict[str, Any]]:
441439
"""Perform an incremental update for updating the various device states."""
442440
if self.smile_type != "power":
443441
await self._update_domain_objects()
@@ -457,7 +455,7 @@ async def async_update(self) -> dict[str, Any]:
457455
dev_dict[key] = value
458456

459457
for item in ["binary_sensors", "sensors", "switches"]:
460-
notifs = None
458+
notifs: dict[str, str] = {}
461459
if item == "binary_sensors":
462460
notifs = self._notifications
463461
if item in dev_dict:
@@ -606,7 +604,7 @@ async def set_max_boiler_temperature(self, temperature: str) -> bool:
606604
return True
607605

608606
async def _set_groupswitch_member_state(
609-
self, members: list[str] | None, state: str, switch: Munch
607+
self, members: list[str], state: str, switch: Munch
610608
) -> bool:
611609
"""Helper-function for set_switch_state() .
612610
Set the given State of the relevant Switch within a group of members.

0 commit comments

Comments
 (0)