Skip to content

Commit 8287631

Browse files
committed
Save updated files
1 parent 64c8110 commit 8287631

File tree

17 files changed

+314
-192
lines changed

17 files changed

+314
-192
lines changed

plugwise/__init__.py

Lines changed: 89 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Plugwise backend module for Home Assistant Core.
44
"""
5+
56
from __future__ import annotations
67

78
from plugwise.constants import (
@@ -63,7 +64,7 @@ def __init__(
6364
self._timeout,
6465
self._username,
6566
self._websession,
66-
)
67+
)
6768

6869
self._cooling_present = False
6970
self._elga = False
@@ -125,52 +126,56 @@ async def connect(self) -> Version | None:
125126
# Determine smile specifics
126127
await self._smile_detect(result, dsmrmain)
127128

128-
self._smile_api = SmileAPI(
129-
self._host,
130-
self._password,
131-
self._request,
132-
self._websession,
133-
self._cooling_present,
134-
self._elga,
135-
self._is_thermostat,
136-
self._last_active,
137-
self._loc_data,
138-
self._on_off_device,
139-
self._opentherm_device,
140-
self._schedule_old_states,
141-
self.gateway_id,
142-
self.smile_fw_version,
143-
self.smile_hostname,
144-
self.smile_hw_version,
145-
self.smile_mac_address,
146-
self.smile_model,
147-
self.smile_model_id,
148-
self.smile_name,
149-
self.smile_type,
150-
self.smile_version,
151-
self._port,
152-
self._username,
153-
) if not self.smile_legacy else SmileLegacyAPI(
154-
self._host,
155-
self._password,
156-
self._request,
157-
self._websession,
158-
self._is_thermostat,
159-
self._loc_data,
160-
self._on_off_device,
161-
self._opentherm_device,
162-
self._stretch_v2,
163-
self._target_smile,
164-
self.smile_fw_version,
165-
self.smile_hostname,
166-
self.smile_hw_version,
167-
self.smile_mac_address,
168-
self.smile_model,
169-
self.smile_name,
170-
self.smile_type,
171-
self.smile_zigbee_mac_address,
172-
self._port,
173-
self._username,
129+
self._smile_api = (
130+
SmileAPI(
131+
self._host,
132+
self._password,
133+
self._request,
134+
self._websession,
135+
self._cooling_present,
136+
self._elga,
137+
self._is_thermostat,
138+
self._last_active,
139+
self._loc_data,
140+
self._on_off_device,
141+
self._opentherm_device,
142+
self._schedule_old_states,
143+
self.gateway_id,
144+
self.smile_fw_version,
145+
self.smile_hostname,
146+
self.smile_hw_version,
147+
self.smile_mac_address,
148+
self.smile_model,
149+
self.smile_model_id,
150+
self.smile_name,
151+
self.smile_type,
152+
self.smile_version,
153+
self._port,
154+
self._username,
155+
)
156+
if not self.smile_legacy
157+
else SmileLegacyAPI(
158+
self._host,
159+
self._password,
160+
self._request,
161+
self._websession,
162+
self._is_thermostat,
163+
self._loc_data,
164+
self._on_off_device,
165+
self._opentherm_device,
166+
self._stretch_v2,
167+
self._target_smile,
168+
self.smile_fw_version,
169+
self.smile_hostname,
170+
self.smile_hw_version,
171+
self.smile_mac_address,
172+
self.smile_model,
173+
self.smile_name,
174+
self.smile_type,
175+
self.smile_zigbee_mac_address,
176+
self._port,
177+
self._username,
178+
)
174179
)
175180

176181
# Update all endpoints on first connect
@@ -203,7 +208,7 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
203208
)
204209
raise UnsupportedDeviceError
205210

206-
version_major= str(self.smile_fw_version.major)
211+
version_major = str(self.smile_fw_version.major)
207212
self._target_smile = f"{model}_v{version_major}"
208213
LOGGER.debug("Plugwise identified as %s", self._target_smile)
209214
if self._target_smile not in SMILES:
@@ -318,9 +323,9 @@ async def async_update(self) -> PlugwiseData:
318323

319324
return data
320325

321-
########################################################################################################
322-
### API Set and HA Service-related Functions ###
323-
########################################################################################################
326+
########################################################################################################
327+
### API Set and HA Service-related Functions ###
328+
########################################################################################################
324329

325330
async def set_select(
326331
self,
@@ -333,7 +338,9 @@ async def set_select(
333338
try:
334339
await self._smile_api.set_select(key, loc_id, option, state)
335340
except ConnectionFailedError as exc:
336-
raise ConnectionFailedError(f"Failed to set select option '{option}': {str(exc)}") from exc
341+
raise ConnectionFailedError(
342+
f"Failed to set select option '{option}': {str(exc)}"
343+
) from exc
337344

338345
async def set_schedule_state(
339346
self,
@@ -345,8 +352,9 @@ async def set_schedule_state(
345352
try:
346353
await self._smile_api.set_schedule_state(loc_id, state, name)
347354
except ConnectionFailedError as exc: # pragma no cover
348-
raise ConnectionFailedError(f"Failed to set schedule state: {str(exc)}") from exc # pragma no cover
349-
355+
raise ConnectionFailedError(
356+
f"Failed to set schedule state: {str(exc)}"
357+
) from exc # pragma no cover
350358

351359
async def set_preset(self, loc_id: str, preset: str) -> None:
352360
"""Set the given Preset on the relevant Thermostat."""
@@ -360,7 +368,9 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
360368
try:
361369
await self._smile_api.set_temperature(loc_id, items)
362370
except ConnectionFailedError as exc:
363-
raise ConnectionFailedError(f"Failed to set temperature: {str(exc)}") from exc
371+
raise ConnectionFailedError(
372+
f"Failed to set temperature: {str(exc)}"
373+
) from exc
364374

365375
async def set_number(
366376
self,
@@ -372,14 +382,18 @@ async def set_number(
372382
try:
373383
await self._smile_api.set_number(dev_id, key, temperature)
374384
except ConnectionFailedError as exc:
375-
raise ConnectionFailedError(f"Failed to set number '{key}': {str(exc)}") from exc
385+
raise ConnectionFailedError(
386+
f"Failed to set number '{key}': {str(exc)}"
387+
) from exc
376388

377389
async def set_temperature_offset(self, dev_id: str, offset: float) -> None:
378390
"""Set the Temperature offset for thermostats that support this feature."""
379391
try: # pragma no cover
380392
await self._smile_api.set_offset(dev_id, offset) # pragma: no cover
381393
except ConnectionFailedError as exc: # pragma no cover
382-
raise ConnectionFailedError(f"Failed to set temperature offset: {str(exc)}") from exc # pragma no cover
394+
raise ConnectionFailedError(
395+
f"Failed to set temperature offset: {str(exc)}"
396+
) from exc # pragma no cover
383397

384398
async def set_switch_state(
385399
self, appl_id: str, members: list[str] | None, model: str, state: str
@@ -388,39 +402,51 @@ async def set_switch_state(
388402
try:
389403
await self._smile_api.set_switch_state(appl_id, members, model, state)
390404
except ConnectionFailedError as exc:
391-
raise ConnectionFailedError(f"Failed to set switch state: {str(exc)}") from exc
405+
raise ConnectionFailedError(
406+
f"Failed to set switch state: {str(exc)}"
407+
) from exc
392408

393409
async def set_gateway_mode(self, mode: str) -> None:
394410
"""Set the gateway mode."""
395411
try: # pragma no cover
396412
await self._smile_api.set_gateway_mode(mode) # pragma: no cover
397413
except ConnectionFailedError as exc: # pragma no cover
398-
raise ConnectionFailedError(f"Failed to set gateway mode: {str(exc)}") from exc # pragma no cover
414+
raise ConnectionFailedError(
415+
f"Failed to set gateway mode: {str(exc)}"
416+
) from exc # pragma no cover
399417

400418
async def set_regulation_mode(self, mode: str) -> None:
401419
"""Set the heating regulation mode."""
402420
try: # pragma no cover
403421
await self._smile_api.set_regulation_mode(mode) # pragma: no cover
404422
except ConnectionFailedError as exc: # pragma no cover
405-
raise ConnectionFailedError(f"Failed to set regulation mode: {str(exc)}") from exc # pragma no cover
423+
raise ConnectionFailedError(
424+
f"Failed to set regulation mode: {str(exc)}"
425+
) from exc # pragma no cover
406426

407427
async def set_dhw_mode(self, mode: str) -> None:
408428
"""Set the domestic hot water heating regulation mode."""
409429
try: # pragma no cover
410430
await self._smile_api.set_dhw_mode(mode) # pragma: no cover
411431
except ConnectionFailedError as exc: # pragma no cover
412-
raise ConnectionFailedError(f"Failed to set dhw mode: {str(exc)}") from exc # pragma no cover
432+
raise ConnectionFailedError(
433+
f"Failed to set dhw mode: {str(exc)}"
434+
) from exc # pragma no cover
413435

414436
async def delete_notification(self) -> None:
415437
"""Delete the active Plugwise Notification."""
416438
try:
417439
await self._smile_api.delete_notification()
418440
except ConnectionFailedError as exc:
419-
raise ConnectionFailedError(f"Failed to delete notification: {str(exc)}") from exc
441+
raise ConnectionFailedError(
442+
f"Failed to delete notification: {str(exc)}"
443+
) from exc
420444

421445
async def reboot_gateway(self) -> None:
422446
"""Reboot the Plugwise Gateway."""
423447
try:
424448
await self._smile_api.reboot_gateway()
425449
except ConnectionFailedError as exc:
426-
raise ConnectionFailedError(f"Failed to reboot gateway: {str(exc)}") from exc
450+
raise ConnectionFailedError(
451+
f"Failed to reboot gateway: {str(exc)}"
452+
) from exc

plugwise/common.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Plugwise Smile protocol helpers.
44
"""
5+
56
from __future__ import annotations
67

78
from typing import cast
@@ -83,21 +84,23 @@ def _appl_heater_central_info(
8384
appl.hardware = module_data["hardware_version"]
8485
appl.model_id = module_data["vendor_model"] if not legacy else None
8586
appl.model = (
86-
"Generic heater/cooler"
87-
if self._cooling_present
88-
else "Generic heater"
87+
"Generic heater/cooler" if self._cooling_present else "Generic heater"
8988
)
9089

9190
return appl
9291

93-
def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None) -> Munch:
92+
def _appl_thermostat_info(
93+
self, appl: Munch, xml_1: etree, xml_2: etree = None
94+
) -> Munch:
9495
"""Helper-function for _appliance_info_finder()."""
9596
locator = "./logs/point_log[type='thermostat']/thermostat"
9697
xml_2 = return_valid(xml_2, self._domain_objects)
9798
module_data = self._get_module_data(xml_1, locator, xml_2)
9899
appl.vendor_name = module_data["vendor_name"]
99100
appl.model = module_data["vendor_model"]
100-
if appl.model != "ThermoTouch": # model_id for Anna not present as stand-alone device
101+
if (
102+
appl.model != "ThermoTouch"
103+
): # model_id for Anna not present as stand-alone device
101104
appl.model_id = appl.model
102105
appl.model = check_model(appl.model, appl.vendor_name)
103106

@@ -108,7 +111,9 @@ def _appl_thermostat_info(self, appl: Munch, xml_1: etree, xml_2: etree = None)
108111

109112
return appl
110113

111-
def _collect_power_values(self, data: GwEntityData, loc: Munch, tariff: str, legacy: bool = False) -> None:
114+
def _collect_power_values(
115+
self, data: GwEntityData, loc: Munch, tariff: str, legacy: bool = False
116+
) -> None:
112117
"""Something."""
113118
for loc.peak_select in ("nl_peak", "nl_offpeak"):
114119
loc.locator = (
@@ -220,9 +225,7 @@ def _create_gw_entities(self, appl: Munch) -> None:
220225
self.gw_entities[appl.entity_id][appl_key] = value
221226
self._count += 1
222227

223-
def _entity_switching_group(
224-
self, entity: GwEntityData, data: GwEntityData
225-
) -> None:
228+
def _entity_switching_group(self, entity: GwEntityData, data: GwEntityData) -> None:
226229
"""Helper-function for _get_device_zone_data().
227230
228231
Determine switching group device data.
@@ -268,7 +271,9 @@ def _get_group_switches(self) -> dict[str, GwEntityData]:
268271

269272
return switch_groups
270273

271-
def _get_lock_state(self, xml: etree, data: GwEntityData, stretch_v2: bool = False) -> None:
274+
def _get_lock_state(
275+
self, xml: etree, data: GwEntityData, stretch_v2: bool = False
276+
) -> None:
272277
"""Helper-function for _get_measurement_data().
273278
274279
Adam & Stretches: obtain the relay-switch lock state.
@@ -323,7 +328,9 @@ def _get_module_data(
323328

324329
return module_data
325330

326-
def _get_zigbee_data(self, module: etree, module_data: ModuleData, legacy: bool) -> None:
331+
def _get_zigbee_data(
332+
self, module: etree, module_data: ModuleData, legacy: bool
333+
) -> None:
327334
"""Helper-function for _get_module_data()."""
328335
if legacy:
329336
# Stretches
@@ -334,5 +341,5 @@ def _get_zigbee_data(self, module: etree, module_data: ModuleData, legacy: bool)
334341
module_data["zigbee_mac_address"] = coord.find("mac_address").text
335342
# Adam
336343
elif (zb_node := module.find("./protocols/zig_bee_node")) is not None:
337-
module_data["zigbee_mac_address"] = zb_node.find("mac_address").text
338-
module_data["reachable"] = zb_node.find("reachable").text == "true"
344+
module_data["zigbee_mac_address"] = zb_node.find("mac_address").text
345+
module_data["reachable"] = zb_node.find("reachable").text == "true"

plugwise/constants.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugwise Smile constants."""
2+
23
from __future__ import annotations
34

45
from collections import namedtuple
@@ -167,9 +168,7 @@
167168
"intended_boiler_state": DATA(
168169
"heating_state", NONE
169170
), # Legacy Anna: shows when heating is active, we don't show dhw_state, cannot be determined reliably
170-
"flame_state": UOM(
171-
NONE
172-
), # Also present when there is a single gas-heater
171+
"flame_state": UOM(NONE), # Also present when there is a single gas-heater
173172
"intended_boiler_temperature": UOM(
174173
TEMP_CELSIUS
175174
), # Non-zero when heating, zero when dhw-heating
@@ -585,4 +584,3 @@ class PlugwiseData:
585584

586585
devices: dict[str, GwEntityData]
587586
gateway: GatewayData
588-

0 commit comments

Comments
 (0)