Skip to content

Commit 7c4f6e9

Browse files
committed
Try 2
1 parent 61db8b0 commit 7c4f6e9

File tree

6 files changed

+364
-404
lines changed

6 files changed

+364
-404
lines changed

plugwise/__init__.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from typing import cast
99

1010
from plugwise.constants import (
11-
ADAM,
12-
ANNA,
1311
DEFAULT_LEGACY_TIMEOUT,
1412
DEFAULT_PORT,
1513
DEFAULT_TIMEOUT,
@@ -18,16 +16,12 @@
1816
LOGGER,
1917
MODULES,
2018
NONE,
21-
SMILE_P1,
2219
SMILES,
2320
STATE_OFF,
2421
STATE_ON,
2522
STATUS,
2623
SYSTEM,
27-
PlugwiseAdamData,
28-
PlugwiseAnnaData,
29-
PlugwiseP1Data,
30-
PlugwiseStretchData,
24+
GwEntityData,
3125
ThermoLoc,
3226
)
3327
from plugwise.exceptions import (
@@ -332,21 +326,9 @@ async def _smile_detect_legacy(
332326
self.smile.legacy = True
333327
return return_model
334328

335-
async def async_update(
336-
self,
337-
) -> dict[
338-
str, PlugwiseAnnaData | PlugwiseAdamData | PlugwiseP1Data | PlugwiseStretchData
339-
]:
340-
"""Update the Plugwise Gateway entities and their data and states."""
341-
if self.smile.type == ANNA:
342-
data: dict[str, PlugwiseAnnaData] = {}
343-
if self.smile.type == ADAM:
344-
data: dict[str, PlugwiseAdamData] = {}
345-
if self.smile.type == SMILE_P1:
346-
data: dict[str, PlugwiseP1Data] = {}
347-
if self.smile.type == "Stretch":
348-
data: dict[str, PlugwiseStretchData] = {}
349-
329+
async def async_update(self) -> dict[str, GwEntityData]:
330+
"""Update the Plughwise Gateway entities and their data and states."""
331+
data: dict[str, GwEntityData] = {}
350332
try:
351333
data = await self._smile_api.async_update()
352334
except (DataMissingError, KeyError) as err:

plugwise/common.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,12 @@ def _appl_thermostat_info(
146146

147147
def _create_gw_entities(self, appl: Munch) -> None:
148148
"""Helper-function for creating/updating gw_entities."""
149-
appl.device = self.device_name(pw_class, model_id or name)
150149
self.gw_entities[appl.entity_id] = {"dev_class": appl.pwclass}
151150
self._count += 1
152151
for key, value in {
153152
"available": appl.available,
154153
"firmware": appl.firmware,
155154
"hardware": appl.hardware,
156-
"id": appl.entity_id,
157155
"location": appl.location,
158156
"mac_address": appl.mac,
159157
"model": appl.model,
@@ -164,49 +162,9 @@ def _create_gw_entities(self, appl: Munch) -> None:
164162
}.items():
165163
if value is not None or key == "location":
166164
appl_key = cast(ApplianceType, key)
167-
self.gw_entities[appl.device][appl_key] = value
165+
self.gw_entities[appl.entity_id][appl_key] = value
168166
self._count += 1
169167

170-
def device_name(self, pw_type: str, model): None
171-
"""Returns device name/type based on pw_type and optionally model.."""
172-
match pw_type:
173-
case "smartmeter":
174-
return "smartmeter"
175-
case "thermostat":
176-
match "143.1":
177-
return "anna_adam"
178-
match: "Anna":
179-
return "anna"
180-
case "zone_thermostat":
181-
match "158-01":
182-
return "lisa"
183-
match "170-01":
184-
return "emma"
185-
match "106-03":
186-
return "tom_floor"
187-
case "zone_thermometer":
188-
match "168-01":
189-
return "jip"
190-
case "heater_central"
191-
match "Opentherm":
192-
return "opentherm"
193-
match "OnOff":
194-
return "onoff"
195-
case "gateway":
196-
match model_id:
197-
case: "smile_open_therm":
198-
return "adam"
199-
case: "smile_thermo":
200-
if self.smile.anna_p1:
201-
return "smile_t_p1"
202-
return "smile_t"
203-
case: "smile":
204-
return "smile_p1"
205-
case: "stretch":
206-
return "stretch"
207-
case s if s.endswith("_plug"):
208-
return "plug"
209-
210168
def _reorder_devices(self) -> None:
211169
"""Place the gateway and optional heater_central devices as 1st and 2nd."""
212170
reordered = {}

plugwise/constants.py

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,9 @@
33
from __future__ import annotations
44

55
from collections import namedtuple
6-
from dataclasses import dataclass
76
import logging
87
from typing import Final, Literal, TypedDict, get_args
98

10-
from plugwise.devices import (
11-
AdamGateway,
12-
AnnaAdam,
13-
Anna,
14-
EmmaJipLisaTom,
15-
OnOff,
16-
OpenTherm,
17-
Plug,
18-
SmartEnergyLegacySensors,
19-
SmartEnergyMeter,
20-
SmileP1Gateway,
21-
SmileTGateway,
22-
StretchGateway,
23-
Zone,
24-
)
25-
269
LOGGER = logging.getLogger(__name__)
2710

2811
# Copied homeassistant.consts
@@ -541,9 +524,24 @@ class ActuatorData(TypedDict, total=False):
541524
upper_bound: float
542525

543526

544-
@dataclass
545-
class GwEntityData:
546-
"""The base Gateway Entity data class."""
527+
class GwEntityData(TypedDict, total=False):
528+
"""The Gateway Entity data class.
529+
530+
Covering the collected output-data per device or location.
531+
"""
532+
533+
# Appliance base data
534+
dev_class: str
535+
firmware: str
536+
hardware: str
537+
location: str
538+
mac_address: str
539+
members: list[str]
540+
model: str
541+
model_id: str | None
542+
name: str
543+
vendor: str
544+
zigbee_mac_address: str
547545

548546
# For temporary use
549547
cooling_enabled: bool
@@ -552,44 +550,40 @@ class GwEntityData:
552550
c_heating_state: bool
553551
thermostat_supports_cooling: bool
554552

553+
# Device availability
554+
available: bool | None
555+
556+
# Loria
557+
select_dhw_mode: str
558+
dhw_modes: list[str]
559+
560+
# Gateway
561+
gateway_modes: list[str]
562+
notifications: dict[str, dict[str, str]]
563+
regulation_modes: list[str]
564+
select_gateway_mode: str
565+
select_regulation_mode: str
566+
567+
# Thermostat-related
568+
select_zone_profile: str
569+
thermostats: dict[str, list[str]]
570+
zone_profiles: list[str]
571+
# Presets:
572+
active_preset: str | None
573+
preset_modes: list[str] | None
574+
# Schedules:
575+
available_schedules: list[str]
576+
select_schedule: str | None
577+
578+
climate_mode: str
579+
# Extra for Adam Master Thermostats
580+
control_state: str
555581

556-
@dataclass
557-
class PlugwiseAnnaData(
558-
Anna,
559-
GwEntityData,
560-
OnOff,
561-
OpenTherm,
562-
SmileTGateway,
563-
):
564-
"""The Plugwise Anna Data class."""
565-
566-
567-
@dataclass
568-
class PlugwiseAdamData(
569-
AdamGateway,
570-
AnnaAdam,
571-
GwEntityData,
572-
EmmaJipLisaTom,
573-
Plug,
574-
OnOff,
575-
OpenTherm,
576-
Zone,
577-
):
578-
"""The Plugwise Adam Data class."""
579-
580-
581-
@dataclass
582-
class PlugwiseP1Data(
583-
SmartEnergyLegacySensors,
584-
SmartEnergyMeter,
585-
SmileP1Gateway,
586-
):
587-
"""The Plugwise P1 Data class."""
588-
589-
590-
@dataclass
591-
class PlugwiseStretchData(
592-
Plug,
593-
StretchGateway,
594-
):
595-
"""The Plugwise Stretch Data class."""
582+
# Dict-types
583+
binary_sensors: SmileBinarySensors
584+
max_dhw_temperature: ActuatorData
585+
maximum_boiler_temperature: ActuatorData
586+
sensors: SmileSensors
587+
switches: SmileSwitches
588+
temperature_offset: ActuatorData
589+
thermostat: ActuatorData

0 commit comments

Comments
 (0)