Skip to content

Commit 43d0fa1

Browse files
committed
Adapt code
1 parent 07fc5b6 commit 43d0fa1

File tree

11 files changed

+139
-139
lines changed

11 files changed

+139
-139
lines changed

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.device_zones.items():
135+
for device_id, device in coordinator.data.entities.items():
136136
if device["dev_class"] != "heater_central":
137137
continue
138138

custom_components/plugwise/binary_sensor.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def async_setup_entry(
112112
@callback
113113
def _add_entities() -> None:
114114
"""Add Entities."""
115-
if not coordinator.new_device_zones:
115+
if not coordinator.new_pw_entities:
116116
return
117117

118118
# Upstream consts to HA
@@ -130,16 +130,16 @@ def _add_entities() -> None:
130130

131131
# pw-beta alternative for debugging
132132
entities: list[PlugwiseBinarySensorEntity] = []
133-
for device_id in coordinator.new_device_zones:
134-
device = coordinator.data.device_zones[device_id]
135-
if not (binary_sensors := device.get(BINARY_SENSORS)):
133+
for pw_entity_id in coordinator.new_pw_entities:
134+
pw_entity = coordinator.data.entities[pw_entity_id]
135+
if not (binary_sensors := pw_entity.get(BINARY_SENSORS)):
136136
continue
137137
for description in PLUGWISE_BINARY_SENSORS:
138138
if description.key not in binary_sensors:
139139
continue
140-
entities.append(PlugwiseBinarySensorEntity(coordinator, device_id, description))
140+
ha_entities.append(PlugwiseBinarySensorEntity(coordinator, pw_entity, description))
141141
LOGGER.debug(
142-
"Add %s %s binary sensor", device["name"], description.translation_key
142+
"Add %s %s binary sensor", pw_entity["name"], description.translation_key
143143
)
144144
async_add_entities(entities)
145145

@@ -155,13 +155,13 @@ class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
155155
def __init__(
156156
self,
157157
coordinator: PlugwiseDataUpdateCoordinator,
158-
device_id: str,
158+
pw_entity_id: str,
159159
description: PlugwiseBinarySensorEntityDescription,
160160
) -> None:
161161
"""Initialise the binary_sensor."""
162-
super().__init__(coordinator, device_id)
162+
super().__init__(coordinator, pw_entity_id)
163163
self.entity_description = description
164-
self._attr_unique_id = f"{device_id}-{description.key}"
164+
self._attr_unique_id = f"{pw_entity_id}-{description.key}"
165165
self._notification: dict[str, str] = {} # pw-beta
166166

167167
@property
@@ -174,12 +174,12 @@ def is_on(self) -> bool:
174174
self.hass, message, "Plugwise Notification:", f"{DOMAIN}.{notify_id}"
175175
)
176176

177-
return self.device_zone[BINARY_SENSORS][self.entity_description.key]
177+
return self.pw_entity[BINARY_SENSORS][self.entity_description.key]
178178

179179
@property
180180
def extra_state_attributes(self) -> Mapping[str, Any] | None:
181181
"""Return entity specific state attributes."""
182-
if self.entity_description.key != PLUGWISE_NOTIFICATION: # Upstream const
182+
if self.entity_dscription.key != PLUGWISE_NOTIFICATION: # Upstream const
183183
return None
184184

185185
# pw-beta adjustment with attrs is to only represent severities *with* content

custom_components/plugwise/button.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ async def async_setup_entry(
3636
# )
3737
# pw-beta alternative for debugging
3838
entities: list[PlugwiseButtonEntity] = []
39-
for device_id, device in coordinator.data.device_zones.items():
40-
if device_id == gateway[GATEWAY_ID] and REBOOT in gateway:
41-
entities.append(PlugwiseButtonEntity(coordinator, device_id))
42-
LOGGER.debug("Add %s reboot button", device["name"])
39+
for pw_entity_id, pw_entity in coordinator.data.entities.items():
40+
if pw_entity_id == gateway[GATEWAY_ID] and REBOOT in gateway:
41+
entities.append(PlugwiseButtonEntity(coordinator, pw_entity_id))
42+
LOGGER.debug("Add %s reboot button", pw_entity["name"])
4343
async_add_entities(entities)
4444

4545

@@ -52,12 +52,12 @@ class PlugwiseButtonEntity(PlugwiseEntity, ButtonEntity):
5252
def __init__(
5353
self,
5454
coordinator: PlugwiseDataUpdateCoordinator,
55-
device_id: str,
55+
pw_entity_id: str,
5656
) -> None:
5757
"""Initialize the button."""
58-
super().__init__(coordinator, device_id)
58+
super().__init__(coordinator, pw_entity_id)
5959
self._attr_translation_key = REBOOT
60-
self._attr_unique_id = f"{device_id}-reboot"
60+
self._attr_unique_id = f"{pw_entity_id}-reboot"
6161

6262
@plugwise_command
6363
async def async_press(self) -> None:

custom_components/plugwise/climate.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,33 +76,33 @@ async def async_setup_entry(
7676
@callback
7777
def _add_entities() -> None:
7878
"""Add Entities during init and runtime."""
79-
if not coordinator.new_device_zones:
79+
if not coordinator.new_pw_entities:
8080
return
8181

82-
climate_present = False
82+
thermostat_zone_present = False
8383
entities: list[PlugwiseClimateEntity] = []
84-
for devzone_id in coordinator.new_device_zones:
85-
devzone = coordinator.data.device_zones[devzone_id]
86-
if devzone[DEV_CLASS] == "climate":
87-
climate_present = True
88-
thermostat = coordinator.data.device_zones[devzone_id]
84+
for pw_entity_id in coordinator.new_pw_entities:
85+
pw_entity = coordinator.data.entities[pw_entity_id]
86+
if pw_entity[DEV_CLASS] == "climate":
87+
thermostat_zone_present = True
88+
thermostat = coordinator.data.entities[pw_entity_id]
8989
entities.append(
9090
PlugwiseClimateEntity(
91-
coordinator, devzone_id, homekit_enabled
91+
coordinator, pw_entity_id, homekit_enabled
9292
) # pw-beta homekit emulation
9393
)
9494
LOGGER.debug("Add climate %s", thermostat[ATTR_NAME])
9595

96-
if not climate_present:
97-
for device_id in coordinator.new_device_zones:
98-
device = coordinator.data.device_zones[device_id]
99-
if device[DEV_CLASS] in MASTER_THERMOSTATS:
96+
if not thermostat_zone_present:
97+
for pw_entity_id in coordinator.new_pw_entities:
98+
pw_entity = coordinator.data.entities[pw_entity_id]
99+
if pw_entity[DEV_CLASS] in MASTER_THERMOSTATS:
100100
entities.append(
101101
PlugwiseClimateEntity(
102-
coordinator, device_id, homekit_enabled
102+
coordinator, pw_entity_id, homekit_enabled
103103
) # pw-beta homekit emulation
104104
)
105-
LOGGER.debug("Add climate %s", device[ATTR_NAME])
105+
LOGGER.debug("Add climate %s", pw_entity[ATTR_NAME])
106106

107107
async_add_entities(entities)
108108

@@ -125,28 +125,28 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
125125
def __init__(
126126
self,
127127
coordinator: PlugwiseDataUpdateCoordinator,
128-
device_id: str,
128+
pw_entity_id: str,
129129
homekit_enabled: bool, # pw-beta homekit emulation
130130
) -> None:
131131
"""Set up the Plugwise API."""
132-
super().__init__(coordinator, device_id)
132+
super().__init__(coordinator, pw_entity_id)
133133

134134
self._homekit_enabled = homekit_enabled # pw-beta homekit emulation
135135

136-
self._location = device_id
137-
if (location := self.device_zone.get(LOCATION)) is not None:
136+
self._location = pw_entity_id
137+
if (location := self.pw_entity.get(LOCATION)) is not None:
138138
self._location = location
139139

140140
gateway_id: str = coordinator.data.gateway[GATEWAY_ID]
141-
self.gateway_data = coordinator.data.device_zones[gateway_id]
141+
self.gateway_data = coordinator.data.entities[gateway_id]
142142

143-
self._attr_max_temp = min(self.device_zone[THERMOSTAT][UPPER_BOUND], 35.0)
144-
self._attr_min_temp = self.device_zone[THERMOSTAT][LOWER_BOUND]
143+
self._attr_max_temp = min(self.pw_entity[THERMOSTAT][UPPER_BOUND], 35.0)
144+
self._attr_min_temp = self.pw_entity[THERMOSTAT][LOWER_BOUND]
145145
# Ensure we don't drop below 0.1
146146
self._attr_target_temperature_step = max(
147-
self.device_zone[THERMOSTAT][RESOLUTION], 0.1
147+
self.pw_entity[THERMOSTAT][RESOLUTION], 0.1
148148
)
149-
self._attr_unique_id = f"{device_id}-climate"
149+
self._attr_unique_id = f"{pw_entity_id}-climate"
150150

151151
# Determine supported features
152152
self.cdr_gateway = coordinator.data.gateway
@@ -162,7 +162,7 @@ def __init__(
162162
self._attr_supported_features |= (
163163
ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
164164
)
165-
if presets := self.device_zone["preset_modes"]: # can be NONE
165+
if presets := self.pw_entity["preset_modes"]: # can be NONE
166166
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
167167
self._attr_preset_modes = presets
168168

@@ -183,7 +183,7 @@ def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> N
183183
@property
184184
def current_temperature(self) -> float:
185185
"""Return the current temperature."""
186-
return self.device_zone[SENSORS][ATTR_TEMPERATURE]
186+
return self.pw_entity[SENSORS][ATTR_TEMPERATURE]
187187

188188
@property
189189
def target_temperature(self) -> float:
@@ -192,29 +192,29 @@ def target_temperature(self) -> float:
192192
Connected to the HVACMode combination of AUTO-HEAT.
193193
"""
194194

195-
return self.device_zone[THERMOSTAT][TARGET_TEMP]
195+
return self.pw_entity[THERMOSTAT][TARGET_TEMP]
196196

197197
@property
198198
def target_temperature_high(self) -> float:
199199
"""Return the temperature we try to reach in case of cooling.
200200
201201
Connected to the HVACMode combination of AUTO-HEAT_COOL.
202202
"""
203-
return self.device_zone[THERMOSTAT][TARGET_TEMP_HIGH]
203+
return self.pw_entity[THERMOSTAT][TARGET_TEMP_HIGH]
204204

205205
@property
206206
def target_temperature_low(self) -> float:
207207
"""Return the heating temperature we try to reach in case of heating.
208208
209209
Connected to the HVACMode combination AUTO-HEAT_COOL.
210210
"""
211-
return self.device_zone[THERMOSTAT][TARGET_TEMP_LOW]
211+
return self.pw_entity[THERMOSTAT][TARGET_TEMP_LOW]
212212

213213
@property
214214
def hvac_mode(self) -> HVACMode:
215215
"""Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
216216
if (
217-
mode := self.device_zone[CLIMATE_MODE]
217+
mode := self.pw_entity[CLIMATE_MODE]
218218
) is None or mode not in self.hvac_modes: # pw-beta add to Core
219219
return HVACMode.HEAT # pragma: no cover
220220
# pw-beta homekit emulation
@@ -233,7 +233,7 @@ def hvac_modes(self) -> list[HVACMode]:
233233
):
234234
hvac_modes.append(HVACMode.OFF)
235235

236-
if AVAILABLE_SCHEDULES in self.device_zone:
236+
if AVAILABLE_SCHEDULES in self.pw_entity:
237237
hvac_modes.append(HVACMode.AUTO)
238238

239239
if self.cdr_gateway[COOLING_PRESENT]:
@@ -256,14 +256,14 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
256256
self._previous_action_mode(self.coordinator)
257257

258258
# Adam provides the hvac_action for each thermostat
259-
if (control_state := self.device_zone.get(CONTROL_STATE)) in (HVACAction.COOLING, HVACAction.HEATING, HVACAction.PREHEATING):
259+
if (control_state := self.pw_entity.get(CONTROL_STATE)) in (HVACAction.COOLING, HVACAction.HEATING, HVACAction.PREHEATING):
260260
return cast(HVACAction, control_state)
261261
if control_state == HVACMode.OFF:
262262
return HVACAction.IDLE
263263

264264
# Anna
265265
heater: str = self.coordinator.data.gateway["heater_id"]
266-
heater_data = self.coordinator.data.device_zones[heater]
266+
heater_data = self.coordinator.data.entities[heater]
267267
if heater_data[BINARY_SENSORS][HEATING_STATE]:
268268
return HVACAction.HEATING
269269
if heater_data[BINARY_SENSORS].get(COOLING_STATE, False):
@@ -274,7 +274,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
274274
@property
275275
def preset_mode(self) -> str | None:
276276
"""Return the current preset mode."""
277-
return self.device_zone[ACTIVE_PRESET]
277+
return self.pw_entity[ACTIVE_PRESET]
278278

279279
@plugwise_command
280280
async def async_set_temperature(self, **kwargs: Any) -> None:

custom_components/plugwise/coordinator.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ def __init__(
6969
username=self.config_entry.data[CONF_USERNAME],
7070
websession=async_get_clientsession(hass, verify_ssl=False),
7171
)
72-
self._current_device_zones: set[str] = set()
73-
self.new_device_zones: set[str] = set()
72+
self._current_pw_entities: set[str] = set()
73+
self.new_pw_entities: set[str] = set()
7474
self.update_interval = update_interval
7575

7676
async def _connect(self) -> None:
7777
"""Connect to the Plugwise Smile."""
7878
version = await self.api.connect()
7979
self._connected = isinstance(version, Version)
8080
if self._connected:
81-
self.api.get_all_device_zones()
81+
self.api.get_all_gateway_entities()
8282
self.update_interval = DEFAULT_SCAN_INTERVAL.get(
8383
self.api.smile_type, timedelta(seconds=60)
8484
) # pw-beta options scan-interval
@@ -91,7 +91,7 @@ async def _connect(self) -> None:
9191

9292
async def _async_update_data(self) -> PlugwiseData:
9393
"""Fetch data from Plugwise."""
94-
data = PlugwiseData(device_zones={}, gateway={})
94+
data = PlugwiseData(entities={}, gateway={})
9595
try:
9696
if not self._connected:
9797
await self._connect()
@@ -110,24 +110,24 @@ async def _async_update_data(self) -> PlugwiseData:
110110
raise ConfigEntryError("Device with unsupported firmware") from err
111111
else:
112112
LOGGER.debug(f"{self.api.smile_name} data: %s", data)
113-
await self.async_add_remove_devices_zones(data, self.config_entry)
113+
await self.async_add_remove_plugise_entities(data, self.config_entry)
114114

115115
return data
116116

117-
async def async_add_remove_devices_zones(self, data: PlugwiseData, entry: ConfigEntry) -> None:
118-
"""Add new Plugwise devices, remove non-existing devices."""
119-
# Check for new or removed devices
120-
self.new_device_zones = set(data.device_zones) - self._current_device_zones
121-
removed_device_zones = self._current_device_zones - set(data.device_zones)
122-
self._current_device_zones = set(data.device_zones)
117+
async def async_add_remove_plugwise_entities(self, data: PlugwiseData, entry: ConfigEntry) -> None:
118+
"""Add new Plugwise entities, remove non-existing entities."""
119+
# Check for new or removed entities
120+
self.new_pw_entities = set(data.entities) - self._current_pw_entities
121+
removed_pw_entities = self._current_pw_entities - set(data.entities)
122+
self._current_pw_entities = set(data.entities)
123123

124-
if removed_device_zones:
125-
await self.async_remove_device_zones(data, entry)
124+
if removed_pw_entities:
125+
await self.async_remove_plugwise_entities(data, entry)
126126

127-
async def async_remove_device_zones(self, data: PlugwiseData, entry: ConfigEntry) -> None:
128-
"""Clean registries when removed devices or zones found."""
127+
async def async_remove_plugwise_entities(self, data: PlugwiseData, entry: ConfigEntry) -> None:
128+
"""Clean registries when removed Plugwise entities."""
129129
device_reg = dr.async_get(self.hass)
130-
device_zone_list = dr.async_entries_for_config_entry(
130+
pw_entities_list = dr.async_entries_for_config_entry(
131131
device_reg, self.config_entry.entry_id
132132
)
133133

@@ -137,7 +137,7 @@ async def async_remove_device_zones(self, data: PlugwiseData, entry: ConfigEntry
137137
via_device_id = gateway_device.id
138138

139139
# Then remove the connected orphaned device(s)
140-
for device_entry in device_zone_list:
140+
for device_entry in pw_entities_list:
141141
for identifier in device_entry.identifiers:
142142
if identifier[0] == DOMAIN:
143143
if (

custom_components/plugwise/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ async def async_get_config_entry_diagnostics(
1515
"""Return diagnostics for a config entry."""
1616
coordinator = entry.runtime_data
1717
return {
18-
"devices": coordinator.data.device_zones,
18+
"entities": coordinator.data.entities,
1919
"gateway": coordinator.data.gateway,
2020
}

0 commit comments

Comments
 (0)