Skip to content

Commit 8ddb3d2

Browse files
authored
Merge pull request #812 from plugwise/pw-v1.7.0
Link to plugwise v1.7.0 and adapt
2 parents 3a3d906 + ce3136b commit 8ddb3d2

File tree

51 files changed

+3082
-3195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3082
-3195
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
Versions from 0.40 and up
44

5-
## Ongoing
5+
## v0.56.0
66

77
- Internal: Fixes for the CI process
88
- Add test-coverage for persistent_notification-use in binary_sensor
99
- Config_flow: restore showing provided user_input when an error occurs
10+
- Link to plugwise [v1.7.0](https://github.com/plugwise/python-plugwise/releases/tag/v1.7.0) and adapt
1011

1112
## v0.55.5
1213

custom_components/plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async def async_migrate_sensor_entities(
132132

133133
# Migrate opentherm_outdoor_temperature
134134
# to opentherm_outdoor_air_temperature sensor
135-
for device_id, device in coordinator.data.devices.items():
135+
for device_id, device in coordinator.data.items():
136136
if device["dev_class"] != "heater_central":
137137
continue
138138

custom_components/plugwise/binary_sensor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
FLAME_STATE,
3333
HEATING_STATE,
3434
LOGGER, # pw-beta
35-
NOTIFICATIONS,
3635
PLUGWISE_NOTIFICATION,
3736
SECONDARY_BOILER_STATE,
3837
SEVERITIES,
@@ -133,7 +132,7 @@ def _add_entities() -> None:
133132
# pw-beta alternative for debugging
134133
entities: list[PlugwiseBinarySensorEntity] = []
135134
for device_id in coordinator.new_devices:
136-
device = coordinator.data.devices[device_id]
135+
device = coordinator.data[device_id]
137136
if not (binary_sensors := device.get(BINARY_SENSORS)):
138137
continue
139138
for description in PLUGWISE_BINARY_SENSORS:
@@ -188,7 +187,8 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
188187
# not all severities including those without content as empty lists
189188
attrs: dict[str, list[str]] = {} # pw-beta Re-evaluate against Core
190189
self._notification = {} # pw-beta
191-
if notify := self.coordinator.data.gateway[NOTIFICATIONS]:
190+
gateway_id = self.coordinator.api.gateway_id
191+
if notify := self.coordinator.data[gateway_id]["notifications"]:
192192
for notify_id, details in notify.items(): # pw-beta uses notify_id
193193
for msg_type, msg in details.items():
194194
msg_type = msg_type.lower()

custom_components/plugwise/button.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from . import PlugwiseConfigEntry
1111
from .const import (
12-
GATEWAY_ID,
1312
LOGGER, # pw-betea
1413
REBOOT,
1514
)
@@ -28,16 +27,15 @@ async def async_setup_entry(
2827
"""Set up Plugwise buttons from a config entry."""
2928
coordinator = entry.runtime_data
3029

31-
gateway = coordinator.data.gateway
3230
# async_add_entities(
3331
# PlugwiseButtonEntity(coordinator, device_id)
3432
# for device_id in coordinator.data.devices
3533
# if device_id == gateway[GATEWAY_ID] and REBOOT in gateway
3634
# )
3735
# pw-beta alternative for debugging
3836
entities: list[PlugwiseButtonEntity] = []
39-
for device_id, device in coordinator.data.devices.items():
40-
if device_id == gateway[GATEWAY_ID] and REBOOT in gateway:
37+
for device_id, device in coordinator.data.items():
38+
if device_id == coordinator.api.gateway_id and coordinator.api.reboot:
4139
entities.append(PlugwiseButtonEntity(coordinator, device_id))
4240
LOGGER.debug("Add %s reboot button", device["name"])
4341
async_add_entities(entities)

custom_components/plugwise/climate.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@
3333
CLIMATE_MODE,
3434
CONF_HOMEKIT_EMULATION, # pw-beta homekit emulation
3535
CONTROL_STATE,
36-
COOLING_PRESENT,
3736
DEV_CLASS,
3837
DOMAIN,
39-
GATEWAY_ID,
4038
LOCATION,
4139
LOGGER,
4240
LOWER_BOUND,
@@ -45,7 +43,6 @@
4543
RESOLUTION,
4644
SELECT_REGULATION_MODE,
4745
SENSORS,
48-
SMILE_NAME,
4946
TARGET_TEMP,
5047
TARGET_TEMP_HIGH,
5148
TARGET_TEMP_LOW,
@@ -77,9 +74,9 @@ def _add_entities() -> None:
7774
return
7875

7976
entities: list[PlugwiseClimateEntity] = []
80-
gateway_name = coordinator.data.gateway[SMILE_NAME]
77+
gateway_name = coordinator.api.smile_name
8178
for device_id in coordinator.new_devices:
82-
device = coordinator.data.devices[device_id]
79+
device = coordinator.data[device_id]
8380
if gateway_name == "Adam":
8481
if device[DEV_CLASS] == "climate":
8582
entities.append(
@@ -123,10 +120,8 @@ def __init__(
123120
"""Set up the Plugwise API."""
124121
super().__init__(coordinator, device_id)
125122

126-
self._devices = coordinator.data.devices
127-
self._gateway = coordinator.data.gateway
128-
gateway_id: str = self._gateway[GATEWAY_ID]
129-
self._gateway_data = self._devices[gateway_id]
123+
gateway_id: str = coordinator.api.gateway_id
124+
self._gateway_data = coordinator.data[gateway_id]
130125
self._homekit_enabled = homekit_enabled # pw-beta homekit emulation
131126

132127
self._location = device_id
@@ -144,8 +139,8 @@ def __init__(
144139
# Determine supported features
145140
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
146141
if (
147-
self._gateway[COOLING_PRESENT]
148-
and self._gateway[SMILE_NAME] != "Adam"
142+
self.coordinator.api.cooling_present
143+
and coordinator.api.smile_name != "Adam"
149144
):
150145
self._attr_supported_features = (
151146
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
@@ -228,7 +223,7 @@ def hvac_modes(self) -> list[HVACMode]:
228223
if AVAILABLE_SCHEDULES in self.device:
229224
hvac_modes.append(HVACMode.AUTO)
230225

231-
if self._gateway[COOLING_PRESENT]:
226+
if self.coordinator.api.cooling_present:
232227
if REGULATION_MODES in self._gateway_data:
233228
if self._gateway_data[SELECT_REGULATION_MODE] == HVACAction.COOLING:
234229
hvac_modes.append(HVACMode.COOL)

custom_components/plugwise/const.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
DHW_STATE: Final = "dhw_state"
3737
FLAME_STATE: Final = "flame_state"
3838
HEATING_STATE: Final = "heating_state"
39-
NOTIFICATIONS: Final ="notifications"
4039
PLUGWISE_NOTIFICATION: Final = "plugwise_notification"
4140
SECONDARY_BOILER_STATE: Final = "secondary_boiler_state"
4241

@@ -70,11 +69,9 @@
7069
# Entity constants
7170
AVAILABLE: Final = "available"
7271
FIRMWARE: Final = "firmware"
73-
GATEWAY_ID: Final = "gateway_id"
7472
HARDWARE: Final = "hardware"
7573
MODEL: Final = "model"
7674
MODEL_ID: Final = "model_id"
77-
SMILE_NAME: Final = "smile_name"
7875
VENDOR: Final = "vendor"
7976

8077
# Number constants

custom_components/plugwise/coordinator.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from datetime import timedelta
44

5-
from plugwise import PlugwiseData, Smile
5+
from plugwise import GwEntityData, Smile
66
from plugwise.exceptions import (
77
ConnectionFailedError,
88
InvalidAuthentication,
@@ -28,10 +28,10 @@
2828
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
2929
from packaging.version import Version
3030

31-
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, GATEWAY_ID, LOGGER
31+
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, LOGGER
3232

3333

34-
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[PlugwiseData]):
34+
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData]]):
3535
"""Class to manage fetching Plugwise data from single endpoint."""
3636

3737
_connected: bool = False
@@ -78,7 +78,6 @@ async def _connect(self) -> None:
7878
version = await self.api.connect()
7979
self._connected = isinstance(version, Version)
8080
if self._connected:
81-
self.api.get_all_gateway_entities()
8281
self.update_interval = DEFAULT_SCAN_INTERVAL.get(
8382
self.api.smile_type, timedelta(seconds=60)
8483
) # pw-beta options scan-interval
@@ -89,9 +88,8 @@ async def _connect(self) -> None:
8988

9089
LOGGER.debug("DUC update interval: %s", self.update_interval) # pw-beta options
9190

92-
async def _async_update_data(self) -> PlugwiseData:
91+
async def _async_update_data(self) -> dict[str, GwEntityData]:
9392
"""Fetch data from Plugwise."""
94-
data = PlugwiseData(devices={}, gateway={})
9593
try:
9694
if not self._connected:
9795
await self._connect()
@@ -122,31 +120,34 @@ async def _async_update_data(self) -> PlugwiseData:
122120
translation_domain=DOMAIN,
123121
translation_key="unsupported_firmware",
124122
) from err
125-
else:
126-
LOGGER.debug(f"{self.api.smile_name} data: %s", data)
127-
await self.async_add_remove_devices(data, self.config_entry)
128123

124+
LOGGER.debug(f"{self.api.smile_name} data: %s", data)
125+
await self._async_add_remove_devices(data, self.config_entry)
129126
return data
130127

131-
async def async_add_remove_devices(self, data: PlugwiseData, entry: ConfigEntry) -> None:
128+
async def _async_add_remove_devices(
129+
self, data: dict[str, GwEntityData], entry: ConfigEntry
130+
) -> None:
132131
"""Add new Plugwise devices, remove non-existing devices."""
133132
# Check for new or removed devices
134-
self.new_devices = set(data.devices) - self._current_devices
135-
removed_devices = self._current_devices - set(data.devices)
136-
self._current_devices = set(data.devices)
133+
self.new_devices = set(data) - self._current_devices
134+
removed_devices = self._current_devices - set(data)
135+
self._current_devices = set(data)
137136

138137
if removed_devices:
139-
await self.async_remove_devices(data, entry)
138+
await self._async_remove_devices(data, entry)
140139

141-
async def async_remove_devices(self, data: PlugwiseData, entry: ConfigEntry) -> None:
140+
async def _async_remove_devices(
141+
self, data: dict[str, GwEntityData], entry: ConfigEntry
142+
) -> None:
142143
"""Clean registries when removed devices found."""
143144
device_reg = dr.async_get(self.hass)
144145
device_list = dr.async_entries_for_config_entry(
145146
device_reg, self.config_entry.entry_id
146147
)
147148

148149
# First find the Plugwise via_device
149-
gateway_device = device_reg.async_get_device({(DOMAIN, data.gateway[GATEWAY_ID])})
150+
gateway_device = device_reg.async_get_device({(DOMAIN, self.api.gateway_id)})
150151
if gateway_device is not None:
151152
via_device_id = gateway_device.id
152153

@@ -156,7 +157,7 @@ async def async_remove_devices(self, data: PlugwiseData, entry: ConfigEntry) ->
156157
if identifier[0] == DOMAIN:
157158
if (
158159
device_entry.via_device_id == via_device_id
159-
and identifier[1] not in data.devices
160+
and identifier[1] not in data
160161
):
161162
device_reg.async_update_device(
162163
device_entry.id, remove_config_entry_id=entry.entry_id

custom_components/plugwise/diagnostics.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ async def async_get_config_entry_diagnostics(
1414
) -> dict[str, Any]:
1515
"""Return diagnostics for a config entry."""
1616
coordinator = entry.runtime_data
17-
return {
18-
"devices": coordinator.data.devices,
19-
"gateway": coordinator.data.gateway,
20-
}
17+
return coordinator.data

custom_components/plugwise/entity.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
AVAILABLE,
1717
DOMAIN,
1818
FIRMWARE,
19-
GATEWAY_ID,
2019
HARDWARE,
2120
MAC_ADDRESS,
2221
MODEL,
2322
MODEL_ID,
24-
SMILE_NAME,
2523
VENDOR,
2624
ZIGBEE_MAC_ADDRESS,
2725
)
@@ -48,7 +46,7 @@ def __init__(
4846
if entry := self.coordinator.config_entry:
4947
configuration_url = f"http://{entry.data[CONF_HOST]}"
5048

51-
data = coordinator.data.devices[device_id]
49+
data = coordinator.data[device_id]
5250
connections = set()
5351
if mac := data.get(MAC_ADDRESS):
5452
connections.add((CONNECTION_NETWORK_MAC, mac))
@@ -62,18 +60,18 @@ def __init__(
6260
manufacturer=data.get(VENDOR),
6361
model=data.get(MODEL),
6462
model_id=data.get(MODEL_ID),
65-
name=coordinator.data.gateway[SMILE_NAME],
63+
name=coordinator.api.smile_name,
6664
sw_version=data.get(FIRMWARE),
6765
hw_version=data.get(HARDWARE),
6866
)
6967

70-
if device_id != coordinator.data.gateway[GATEWAY_ID]:
68+
if device_id != coordinator.api.gateway_id:
7169
self._attr_device_info.update(
7270
{
7371
ATTR_NAME: data.get(ATTR_NAME),
7472
ATTR_VIA_DEVICE: (
7573
DOMAIN,
76-
str(self.coordinator.data.gateway[GATEWAY_ID]),
74+
str(self.coordinator.api.gateway_id),
7775
),
7876
}
7977
)
@@ -84,12 +82,12 @@ def available(self) -> bool:
8482
return (
8583
# Upstream: Do not change the AVAILABLE line below: some Plugwise devices and zones
8684
# Upstream: do not provide their availability-status!
87-
self._dev_id in self.coordinator.data.devices
85+
self._dev_id in self.coordinator.data
8886
and (AVAILABLE not in self.device or self.device[AVAILABLE] is True)
8987
and super().available
9088
)
9189

9290
@property
9391
def device(self) -> GwEntityData:
9492
"""Return data for this device."""
95-
return self.coordinator.data.devices[self._dev_id]
93+
return self.coordinator.data[self._dev_id]

custom_components/plugwise/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"integration_type": "hub",
88
"iot_class": "local_polling",
99
"loggers": ["plugwise"],
10-
"requirements": ["plugwise==1.6.4"],
11-
"version": "0.55.5",
10+
"requirements": ["plugwise==1.7.0"],
11+
"version": "0.56.0",
1212
"zeroconf": ["_plugwise._tcp.local."]
1313
}

0 commit comments

Comments
 (0)