Diff to HTML by rtfpessoa

Files changed (17) hide show
  1. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/__init__.py +20 -88
  2. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/binary_sensor.py +38 -97
  3. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/button.py +9 -18
  4. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/climate.py +177 -202
  5. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/config_flow.py +37 -142
  6. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/const.py +45 -152
  7. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/coordinator.py +86 -80
  8. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/diagnostics.py +0 -2
  9. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/entity.py +26 -29
  10. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/icons.json +6 -9
  11. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/manifest.json +4 -4
  12. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/number.py +27 -57
  13. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/select.py +78 -57
  14. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/sensor.py +103 -174
  15. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/strings.json +59 -61
  16. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/switch.py +28 -57
  17. /home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/util.py +5 -12
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/__init__.py RENAMED
@@ -1,47 +1,22 @@
1
  """Plugwise platform for Home Assistant Core."""
2
 
3
- from __future__ import annotations
4
-
5
  from typing import Any
6
 
7
- from plugwise.exceptions import PlugwiseError
8
- import voluptuous as vol # pw-beta delete_notification
9
-
10
- from homeassistant.const import CONF_TIMEOUT, Platform
11
- from homeassistant.core import (
12
- HomeAssistant,
13
- ServiceCall, # pw-beta delete_notification
14
- callback,
15
- )
16
  from homeassistant.helpers import device_registry as dr, entity_registry as er
17
 
18
- from .const import (
19
- CONF_REFRESH_INTERVAL, # pw-beta options
20
- DOMAIN,
21
- LOGGER,
22
- PLATFORMS,
23
- SERVICE_DELETE, # pw-beta delete_notifications
24
- )
25
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
26
 
27
 
28
  async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
29
- """Set up Plugwise from a config entry."""
30
  await er.async_migrate_entries(hass, entry.entry_id, async_migrate_entity_entry)
31
 
32
- cooldown = 1.5 # pw-beta frontend refresh-interval
33
- if (
34
- custom_refresh := entry.options.get(CONF_REFRESH_INTERVAL)
35
- ) is not None: # pragma: no cover
36
- cooldown = custom_refresh
37
- LOGGER.debug("DUC cooldown interval: %s", cooldown)
38
-
39
- coordinator = PlugwiseDataUpdateCoordinator(
40
- hass, cooldown, entry
41
- ) # pw-beta - cooldown, update_interval as extra
42
  await coordinator.async_config_entry_first_refresh()
43
-
44
- await async_migrate_sensor_entities(hass, coordinator)
45
 
46
  entry.runtime_data = coordinator
47
 
@@ -56,49 +31,22 @@
56
  sw_version=str(coordinator.api.smile.version),
57
  ) # required for adding the entity-less P1 Gateway
58
 
59
- async def delete_notification(
60
- call: ServiceCall,
61
- ) -> None: # pragma: no cover # pw-beta: HA service - delete_notification
62
- """Service: delete the Plugwise Notification."""
63
- LOGGER.debug(
64
- "Service delete PW Notification called for %s",
65
- coordinator.api.smile.name,
66
- )
67
- try:
68
- await coordinator.api.delete_notification()
69
- LOGGER.debug("PW Notification deleted")
70
- except PlugwiseError:
71
- LOGGER.debug(
72
- "Failed to delete the Plugwise Notification for %s",
73
- coordinator.api.smile.name,
74
- )
75
-
76
  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
77
 
78
- entry.async_on_unload(entry.add_update_listener(update_listener)) # pw-beta options_flow
79
- for component in PLATFORMS: # pw-beta delete_notification
80
- if component == Platform.BINARY_SENSOR:
81
- hass.services.async_register(
82
- DOMAIN, SERVICE_DELETE, delete_notification, schema=vol.Schema({})
83
- )
84
-
85
  return True
86
 
87
- async def update_listener(
88
- hass: HomeAssistant, entry: PlugwiseConfigEntry
89
- ) -> None: # pragma: no cover # pw-beta
90
- """Handle options update."""
91
- await hass.config_entries.async_reload(entry.entry_id)
92
 
93
  async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
94
- """Unload Plugwise."""
95
  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
96
 
 
97
  @callback
98
  def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None:
99
  """Migrate Plugwise entity entries.
100
 
101
- - Migrates old unique ID's from old binary_sensors and switches to the new unique ID's
 
102
  """
103
  if entry.domain == Platform.BINARY_SENSOR and entry.unique_id.endswith(
104
  "-slave_boiler_state"
@@ -120,17 +68,18 @@
120
  # No migration needed
121
  return None
122
 
123
- async def async_migrate_sensor_entities(
 
124
  hass: HomeAssistant,
125
  coordinator: PlugwiseDataUpdateCoordinator,
126
  ) -> None:
127
  """Migrate Sensors if needed."""
128
  ent_reg = er.async_get(hass)
129
 
130
- # Migrate opentherm_outdoor_temperature
131
  # to opentherm_outdoor_air_temperature sensor
132
  for device_id, device in coordinator.data.items():
133
- if device["dev_class"] != "heater_central":
134
  continue
135
 
136
  old_unique_id = f"{device_id}-outdoor_temperature"
@@ -138,27 +87,10 @@
138
  Platform.SENSOR, DOMAIN, old_unique_id
139
  ):
140
  new_unique_id = f"{device_id}-outdoor_air_temperature"
141
- # Upstream remove LOGGER debug
 
 
 
 
 
142
  ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
143
-
144
- # pw-beta only - revert adding CONF_TIMEOUT to config_entry in v0.53.3
145
- async def async_migrate_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
146
- """Migrate back to v1.1 config entry."""
147
- if entry.version > 1:
148
- # This means the user has downgraded from a future version
149
- return False #pragma: no cover
150
-
151
- if entry.version == 1 and entry.minor_version == 2:
152
- new_data = {**entry.data}
153
- new_data.pop(CONF_TIMEOUT)
154
- hass.config_entries.async_update_entry(
155
- entry, data=new_data, minor_version=1, version=1
156
- )
157
-
158
- LOGGER.debug(
159
- "Migration to version %s.%s successful",
160
- entry.version,
161
- entry.minor_version,
162
- )
163
-
164
- return True
 
1
  """Plugwise platform for Home Assistant Core."""
2
 
 
 
3
  from typing import Any
4
 
5
+ from homeassistant.const import Platform
6
+ from homeassistant.core import HomeAssistant, callback
 
 
 
 
 
 
 
7
  from homeassistant.helpers import device_registry as dr, entity_registry as er
8
 
9
+ from .const import DEV_CLASS, DOMAIN, LOGGER, PLATFORMS
 
 
 
 
 
 
10
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
11
 
12
 
13
  async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
14
+ """Set up Plugwise components from a config entry."""
15
  await er.async_migrate_entries(hass, entry.entry_id, async_migrate_entity_entry)
16
 
17
+ coordinator = PlugwiseDataUpdateCoordinator(hass, entry)
 
 
 
 
 
 
 
 
 
18
  await coordinator.async_config_entry_first_refresh()
19
+ migrate_sensor_entities(hass, coordinator)
 
20
 
21
  entry.runtime_data = coordinator
22
 
 
31
  sw_version=str(coordinator.api.smile.version),
32
  ) # required for adding the entity-less P1 Gateway
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
35
 
 
 
 
 
 
 
 
36
  return True
37
 
 
 
 
 
 
38
 
39
  async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
40
+ """Unload the Plugwise components."""
41
  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
42
 
43
+
44
  @callback
45
  def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None:
46
  """Migrate Plugwise entity entries.
47
 
48
+ Migrates old unique ID's from old binary_sensors and
49
+ switches to the new unique ID's.
50
  """
51
  if entry.domain == Platform.BINARY_SENSOR and entry.unique_id.endswith(
52
  "-slave_boiler_state"
 
68
  # No migration needed
69
  return None
70
 
71
+
72
+ def migrate_sensor_entities(
73
  hass: HomeAssistant,
74
  coordinator: PlugwiseDataUpdateCoordinator,
75
  ) -> None:
76
  """Migrate Sensors if needed."""
77
  ent_reg = er.async_get(hass)
78
 
79
+ # Migrating opentherm_outdoor_temperature
80
  # to opentherm_outdoor_air_temperature sensor
81
  for device_id, device in coordinator.data.items():
82
+ if device[DEV_CLASS] != "heater_central":
83
  continue
84
 
85
  old_unique_id = f"{device_id}-outdoor_temperature"
 
87
  Platform.SENSOR, DOMAIN, old_unique_id
88
  ):
89
  new_unique_id = f"{device_id}-outdoor_air_temperature"
90
+ LOGGER.debug(
91
+ "Migrating entity %s from old unique ID '%s' to new unique ID '%s'",
92
+ entity_id,
93
+ old_unique_id,
94
+ new_unique_id,
95
+ )
96
  ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/binary_sensor.py RENAMED
@@ -1,16 +1,11 @@
1
  """Plugwise Binary Sensor component for Home Assistant."""
2
 
3
- from __future__ import annotations
4
-
5
  from collections.abc import Mapping
6
  from dataclasses import dataclass
7
- from typing import Any
8
 
9
  from plugwise.constants import BinarySensorType
10
 
11
- from homeassistant.components import (
12
- persistent_notification, # pw-beta Plugwise notifications
13
- )
14
  from homeassistant.components.binary_sensor import (
15
  BinarySensorDeviceClass,
16
  BinarySensorEntity,
@@ -20,26 +15,11 @@
20
  from homeassistant.core import HomeAssistant, callback
21
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
22
 
23
- from .const import (
24
- BATTERY_STATE,
25
- BINARY_SENSORS,
26
- COMPRESSOR_STATE,
27
- COOLING_ENABLED,
28
- COOLING_STATE,
29
- DHW_STATE,
30
- DOMAIN,
31
- FLAME_STATE,
32
- HEATING_STATE,
33
- LOGGER, # pw-beta
34
- PLUGWISE_NOTIFICATION,
35
- SECONDARY_BOILER_STATE,
36
- SEVERITIES,
37
- )
38
-
39
- # Upstream
40
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
41
  from .entity import PlugwiseEntity
42
 
 
 
43
  # Coordinator is used to centralize the data updates
44
  PARALLEL_UPDATES = 0
45
 
@@ -51,51 +31,50 @@
51
  key: BinarySensorType
52
 
53
 
54
- # Upstream PLUGWISE_BINARY_SENSORS
55
- PLUGWISE_BINARY_SENSORS: tuple[PlugwiseBinarySensorEntityDescription, ...] = (
56
  PlugwiseBinarySensorEntityDescription(
57
- key=BATTERY_STATE,
58
  device_class=BinarySensorDeviceClass.BATTERY,
59
  entity_category=EntityCategory.DIAGNOSTIC,
60
  ),
61
  PlugwiseBinarySensorEntityDescription(
62
- key=COMPRESSOR_STATE,
63
- translation_key=COMPRESSOR_STATE,
64
  entity_category=EntityCategory.DIAGNOSTIC,
65
  ),
66
  PlugwiseBinarySensorEntityDescription(
67
- key=COOLING_ENABLED,
68
- translation_key=COOLING_ENABLED,
69
  entity_category=EntityCategory.DIAGNOSTIC,
70
  ),
71
  PlugwiseBinarySensorEntityDescription(
72
- key=DHW_STATE,
73
- translation_key=DHW_STATE,
74
  entity_category=EntityCategory.DIAGNOSTIC,
75
  ),
76
  PlugwiseBinarySensorEntityDescription(
77
- key=FLAME_STATE,
78
- translation_key=FLAME_STATE,
79
  entity_category=EntityCategory.DIAGNOSTIC,
80
  ),
81
  PlugwiseBinarySensorEntityDescription(
82
- key=HEATING_STATE,
83
- translation_key=HEATING_STATE,
84
  entity_category=EntityCategory.DIAGNOSTIC,
85
  ),
86
  PlugwiseBinarySensorEntityDescription(
87
- key=COOLING_STATE,
88
- translation_key=COOLING_STATE,
89
  entity_category=EntityCategory.DIAGNOSTIC,
90
  ),
91
  PlugwiseBinarySensorEntityDescription(
92
- key=SECONDARY_BOILER_STATE,
93
- translation_key=SECONDARY_BOILER_STATE,
94
  entity_category=EntityCategory.DIAGNOSTIC,
95
  ),
96
  PlugwiseBinarySensorEntityDescription(
97
- key=PLUGWISE_NOTIFICATION,
98
- translation_key=PLUGWISE_NOTIFICATION,
99
  entity_category=EntityCategory.DIAGNOSTIC,
100
  ),
101
  )
@@ -106,7 +85,7 @@
106
  entry: PlugwiseConfigEntry,
107
  async_add_entities: AddConfigEntryEntitiesCallback,
108
  ) -> None:
109
- """Set up Plugwise binary_sensors from a config entry."""
110
  coordinator = entry.runtime_data
111
 
112
  @callback
@@ -115,40 +94,20 @@
115
  if not coordinator.new_devices:
116
  return
117
 
118
- # Upstream consts to HA
119
- # async_add_entities(
120
- # PlugwiseBinarySensorEntity(coordinator, device_id, description)
121
- # for device_id in coordinator.new_devices
122
- # if (
123
- # binary_sensors := coordinator.data.devices[device_id].get(
124
- # BINARY_SENSORS
125
- # )
126
- # )
127
- # for description in PLUGWISE_BINARY_SENSORS
128
- # if description.key in binary_sensors
129
- # )
130
-
131
- # pw-beta alternative for debugging
132
- entities: list[PlugwiseBinarySensorEntity] = []
133
- for device_id in coordinator.new_devices:
134
- device = coordinator.data[device_id]
135
- if not (binary_sensors := device.get(BINARY_SENSORS)):
136
- continue
137
- for description in PLUGWISE_BINARY_SENSORS:
138
- if description.key not in binary_sensors:
139
- continue
140
- entities.append(PlugwiseBinarySensorEntity(coordinator, device_id, description))
141
- LOGGER.debug(
142
- "Add %s %s binary sensor", device["name"], description.translation_key or description.key
143
- )
144
- async_add_entities(entities)
145
 
146
  _add_entities()
147
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
148
 
149
 
150
  class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
151
- """Set up Plugwise binary_sensors from a config entry."""
152
 
153
  entity_description: PlugwiseBinarySensorEntityDescription
154
 
@@ -162,46 +121,28 @@
162
  super().__init__(coordinator, device_id)
163
  self.entity_description = description
164
  self._attr_unique_id = f"{device_id}-{description.key}"
165
- self._notification: dict[str, str] = {} # pw-beta
166
 
167
  @property
168
- def is_on(self) -> bool | None:
 
169
  """Return true if the binary sensor is on."""
170
- # pw-beta: show Plugwise notifications as HA persistent notifications
171
- if self._notification:
172
- for notify_id, message in self._notification.items():
173
- persistent_notification.async_create(
174
- self.hass, message, "Plugwise Notification:", f"{DOMAIN}.{notify_id}"
175
- )
176
-
177
- return self.device.get(BINARY_SENSORS, {}).get(self.entity_description.key)
178
 
179
  @property
 
180
  def extra_state_attributes(self) -> Mapping[str, Any] | None:
181
  """Return entity specific state attributes."""
182
- if self.entity_description.key != PLUGWISE_NOTIFICATION: # Upstream const
183
  return None
184
 
185
- # pw-beta adjustment with attrs is to only represent severities *with* content
186
- # not all severities including those without content as empty lists
187
- attrs: dict[str, list[str]] = {} # pw-beta Re-evaluate against Core
188
- self._notification = {} # pw-beta
189
  gateway_id = self.coordinator.api.gateway_id
190
  if notify := self.coordinator.data[gateway_id]["notifications"]:
191
- for notify_id, details in notify.items(): # pw-beta uses notify_id
192
  for msg_type, msg in details.items():
193
  msg_type = msg_type.lower()
194
  if msg_type not in SEVERITIES:
195
- msg_type = "other" # pragma: no cover
196
-
197
- if (
198
- f"{msg_type}_msg" not in attrs
199
- ): # pw-beta Re-evaluate against Core
200
- attrs[f"{msg_type}_msg"] = []
201
  attrs[f"{msg_type}_msg"].append(msg)
202
 
203
- self._notification[
204
- notify_id
205
- ] = f"{msg_type.title()}: {msg}" # pw-beta
206
-
207
  return attrs
 
1
  """Plugwise Binary Sensor component for Home Assistant."""
2
 
 
 
3
  from collections.abc import Mapping
4
  from dataclasses import dataclass
5
+ from typing import Any, override
6
 
7
  from plugwise.constants import BinarySensorType
8
 
 
 
 
9
  from homeassistant.components.binary_sensor import (
10
  BinarySensorDeviceClass,
11
  BinarySensorEntity,
 
15
  from homeassistant.core import HomeAssistant, callback
16
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
19
  from .entity import PlugwiseEntity
20
 
21
+ SEVERITIES = ["other", "info", "warning", "error"]
22
+
23
  # Coordinator is used to centralize the data updates
24
  PARALLEL_UPDATES = 0
25
 
 
31
  key: BinarySensorType
32
 
33
 
34
+ BINARY_SENSORS: tuple[PlugwiseBinarySensorEntityDescription, ...] = (
 
35
  PlugwiseBinarySensorEntityDescription(
36
+ key="low_battery",
37
  device_class=BinarySensorDeviceClass.BATTERY,
38
  entity_category=EntityCategory.DIAGNOSTIC,
39
  ),
40
  PlugwiseBinarySensorEntityDescription(
41
+ key="compressor_state",
42
+ translation_key="compressor_state",
43
  entity_category=EntityCategory.DIAGNOSTIC,
44
  ),
45
  PlugwiseBinarySensorEntityDescription(
46
+ key="cooling_enabled",
47
+ translation_key="cooling_enabled",
48
  entity_category=EntityCategory.DIAGNOSTIC,
49
  ),
50
  PlugwiseBinarySensorEntityDescription(
51
+ key="dhw_state",
52
+ translation_key="dhw_state",
53
  entity_category=EntityCategory.DIAGNOSTIC,
54
  ),
55
  PlugwiseBinarySensorEntityDescription(
56
+ key="flame_state",
57
+ translation_key="flame_state",
58
  entity_category=EntityCategory.DIAGNOSTIC,
59
  ),
60
  PlugwiseBinarySensorEntityDescription(
61
+ key="heating_state",
62
+ translation_key="heating_state",
63
  entity_category=EntityCategory.DIAGNOSTIC,
64
  ),
65
  PlugwiseBinarySensorEntityDescription(
66
+ key="cooling_state",
67
+ translation_key="cooling_state",
68
  entity_category=EntityCategory.DIAGNOSTIC,
69
  ),
70
  PlugwiseBinarySensorEntityDescription(
71
+ key="secondary_boiler_state",
72
+ translation_key="secondary_boiler_state",
73
  entity_category=EntityCategory.DIAGNOSTIC,
74
  ),
75
  PlugwiseBinarySensorEntityDescription(
76
+ key="plugwise_notification",
77
+ translation_key="plugwise_notification",
78
  entity_category=EntityCategory.DIAGNOSTIC,
79
  ),
80
  )
 
85
  entry: PlugwiseConfigEntry,
86
  async_add_entities: AddConfigEntryEntitiesCallback,
87
  ) -> None:
88
+ """Set up the Smile binary_sensors from a config entry."""
89
  coordinator = entry.runtime_data
90
 
91
  @callback
 
94
  if not coordinator.new_devices:
95
  return
96
 
97
+ async_add_entities(
98
+ PlugwiseBinarySensorEntity(coordinator, device_id, description)
99
+ for device_id in coordinator.new_devices
100
+ if (binary_sensors := coordinator.data[device_id].get("binary_sensors"))
101
+ for description in BINARY_SENSORS
102
+ if description.key in binary_sensors
103
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  _add_entities()
106
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
107
 
108
 
109
  class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity):
110
+ """Represent Smile Binary Sensors."""
111
 
112
  entity_description: PlugwiseBinarySensorEntityDescription
113
 
 
121
  super().__init__(coordinator, device_id)
122
  self.entity_description = description
123
  self._attr_unique_id = f"{device_id}-{description.key}"
 
124
 
125
  @property
126
+ @override
127
+ def is_on(self) -> bool:
128
  """Return true if the binary sensor is on."""
129
+ return self.device["binary_sensors"][self.entity_description.key]
 
 
 
 
 
 
 
130
 
131
  @property
132
+ @override
133
  def extra_state_attributes(self) -> Mapping[str, Any] | None:
134
  """Return entity specific state attributes."""
135
+ if self.entity_description.key != "plugwise_notification":
136
  return None
137
 
138
+ attrs: dict[str, list[str]] = {f"{severity}_msg": [] for severity in SEVERITIES}
 
 
 
139
  gateway_id = self.coordinator.api.gateway_id
140
  if notify := self.coordinator.data[gateway_id]["notifications"]:
141
+ for details in notify.values():
142
  for msg_type, msg in details.items():
143
  msg_type = msg_type.lower()
144
  if msg_type not in SEVERITIES:
145
+ msg_type = "other"
 
 
 
 
 
146
  attrs[f"{msg_type}_msg"].append(msg)
147
 
 
 
 
 
148
  return attrs
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/button.py RENAMED
@@ -1,16 +1,13 @@
1
  """Plugwise Button component for Home Assistant."""
2
 
3
- from __future__ import annotations
4
 
5
  from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
6
  from homeassistant.const import EntityCategory
7
  from homeassistant.core import HomeAssistant
8
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
9
 
10
- from .const import (
11
- LOGGER, # pw-betea
12
- REBOOT,
13
- )
14
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
15
  from .entity import PlugwiseEntity
16
  from .util import plugwise_command
@@ -23,21 +20,14 @@
23
  entry: PlugwiseConfigEntry,
24
  async_add_entities: AddConfigEntryEntitiesCallback,
25
  ) -> None:
26
- """Set up Plugwise buttons from a config entry."""
27
  coordinator = entry.runtime_data
28
 
29
- # async_add_entities(
30
- # PlugwiseButtonEntity(coordinator, device_id)
31
- # for device_id in coordinator.data.devices
32
- # if device_id == gateway[GATEWAY_ID] and REBOOT in gateway
33
- # )
34
- # pw-beta alternative for debugging
35
- entities: list[PlugwiseButtonEntity] = []
36
- for device_id, device in coordinator.data.items():
37
- if device_id == coordinator.api.gateway_id and coordinator.api.reboot:
38
- entities.append(PlugwiseButtonEntity(coordinator, device_id))
39
- LOGGER.debug("Add %s reboot button", device["name"])
40
- async_add_entities(entities)
41
 
42
 
43
  class PlugwiseButtonEntity(PlugwiseEntity, ButtonEntity):
@@ -57,6 +47,7 @@
57
  self._attr_unique_id = f"{device_id}-reboot"
58
 
59
  @plugwise_command
 
60
  async def async_press(self) -> None:
61
  """Triggers the Plugwise button press service."""
62
  await self.coordinator.api.reboot_gateway()
 
1
  """Plugwise Button component for Home Assistant."""
2
 
3
+ from typing import override
4
 
5
  from homeassistant.components.button import ButtonDeviceClass, ButtonEntity
6
  from homeassistant.const import EntityCategory
7
  from homeassistant.core import HomeAssistant
8
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
9
 
10
+ from .const import REBOOT
 
 
 
11
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
12
  from .entity import PlugwiseEntity
13
  from .util import plugwise_command
 
20
  entry: PlugwiseConfigEntry,
21
  async_add_entities: AddConfigEntryEntitiesCallback,
22
  ) -> None:
23
+ """Set up the Plugwise buttons from a ConfigEntry."""
24
  coordinator = entry.runtime_data
25
 
26
+ async_add_entities(
27
+ PlugwiseButtonEntity(coordinator, device_id)
28
+ for device_id in coordinator.data
29
+ if device_id == coordinator.api.gateway_id and coordinator.api.reboot
30
+ )
 
 
 
 
 
 
 
31
 
32
 
33
  class PlugwiseButtonEntity(PlugwiseEntity, ButtonEntity):
 
47
  self._attr_unique_id = f"{device_id}-reboot"
48
 
49
  @plugwise_command
50
+ @override
51
  async def async_press(self) -> None:
52
  """Triggers the Plugwise button press service."""
53
  await self.coordinator.api.reboot_gateway()
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/climate.py RENAMED
@@ -1,55 +1,24 @@
1
  """Plugwise Climate component for Home Assistant."""
2
 
3
- from __future__ import annotations
4
-
5
- from dataclasses import dataclass
6
- from typing import Any
7
 
8
  from homeassistant.components.climate import (
9
  ATTR_HVAC_MODE,
10
  ATTR_TARGET_TEMP_HIGH,
11
  ATTR_TARGET_TEMP_LOW,
12
- PRESET_AWAY, # pw-beta homekit emulation
13
- PRESET_HOME, # pw-beta homekit emulation
14
  ClimateEntity,
15
  ClimateEntityFeature,
16
  HVACAction,
17
  HVACMode,
18
  )
19
- from homeassistant.const import (
20
- ATTR_NAME,
21
- ATTR_TEMPERATURE,
22
- STATE_OFF,
23
- STATE_ON,
24
- UnitOfTemperature,
25
- )
26
  from homeassistant.core import HomeAssistant, callback
27
  from homeassistant.exceptions import HomeAssistantError
28
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
29
  from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
30
 
31
- from .const import (
32
- ACTIVE_PRESET,
33
- AVAILABLE_SCHEDULES,
34
- CLIMATE_MODE,
35
- CONF_HOMEKIT_EMULATION, # pw-beta homekit emulation
36
- CONTROL_STATE,
37
- DEV_CLASS,
38
- DOMAIN,
39
- LOCATION,
40
- LOGGER,
41
- LOWER_BOUND,
42
- MASTER_THERMOSTATS,
43
- REGULATION_MODES,
44
- RESOLUTION,
45
- SELECT_REGULATION_MODE,
46
- SENSORS,
47
- TARGET_TEMP,
48
- TARGET_TEMP_HIGH,
49
- TARGET_TEMP_LOW,
50
- THERMOSTAT,
51
- UPPER_BOUND,
52
- )
53
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
54
  from .entity import PlugwiseEntity
55
  from .util import plugwise_command
@@ -58,47 +27,14 @@
58
  PARALLEL_UPDATES = 0
59
 
60
 
61
- async def async_setup_entry(
62
- hass: HomeAssistant,
63
- entry: PlugwiseConfigEntry,
64
- async_add_entities: AddConfigEntryEntitiesCallback,
65
- ) -> None:
66
- """Set up Plugwise thermostats from a config entry."""
67
- coordinator = entry.runtime_data
68
- homekit_enabled: bool = entry.options.get(
69
- CONF_HOMEKIT_EMULATION, False
70
- ) # pw-beta homekit emulation
71
-
72
- @callback
73
- def _add_entities() -> None:
74
- """Add Entities during init and runtime."""
75
- if not coordinator.new_devices:
76
- return
77
-
78
- entities: list[PlugwiseClimateEntity] = []
79
- gateway_name = coordinator.api.smile.name
80
- for device_id in coordinator.new_devices:
81
- device = coordinator.data[device_id]
82
- if gateway_name == "Adam":
83
- if device[DEV_CLASS] == "climate":
84
- entities.append(
85
- PlugwiseClimateEntity(
86
- coordinator, device_id, homekit_enabled
87
- ) # pw-beta homekit emulation
88
- )
89
- LOGGER.debug("Add climate %s", device[ATTR_NAME])
90
- elif device[DEV_CLASS] in MASTER_THERMOSTATS:
91
- entities.append(
92
- PlugwiseClimateEntity(
93
- coordinator, device_id, homekit_enabled
94
- ) # pw-beta homekit emulation
95
- )
96
- LOGGER.debug("Add climate %s", device[ATTR_NAME])
97
-
98
- async_add_entities(entities)
99
-
100
- _add_entities()
101
- entry.async_on_unload(coordinator.async_add_listener(_add_entities))
102
 
103
 
104
  @dataclass
@@ -108,12 +44,10 @@
108
  last_active_schedule: str | None
109
  previous_action_mode: str | None
110
 
 
111
  def as_dict(self) -> dict[str, Any]:
112
  """Return a dict representation of the text data."""
113
- return {
114
- "last_active_schedule": self.last_active_schedule,
115
- "previous_action_mode": self.previous_action_mode,
116
- }
117
 
118
  @classmethod
119
  def from_dict(cls, restored: dict[str, Any]) -> PlugwiseClimateExtraStoredData:
@@ -124,60 +58,65 @@
124
  )
125
 
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity, RestoreEntity):
128
  """Representation of a Plugwise thermostat."""
129
 
130
- _attr_has_entity_name = True
131
  _attr_name = None
132
  _attr_temperature_unit = UnitOfTemperature.CELSIUS
133
  _attr_translation_key = DOMAIN
134
- _enable_turn_on_off_backwards_compatibility = False
135
-
136
- _last_active_schedule: str | None = None
137
- _previous_action_mode: str | None = HVACAction.HEATING.value # Upstream
138
- _homekit_mode: HVACMode | None = None # pw-beta homekit emulation + intentional unsort
139
-
140
- async def async_added_to_hass(self) -> None:
141
- """Run when entity about to be added."""
142
- await super().async_added_to_hass()
143
-
144
- if extra_data := await self.async_get_last_extra_data():
145
- plugwise_extra_data = PlugwiseClimateExtraStoredData.from_dict(
146
- extra_data.as_dict()
147
- )
148
- self._last_active_schedule = plugwise_extra_data.last_active_schedule
149
- self._previous_action_mode = plugwise_extra_data.previous_action_mode
150
 
151
  def __init__(
152
  self,
153
  coordinator: PlugwiseDataUpdateCoordinator,
154
  device_id: str,
155
- homekit_enabled: bool, # pw-beta homekit emulation
156
  ) -> None:
157
  """Set up the Plugwise API."""
158
  super().__init__(coordinator, device_id)
 
159
 
160
- gateway_id: str = coordinator.api.gateway_id
 
161
  self._gateway_data = coordinator.data[gateway_id]
162
- self._homekit_enabled = homekit_enabled # pw-beta homekit emulation
163
  self._location = device_id
164
- if (location := self.device.get(LOCATION)) is not None:
165
  self._location = location
166
-
167
- self._attr_max_temp = min(self.device.get(THERMOSTAT, {}).get(UPPER_BOUND, 35.0), 35.0)
168
- self._attr_min_temp = self.device.get(THERMOSTAT, {}).get(LOWER_BOUND, 0.0)
169
- # Ensure we don't drop below 0.1
170
- self._attr_target_temperature_step = max(
171
- self.device.get(THERMOSTAT, {}).get(RESOLUTION, 0.5), 0.1
172
- )
173
- self._attr_unique_id = f"{device_id}-climate"
174
 
175
  # Determine supported features
176
  self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
177
- if (
178
- self.coordinator.api.cooling_present
179
- and coordinator.api.smile.name != "Adam"
180
- ):
181
  self._attr_supported_features = (
182
  ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
183
  )
@@ -185,16 +124,35 @@
185
  self._attr_supported_features |= (
186
  ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
187
  )
188
- if presets := self.device.get("preset_modes", None): # can be NONE
189
  self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
190
- self._attr_preset_modes = presets
191
 
192
- @property
193
- def current_temperature(self) -> float | None:
194
- """Return the current temperature."""
195
- return self.device.get(SENSORS, {}).get(ATTR_TEMPERATURE)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
  @property
 
198
  def extra_restore_state_data(self) -> PlugwiseClimateExtraStoredData:
199
  """Return text specific state data to be restored."""
200
  return PlugwiseClimateExtraStoredData(
@@ -203,68 +161,66 @@
203
  )
204
 
205
  @property
206
- def target_temperature(self) -> float | None:
 
 
 
 
 
 
 
207
  """Return the temperature we try to reach.
208
 
209
  Connected to the HVACMode combination of AUTO-HEAT.
210
  """
211
 
212
- return self.device.get(THERMOSTAT, {}).get(TARGET_TEMP)
213
 
214
  @property
215
- def target_temperature_high(self) -> float | None:
 
216
  """Return the temperature we try to reach in case of cooling.
217
 
218
  Connected to the HVACMode combination of AUTO-HEAT_COOL.
219
  """
220
- return self.device.get(THERMOSTAT, {}).get(TARGET_TEMP_HIGH)
221
 
222
  @property
223
- def target_temperature_low(self) -> float | None:
 
224
  """Return the heating temperature we try to reach in case of heating.
225
 
226
  Connected to the HVACMode combination AUTO-HEAT_COOL.
227
  """
228
- return self.device.get(THERMOSTAT, {}).get(TARGET_TEMP_LOW)
229
 
230
  @property
 
231
  def hvac_mode(self) -> HVACMode:
232
  """Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
233
- mode = self.device.get(CLIMATE_MODE)
234
- if mode is None:
235
- return HVACMode.HEAT # pragma: no cover
236
- try:
237
- hvac = HVACMode(mode)
238
- except ValueError: # pragma: no cover
239
- return HVACMode.HEAT # pragma: no cover
240
- if hvac not in self.hvac_modes:
241
- return HVACMode.HEAT # pragma: no cover
242
- # pw-beta homekit emulation
243
- if self._homekit_enabled and self._homekit_mode == HVACMode.OFF:
244
- return HVACMode.OFF # pragma: no cover
245
-
246
- return hvac
247
 
248
  @property
 
249
  def hvac_modes(self) -> list[HVACMode]:
250
  """Return a list of available HVACModes."""
251
  hvac_modes: list[HVACMode] = []
252
- if (
253
- self._homekit_enabled # pw-beta homekit emulation
254
- or REGULATION_MODES in self._gateway_data
255
- ):
256
  hvac_modes.append(HVACMode.OFF)
257
 
258
- if self.device.get(AVAILABLE_SCHEDULES, []):
259
  hvac_modes.append(HVACMode.AUTO)
260
 
261
- if self.coordinator.api.cooling_present:
262
- if REGULATION_MODES in self._gateway_data:
263
- selected = self._gateway_data.get(SELECT_REGULATION_MODE)
264
- if selected == HVACAction.COOLING.value:
265
- hvac_modes.append(HVACMode.COOL)
266
- if selected == HVACAction.HEATING.value:
267
  hvac_modes.append(HVACMode.HEAT)
 
 
268
  else:
269
  hvac_modes.append(HVACMode.HEAT_COOL)
270
  else:
@@ -273,97 +229,116 @@
273
  return hvac_modes
274
 
275
  @property
276
- def hvac_action(self) -> HVACAction: # pw-beta add to Core
 
277
  """Return the current running hvac operation if supported."""
278
  # Keep track of the previous hvac_action mode.
279
  # When no cooling available, _previous_action_mode is always heating
280
  if (
281
- REGULATION_MODES in self._gateway_data
282
- and HVACAction.COOLING.value in self._gateway_data[REGULATION_MODES]
283
  ):
284
- mode = self._gateway_data[SELECT_REGULATION_MODE]
285
  if mode in (HVACAction.COOLING.value, HVACAction.HEATING.value):
286
  self._previous_action_mode = mode
287
 
288
- if (action := self.device.get(CONTROL_STATE)) is not None:
289
  return HVACAction(action)
290
 
291
  return HVACAction.IDLE
292
 
293
  @property
 
294
  def preset_mode(self) -> str | None:
295
  """Return the current preset mode."""
296
- return self.device.get(ACTIVE_PRESET)
297
 
298
  @plugwise_command
 
299
  async def async_set_temperature(self, **kwargs: Any) -> None:
300
  """Set new target temperature."""
301
  data: dict[str, Any] = {}
302
  if ATTR_TEMPERATURE in kwargs:
303
- data[TARGET_TEMP] = kwargs.get(ATTR_TEMPERATURE)
304
  if ATTR_TARGET_TEMP_HIGH in kwargs:
305
- data[TARGET_TEMP_HIGH] = kwargs.get(ATTR_TARGET_TEMP_HIGH)
306
  if ATTR_TARGET_TEMP_LOW in kwargs:
307
- data[TARGET_TEMP_LOW] = kwargs.get(ATTR_TARGET_TEMP_LOW)
308
-
309
- # Upstream removed input-valid check
310
 
311
  if mode := kwargs.get(ATTR_HVAC_MODE):
312
  await self.async_set_hvac_mode(mode)
313
 
314
- await self.coordinator.api.set_temperature(self._location, data)
 
 
 
 
 
 
 
 
 
 
 
315
 
316
  @plugwise_command
 
317
  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
318
- """Set the hvac mode."""
 
319
  if hvac_mode == self.hvac_mode:
320
  return
321
 
322
- if hvac_mode != HVACMode.OFF:
323
- current = self.device.get("select_schedule")
324
- desired = current
325
-
326
- # Capture the last valid schedule
327
- if desired and desired != "off":
328
- self._last_active_schedule = desired
329
- elif desired == "off":
330
- desired = self._last_active_schedule
331
-
332
- # Enabling HVACMode.AUTO requires a previously set schedule for saving and restoring
333
- if hvac_mode == HVACMode.AUTO and not desired:
334
- raise HomeAssistantError(
335
- translation_domain=DOMAIN,
336
- translation_key=ERROR_NO_SCHEDULE,
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  )
 
 
 
 
338
 
339
- await self.coordinator.api.set_schedule_state(
 
 
340
  self._location,
341
- STATE_ON if hvac_mode == HVACMode.AUTO else STATE_OFF,
342
- desired,
343
  )
 
 
344
 
345
- await self._homekit_translate_or_not(hvac_mode) # pw-beta
346
-
347
- async def _homekit_translate_or_not(self, mode: HVACMode) -> None:
348
- """Mimic HomeKit by setting a suitable preset, when homekit mode is enabled."""
349
- if (
350
- not self._homekit_enabled # pw-beta
351
- ):
352
- if mode == HVACMode.OFF:
353
- await self.coordinator.api.set_regulation_mode(mode.value)
354
- elif self.hvac_mode == HVACMode.OFF and self._previous_action_mode:
355
- await self.coordinator.api.set_regulation_mode(self._previous_action_mode)
356
- else: # pw-beta
357
- self._homekit_mode = mode # pragma: no cover
358
- if self._homekit_mode == HVACMode.OFF: # pragma: no cover
359
- await self.async_set_preset_mode(PRESET_AWAY) # pragma: no cover
360
- if (
361
- self._homekit_mode in [HVACMode.HEAT, HVACMode.HEAT_COOL]
362
- and self.device.get(ACTIVE_PRESET) == PRESET_AWAY
363
- ): # pragma: no cover
364
- await self.async_set_preset_mode(PRESET_HOME) # pragma: no cover
365
 
366
  @plugwise_command
 
367
  async def async_set_preset_mode(self, preset_mode: str) -> None:
368
  """Set the preset mode."""
369
- await self.coordinator.api.set_preset(self._location, preset_mode)
 
1
  """Plugwise Climate component for Home Assistant."""
2
 
3
+ from dataclasses import asdict, dataclass
4
+ from typing import Any, override
 
 
5
 
6
  from homeassistant.components.climate import (
7
  ATTR_HVAC_MODE,
8
  ATTR_TARGET_TEMP_HIGH,
9
  ATTR_TARGET_TEMP_LOW,
 
 
10
  ClimateEntity,
11
  ClimateEntityFeature,
12
  HVACAction,
13
  HVACMode,
14
  )
15
+ from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, STATE_ON, UnitOfTemperature
 
 
 
 
 
 
16
  from homeassistant.core import HomeAssistant, callback
17
  from homeassistant.exceptions import HomeAssistantError
18
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
19
  from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
20
 
21
+ from .const import DOMAIN, MASTER_THERMOSTATS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
23
  from .entity import PlugwiseEntity
24
  from .util import plugwise_command
 
27
  PARALLEL_UPDATES = 0
28
 
29
 
30
+ def _check_for_schedule(active: bool, last_active: str) -> None:
31
+ """Raise a HAError when no thermostat schedule has been set."""
32
+ # last_active can be stored as None from before the plugwise v1.14.3 bump
33
+ if not active and last_active == STATE_OFF:
34
+ raise HomeAssistantError(
35
+ translation_domain=DOMAIN,
36
+ translation_key=ERROR_NO_SCHEDULE,
37
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
  @dataclass
 
44
  last_active_schedule: str | None
45
  previous_action_mode: str | None
46
 
47
+ @override
48
  def as_dict(self) -> dict[str, Any]:
49
  """Return a dict representation of the text data."""
50
+ return asdict(self)
 
 
 
51
 
52
  @classmethod
53
  def from_dict(cls, restored: dict[str, Any]) -> PlugwiseClimateExtraStoredData:
 
58
  )
59
 
60
 
61
+ async def async_setup_entry(
62
+ hass: HomeAssistant,
63
+ entry: PlugwiseConfigEntry,
64
+ async_add_entities: AddConfigEntryEntitiesCallback,
65
+ ) -> None:
66
+ """Set up the Smile Thermostats from a config entry."""
67
+ coordinator = entry.runtime_data
68
+
69
+ @callback
70
+ def _add_entities() -> None:
71
+ """Add Entities."""
72
+ if not coordinator.new_devices:
73
+ return
74
+
75
+ if coordinator.api.smile.name == "Adam":
76
+ async_add_entities(
77
+ PlugwiseClimateEntity(coordinator, device_id)
78
+ for device_id in coordinator.new_devices
79
+ if coordinator.data[device_id]["dev_class"] == "climate"
80
+ )
81
+ else:
82
+ async_add_entities(
83
+ PlugwiseClimateEntity(coordinator, device_id)
84
+ for device_id in coordinator.new_devices
85
+ if coordinator.data[device_id]["dev_class"] in MASTER_THERMOSTATS
86
+ )
87
+
88
+ _add_entities()
89
+ entry.async_on_unload(coordinator.async_add_listener(_add_entities))
90
+
91
+
92
  class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity, RestoreEntity):
93
  """Representation of a Plugwise thermostat."""
94
 
 
95
  _attr_name = None
96
  _attr_temperature_unit = UnitOfTemperature.CELSIUS
97
  _attr_translation_key = DOMAIN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  def __init__(
100
  self,
101
  coordinator: PlugwiseDataUpdateCoordinator,
102
  device_id: str,
 
103
  ) -> None:
104
  """Set up the Plugwise API."""
105
  super().__init__(coordinator, device_id)
106
+ self._attr_unique_id = f"{device_id}-climate" # pylint: disable=home-assistant-entity-unique-id-redundant-platform
107
 
108
+ self._api = coordinator.api
109
+ gateway_id: str = self._api.gateway_id
110
  self._gateway_data = coordinator.data[gateway_id]
111
+ self._last_active_schedule = STATE_OFF
112
  self._location = device_id
113
+ if (location := self.device.get("location")) is not None:
114
  self._location = location
115
+ self._previous_action_mode = HVACAction.HEATING.value
 
 
 
 
 
 
 
116
 
117
  # Determine supported features
118
  self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
119
+ if self._api.cooling_present and self._api.smile.name != "Adam":
 
 
 
120
  self._attr_supported_features = (
121
  ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
122
  )
 
124
  self._attr_supported_features |= (
125
  ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
126
  )
127
+ if presets := self.device.get("preset_modes"):
128
  self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
129
+ self._attr_preset_modes = presets
130
 
131
+ self._attr_min_temp = self.device["thermostat"]["lower_bound"]
132
+ self._attr_max_temp = min(self.device["thermostat"]["upper_bound"], 35.0)
133
+ # Ensure we don't drop below 0.1
134
+ self._attr_target_temperature_step = max(
135
+ self.device["thermostat"]["resolution"], 0.1
136
+ )
137
+
138
+ @override
139
+ async def async_added_to_hass(self) -> None:
140
+ """Run when entity about to be added."""
141
+ await super().async_added_to_hass()
142
+
143
+ if extra_data := await self.async_get_last_extra_data():
144
+ plugwise_extra_data = PlugwiseClimateExtraStoredData.from_dict(
145
+ extra_data.as_dict()
146
+ )
147
+ self._last_active_schedule = (
148
+ plugwise_extra_data.last_active_schedule or STATE_OFF
149
+ )
150
+ self._previous_action_mode = (
151
+ plugwise_extra_data.previous_action_mode or HVACAction.HEATING.value
152
+ )
153
 
154
  @property
155
+ @override
156
  def extra_restore_state_data(self) -> PlugwiseClimateExtraStoredData:
157
  """Return text specific state data to be restored."""
158
  return PlugwiseClimateExtraStoredData(
 
161
  )
162
 
163
  @property
164
+ @override
165
+ def current_temperature(self) -> float | None:
166
+ """Return the current temperature."""
167
+ return self.device["sensors"].get("temperature")
168
+
169
+ @property
170
+ @override
171
+ def target_temperature(self) -> float:
172
  """Return the temperature we try to reach.
173
 
174
  Connected to the HVACMode combination of AUTO-HEAT.
175
  """
176
 
177
+ return self.device["thermostat"]["setpoint"]
178
 
179
  @property
180
+ @override
181
+ def target_temperature_high(self) -> float:
182
  """Return the temperature we try to reach in case of cooling.
183
 
184
  Connected to the HVACMode combination of AUTO-HEAT_COOL.
185
  """
186
+ return self.device["thermostat"]["setpoint_high"]
187
 
188
  @property
189
+ @override
190
+ def target_temperature_low(self) -> float:
191
  """Return the heating temperature we try to reach in case of heating.
192
 
193
  Connected to the HVACMode combination AUTO-HEAT_COOL.
194
  """
195
+ return self.device["thermostat"]["setpoint_low"]
196
 
197
  @property
198
+ @override
199
  def hvac_mode(self) -> HVACMode:
200
  """Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
201
+ if (
202
+ mode := self.device.get("climate_mode")
203
+ ) is None or mode not in self.hvac_modes:
204
+ return HVACMode.HEAT
205
+ return HVACMode(mode)
 
 
 
 
 
 
 
 
 
206
 
207
  @property
208
+ @override
209
  def hvac_modes(self) -> list[HVACMode]:
210
  """Return a list of available HVACModes."""
211
  hvac_modes: list[HVACMode] = []
212
+ if "regulation_modes" in self._gateway_data:
 
 
 
213
  hvac_modes.append(HVACMode.OFF)
214
 
215
+ if self.device["available_schedules"] != [STATE_OFF]:
216
  hvac_modes.append(HVACMode.AUTO)
217
 
218
+ if self._api.cooling_present:
219
+ if "regulation_modes" in self._gateway_data:
220
+ if "heating" in self._gateway_data["regulation_modes"]:
 
 
 
221
  hvac_modes.append(HVACMode.HEAT)
222
+ if "cooling" in self._gateway_data["regulation_modes"]:
223
+ hvac_modes.append(HVACMode.COOL)
224
  else:
225
  hvac_modes.append(HVACMode.HEAT_COOL)
226
  else:
 
229
  return hvac_modes
230
 
231
  @property
232
+ @override
233
+ def hvac_action(self) -> HVACAction:
234
  """Return the current running hvac operation if supported."""
235
  # Keep track of the previous hvac_action mode.
236
  # When no cooling available, _previous_action_mode is always heating
237
  if (
238
+ "regulation_modes" in self._gateway_data
239
+ and HVACAction.COOLING.value in self._gateway_data["regulation_modes"]
240
  ):
241
+ mode = self._gateway_data["select_regulation_mode"]
242
  if mode in (HVACAction.COOLING.value, HVACAction.HEATING.value):
243
  self._previous_action_mode = mode
244
 
245
+ if (action := self.device.get("control_state")) is not None:
246
  return HVACAction(action)
247
 
248
  return HVACAction.IDLE
249
 
250
  @property
251
+ @override
252
  def preset_mode(self) -> str | None:
253
  """Return the current preset mode."""
254
+ return self.device.get("active_preset")
255
 
256
  @plugwise_command
257
+ @override
258
  async def async_set_temperature(self, **kwargs: Any) -> None:
259
  """Set new target temperature."""
260
  data: dict[str, Any] = {}
261
  if ATTR_TEMPERATURE in kwargs:
262
+ data["setpoint"] = kwargs.get(ATTR_TEMPERATURE)
263
  if ATTR_TARGET_TEMP_HIGH in kwargs:
264
+ data["setpoint_high"] = kwargs.get(ATTR_TARGET_TEMP_HIGH)
265
  if ATTR_TARGET_TEMP_LOW in kwargs:
266
+ data["setpoint_low"] = kwargs.get(ATTR_TARGET_TEMP_LOW)
 
 
267
 
268
  if mode := kwargs.get(ATTR_HVAC_MODE):
269
  await self.async_set_hvac_mode(mode)
270
 
271
+ await self._api.set_temperature(self._location, data)
272
+
273
+ def _regulation_mode_for_hvac(self, hvac_mode: HVACMode) -> str:
274
+ """Return the API regulation value for a manual HVAC mode, or None.
275
+
276
+ The function inputs are limited to the HVACModes HEAT and COOL.
277
+ """
278
+ if hvac_mode == HVACMode.HEAT:
279
+ mode = HVACAction.HEATING.value
280
+ if hvac_mode == HVACMode.COOL:
281
+ mode = HVACAction.COOLING.value
282
+ return mode
283
 
284
  @plugwise_command
285
+ @override
286
  async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
287
+ """Set the HVAC mode (off, heat, cool, heat_cool, or auto/schedule)."""
288
+ # Early exit if no mode change
289
  if hvac_mode == self.hvac_mode:
290
  return
291
 
292
+ # Adam only: set to HVACMode.OFF
293
+ if hvac_mode == HVACMode.OFF:
294
+ await self._api.set_regulation_mode(hvac_mode.value)
295
+ return
296
+
297
+ current_schedule = self.device["select_schedule"]
298
+ schedule_is_active = current_schedule != STATE_OFF
299
+ desired_schedule = (
300
+ current_schedule if schedule_is_active else self._last_active_schedule
301
+ )
302
+ # Adam only: transition from HVACMode.OFF
303
+ if self.hvac_mode == HVACMode.OFF:
304
+ if hvac_mode == HVACMode.AUTO:
305
+ _check_for_schedule(schedule_is_active, self._last_active_schedule)
306
+ await self._api.set_schedule_state(
307
+ self._location,
308
+ desired_schedule,
309
+ STATE_ON,
310
+ )
311
+ await self._api.set_regulation_mode(self._previous_action_mode)
312
+ return
313
+
314
+ # Transition to manual mode
315
+ if schedule_is_active:
316
+ await self._api.set_schedule_state(
317
+ self._location,
318
+ current_schedule,
319
+ STATE_OFF,
320
  )
321
+ self._last_active_schedule = current_schedule
322
+ regulation = self._regulation_mode_for_hvac(hvac_mode)
323
+ await self._api.set_regulation_mode(regulation)
324
+ return
325
 
326
+ # Common - transition from auto = schedule off
327
+ if self.hvac_mode == HVACMode.AUTO:
328
+ await self._api.set_schedule_state(
329
  self._location,
330
+ current_schedule,
331
+ STATE_OFF,
332
  )
333
+ self._last_active_schedule = current_schedule
334
+ return
335
 
336
+ # Common - transition to auto = schedule on
337
+ _check_for_schedule(schedule_is_active, self._last_active_schedule)
338
+ await self._api.set_schedule_state(self._location, desired_schedule, STATE_ON)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  @plugwise_command
341
+ @override
342
  async def async_set_preset_mode(self, preset_mode: str) -> None:
343
  """Set the preset mode."""
344
+ await self._api.set_preset(self._location, preset_mode)
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/config_flow.py RENAMED
@@ -1,10 +1,7 @@
1
  """Config flow for Plugwise integration."""
2
 
3
- from __future__ import annotations
4
-
5
- from copy import deepcopy
6
  import logging
7
- from typing import Any, Self
8
 
9
  from plugwise import Smile
10
  from plugwise.exceptions import (
@@ -15,17 +12,9 @@
15
  ResponseError,
16
  UnsupportedDeviceError,
17
  )
18
- import voluptuous as vol
19
-
20
- from homeassistant.config_entries import (
21
- SOURCE_USER,
22
- ConfigEntry,
23
- ConfigFlow,
24
- ConfigFlowResult,
25
- OptionsFlow,
26
- )
27
 
28
- # Upstream
29
  from homeassistant.const import (
30
  ATTR_CONFIGURATION_URL,
31
  CONF_BASE,
@@ -33,80 +22,52 @@
33
  CONF_NAME,
34
  CONF_PASSWORD,
35
  CONF_PORT,
36
- CONF_SCAN_INTERVAL,
37
  CONF_USERNAME,
38
  )
39
-
40
- # Upstream
41
- from homeassistant.core import HomeAssistant, callback
42
- from homeassistant.helpers import config_validation as cv
43
  from homeassistant.helpers.aiohttp_client import async_get_clientsession
44
  from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
45
 
46
  from .const import (
47
  ANNA_WITH_ADAM,
48
- CONF_HOMEKIT_EMULATION, # pw-beta option
49
- CONF_REFRESH_INTERVAL, # pw-beta option
50
  DEFAULT_PORT,
51
- DEFAULT_UPDATE_INTERVAL,
52
  DEFAULT_USERNAME,
53
  DOMAIN,
54
  FLOW_SMILE,
55
  FLOW_STRETCH,
56
- INIT,
57
- P1_UPDATE_INTERVAL,
58
  SMILE,
59
  SMILE_OPEN_THERM,
60
  SMILE_THERMO,
61
  STRETCH,
62
  STRETCH_USERNAME,
63
- THERMOSTAT,
64
- TITLE_PLACEHOLDERS,
65
- VERSION,
66
  ZEROCONF_MAP,
67
  )
68
 
69
- # Upstream
70
- from .coordinator import PlugwiseDataUpdateCoordinator
71
-
72
- type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator]
73
-
74
  _LOGGER = logging.getLogger(__name__)
75
 
76
- # Upstream basically the whole file (excluding the pw-beta options)
77
-
78
- SMILE_RECONF_SCHEMA = vol.Schema(
79
  {
80
- vol.Required(CONF_HOST): str,
81
  }
82
  )
83
 
84
 
85
- def smile_user_schema(cf_input: ZeroconfServiceInfo | dict[str, Any] | None) -> vol.Schema:
86
  """Generate base schema for gateways."""
87
- if not cf_input: # no discovery- or user-input available
88
- return vol.Schema(
 
 
89
  {
90
- vol.Required(CONF_HOST): str,
91
- vol.Required(CONF_PASSWORD): str,
92
- vol.Required(CONF_USERNAME, default=SMILE): vol.In(
93
  {SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
94
  ),
95
  }
96
  )
97
 
98
- if isinstance(cf_input, ZeroconfServiceInfo):
99
- return vol.Schema({vol.Required(CONF_PASSWORD): str})
100
-
101
- return vol.Schema(
102
- {
103
- vol.Required(CONF_HOST, default=cf_input[CONF_HOST]): str,
104
- vol.Required(CONF_PASSWORD, default=cf_input[CONF_PASSWORD]): str,
105
- vol.Required(CONF_USERNAME, default=cf_input[CONF_USERNAME]): vol.In(
106
- {SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
107
- ),
108
- }
109
- )
110
 
111
 
112
  async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> Smile:
@@ -140,7 +101,7 @@
140
  errors[CONF_BASE] = "invalid_auth"
141
  except InvalidSetupError:
142
  errors[CONF_BASE] = "invalid_setup"
143
- except (InvalidXMLError, ResponseError):
144
  errors[CONF_BASE] = "response_error"
145
  except UnsupportedDeviceError:
146
  errors[CONF_BASE] = "unsupported"
@@ -156,33 +117,29 @@
156
  """Handle a config flow for Plugwise Smile."""
157
 
158
  VERSION = 1
159
- MINOR_VERSION = 1
160
 
161
  discovery_info: ZeroconfServiceInfo | None = None
162
- product: str = "Unknown Smile"
163
  _username: str = DEFAULT_USERNAME
164
 
 
165
  async def async_step_zeroconf(
166
  self, discovery_info: ZeroconfServiceInfo
167
  ) -> ConfigFlowResult:
168
  """Prepare configuration for a discovered Plugwise Smile."""
169
  self.discovery_info = discovery_info
170
  _properties = discovery_info.properties
171
- _version = _properties.get(VERSION, "n/a")
172
- self.product = _product = _properties.get("product", "Unknown Smile")
173
- unique_id = discovery_info.hostname.split(".")[0].split("-")[0]
174
- if DEFAULT_USERNAME not in unique_id:
175
- self._username = STRETCH_USERNAME
176
 
 
177
  if config_entry := await self.async_set_unique_id(unique_id):
178
  try:
179
  await validate_input(
180
  self.hass,
181
  {
182
  CONF_HOST: discovery_info.host,
183
- CONF_PASSWORD: config_entry.data[CONF_PASSWORD],
184
  CONF_PORT: discovery_info.port,
185
  CONF_USERNAME: config_entry.data[CONF_USERNAME],
 
186
  },
187
  )
188
  except Exception: # noqa: BLE001
@@ -195,6 +152,12 @@
195
  }
196
  )
197
 
 
 
 
 
 
 
198
  # This is an Anna, but we already have config entries.
199
  # Assuming that the user has already configured Adam, aborting discovery.
200
  if self._async_current_entries() and _product == SMILE_THERMO:
@@ -204,19 +167,19 @@
204
  # In that case, we need to cancel the Anna flow, as the Adam should
205
  # be added.
206
  if self.hass.config_entries.flow.async_has_matching_flow(self):
207
- return self.async_abort(reason="anna_with_adam")
208
 
209
- _name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
210
  self.context.update(
211
  {
212
- TITLE_PLACEHOLDERS: {CONF_NAME: _name},
213
  ATTR_CONFIGURATION_URL: (
214
  f"http://{discovery_info.host}:{discovery_info.port}"
215
- )
216
  }
217
  )
218
  return await self.async_step_user()
219
 
 
220
  def is_matching(self, other_flow: Self) -> bool:
221
  """Return True if other_flow is matching this flow."""
222
  # This is an Anna, and there is already an Adam flow in progress
@@ -229,7 +192,7 @@
229
 
230
  return False
231
 
232
-
233
  async def async_step_user(
234
  self, user_input: dict[str, Any] | None = None
235
  ) -> ConfigFlowResult:
@@ -246,19 +209,18 @@
246
  api, errors = await verify_connection(self.hass, user_input)
247
  if api:
248
  await self.async_set_unique_id(
249
- api.smile.hostname or api.gateway_id, raise_on_progress=False
 
250
  )
251
  self._abort_if_unique_id_configured()
252
  return self.async_create_entry(title=api.smile.name, data=user_input)
253
 
254
- configure_input = self.discovery_info or user_input
255
  return self.async_show_form(
256
  step_id=SOURCE_USER,
257
- data_schema=smile_user_schema(configure_input),
258
  errors=errors,
259
  )
260
 
261
-
262
  async def async_step_reconfigure(
263
  self, user_input: dict[str, Any] | None = None
264
  ) -> ConfigFlowResult:
@@ -268,7 +230,7 @@
268
  reconfigure_entry = self._get_reconfigure_entry()
269
 
270
  if user_input:
271
- # Redefine ingest existing username and password
272
  full_input = {
273
  CONF_HOST: user_input.get(CONF_HOST),
274
  CONF_PORT: reconfigure_entry.data.get(CONF_PORT),
@@ -279,7 +241,8 @@
279
  api, errors = await verify_connection(self.hass, full_input)
280
  if api:
281
  await self.async_set_unique_id(
282
- api.smile.hostname or api.gateway_id, raise_on_progress=False
 
283
  )
284
  self._abort_if_unique_id_mismatch(reason="not_the_same_smile")
285
  return self.async_update_reload_and_abort(
@@ -296,71 +259,3 @@
296
  description_placeholders={"title": reconfigure_entry.title},
297
  errors=errors,
298
  )
299
-
300
-
301
- @staticmethod
302
- @callback
303
- def async_get_options_flow(
304
- config_entry: PlugwiseConfigEntry,
305
- ) -> PlugwiseOptionsFlowHandler: # pw-beta options
306
- """Get the options flow for this handler."""
307
- return PlugwiseOptionsFlowHandler(config_entry)
308
-
309
-
310
- # pw-beta - change the scan-interval via CONFIGURE
311
- # pw-beta - add homekit emulation via CONFIGURE
312
- # pw-beta - change the frontend refresh interval via CONFIGURE
313
- class PlugwiseOptionsFlowHandler(OptionsFlow): # pw-beta options
314
- """Plugwise option flow."""
315
-
316
- def __init__(self, config_entry: ConfigEntry) -> None:
317
- """Initialize options flow."""
318
- self.options = deepcopy(dict(config_entry.options))
319
-
320
- def _create_options_schema(self, coordinator: PlugwiseDataUpdateCoordinator) -> vol.Schema:
321
- interval = DEFAULT_UPDATE_INTERVAL
322
- if coordinator.api.smile.type == "power":
323
- interval = P1_UPDATE_INTERVAL
324
- schema = {
325
- vol.Optional(
326
- CONF_SCAN_INTERVAL,
327
- default=self.options.get(CONF_SCAN_INTERVAL, interval.seconds),
328
- ): vol.All(cv.positive_int, vol.Clamp(min=10)),
329
- } # pw-beta
330
-
331
- if coordinator.api.smile.type == THERMOSTAT:
332
- schema.update({
333
- vol.Optional(
334
- CONF_HOMEKIT_EMULATION,
335
- default=self.options.get(CONF_HOMEKIT_EMULATION, False),
336
- ): vol.All(cv.boolean),
337
- vol.Optional(
338
- CONF_REFRESH_INTERVAL,
339
- default=self.options.get(CONF_REFRESH_INTERVAL, 1.5),
340
- ): vol.All(vol.Coerce(float), vol.Range(min=1.5, max=10.0)),
341
- }) # pw-beta
342
-
343
- return vol.Schema(schema)
344
-
345
- async def async_step_none(
346
- self, user_input: dict[str, Any] | None = None
347
- ) -> ConfigFlowResult: # pragma: no cover
348
- """No options available."""
349
- if user_input is not None:
350
- # Apparently not possible to abort an options flow at the moment
351
- return self.async_create_entry(title="", data=self.options)
352
- return self.async_show_form(step_id="none")
353
-
354
- async def async_step_init(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
355
- """Manage the Plugwise options."""
356
- if not self.config_entry.data.get(CONF_HOST):
357
- return await self.async_step_none(user_input) # pragma: no cover
358
-
359
- if user_input is not None:
360
- return self.async_create_entry(title="", data=user_input)
361
-
362
- coordinator = self.config_entry.runtime_data
363
- return self.async_show_form(
364
- step_id=INIT,
365
- data_schema=self._create_options_schema(coordinator)
366
- )
 
1
  """Config flow for Plugwise integration."""
2
 
 
 
 
3
  import logging
4
+ from typing import Any, Self, override
5
 
6
  from plugwise import Smile
7
  from plugwise.exceptions import (
 
12
  ResponseError,
13
  UnsupportedDeviceError,
14
  )
15
+ import probatio
 
 
 
 
 
 
 
 
16
 
17
+ from homeassistant.config_entries import SOURCE_USER, ConfigFlow, ConfigFlowResult
18
  from homeassistant.const import (
19
  ATTR_CONFIGURATION_URL,
20
  CONF_BASE,
 
22
  CONF_NAME,
23
  CONF_PASSWORD,
24
  CONF_PORT,
 
25
  CONF_USERNAME,
26
  )
27
+ from homeassistant.core import HomeAssistant
 
 
 
28
  from homeassistant.helpers.aiohttp_client import async_get_clientsession
29
  from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
30
 
31
  from .const import (
32
  ANNA_WITH_ADAM,
 
 
33
  DEFAULT_PORT,
 
34
  DEFAULT_USERNAME,
35
  DOMAIN,
36
  FLOW_SMILE,
37
  FLOW_STRETCH,
 
 
38
  SMILE,
39
  SMILE_OPEN_THERM,
40
  SMILE_THERMO,
41
  STRETCH,
42
  STRETCH_USERNAME,
43
+ UNKNOWN_SMILE,
 
 
44
  ZEROCONF_MAP,
45
  )
46
 
 
 
 
 
 
47
  _LOGGER = logging.getLogger(__name__)
48
 
49
+ SMILE_RECONF_SCHEMA = probatio.Schema(
 
 
50
  {
51
+ probatio.Required(CONF_HOST): str,
52
  }
53
  )
54
 
55
 
56
+ def smile_user_schema(discovery_info: ZeroconfServiceInfo | None) -> probatio.Schema:
57
  """Generate base schema for gateways."""
58
+ schema = probatio.Schema({probatio.Required(CONF_PASSWORD): str})
59
+
60
+ if not discovery_info:
61
+ schema = schema.extend(
62
  {
63
+ probatio.Required(CONF_HOST): str,
64
+ probatio.Required(CONF_USERNAME, default=SMILE): probatio.In(
 
65
  {SMILE: FLOW_SMILE, STRETCH: FLOW_STRETCH}
66
  ),
67
  }
68
  )
69
 
70
+ return schema
 
 
 
 
 
 
 
 
 
 
 
71
 
72
 
73
  async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> Smile:
 
101
  errors[CONF_BASE] = "invalid_auth"
102
  except InvalidSetupError:
103
  errors[CONF_BASE] = "invalid_setup"
104
+ except InvalidXMLError, ResponseError:
105
  errors[CONF_BASE] = "response_error"
106
  except UnsupportedDeviceError:
107
  errors[CONF_BASE] = "unsupported"
 
117
  """Handle a config flow for Plugwise Smile."""
118
 
119
  VERSION = 1
 
120
 
121
  discovery_info: ZeroconfServiceInfo | None = None
122
+ product: str = UNKNOWN_SMILE
123
  _username: str = DEFAULT_USERNAME
124
 
125
+ @override
126
  async def async_step_zeroconf(
127
  self, discovery_info: ZeroconfServiceInfo
128
  ) -> ConfigFlowResult:
129
  """Prepare configuration for a discovered Plugwise Smile."""
130
  self.discovery_info = discovery_info
131
  _properties = discovery_info.properties
 
 
 
 
 
132
 
133
+ unique_id = discovery_info.hostname.split(".")[0].split("-")[0]
134
  if config_entry := await self.async_set_unique_id(unique_id):
135
  try:
136
  await validate_input(
137
  self.hass,
138
  {
139
  CONF_HOST: discovery_info.host,
 
140
  CONF_PORT: discovery_info.port,
141
  CONF_USERNAME: config_entry.data[CONF_USERNAME],
142
+ CONF_PASSWORD: config_entry.data[CONF_PASSWORD],
143
  },
144
  )
145
  except Exception: # noqa: BLE001
 
152
  }
153
  )
154
 
155
+ if DEFAULT_USERNAME not in unique_id:
156
+ self._username = STRETCH_USERNAME
157
+ self.product = _product = _properties.get("product", UNKNOWN_SMILE)
158
+ _version = _properties.get("version", "n/a")
159
+ _name = f"{ZEROCONF_MAP.get(_product, _product)} v{_version}"
160
+
161
  # This is an Anna, but we already have config entries.
162
  # Assuming that the user has already configured Adam, aborting discovery.
163
  if self._async_current_entries() and _product == SMILE_THERMO:
 
167
  # In that case, we need to cancel the Anna flow, as the Adam should
168
  # be added.
169
  if self.hass.config_entries.flow.async_has_matching_flow(self):
170
+ return self.async_abort(reason=ANNA_WITH_ADAM)
171
 
 
172
  self.context.update(
173
  {
174
+ "title_placeholders": {CONF_NAME: _name},
175
  ATTR_CONFIGURATION_URL: (
176
  f"http://{discovery_info.host}:{discovery_info.port}"
177
+ ),
178
  }
179
  )
180
  return await self.async_step_user()
181
 
182
+ @override
183
  def is_matching(self, other_flow: Self) -> bool:
184
  """Return True if other_flow is matching this flow."""
185
  # This is an Anna, and there is already an Adam flow in progress
 
192
 
193
  return False
194
 
195
+ @override
196
  async def async_step_user(
197
  self, user_input: dict[str, Any] | None = None
198
  ) -> ConfigFlowResult:
 
209
  api, errors = await verify_connection(self.hass, user_input)
210
  if api:
211
  await self.async_set_unique_id(
212
+ api.smile.hostname or api.gateway_id,
213
+ raise_on_progress=False,
214
  )
215
  self._abort_if_unique_id_configured()
216
  return self.async_create_entry(title=api.smile.name, data=user_input)
217
 
 
218
  return self.async_show_form(
219
  step_id=SOURCE_USER,
220
+ data_schema=smile_user_schema(self.discovery_info),
221
  errors=errors,
222
  )
223
 
 
224
  async def async_step_reconfigure(
225
  self, user_input: dict[str, Any] | None = None
226
  ) -> ConfigFlowResult:
 
230
  reconfigure_entry = self._get_reconfigure_entry()
231
 
232
  if user_input:
233
+ # Keep current username and password
234
  full_input = {
235
  CONF_HOST: user_input.get(CONF_HOST),
236
  CONF_PORT: reconfigure_entry.data.get(CONF_PORT),
 
241
  api, errors = await verify_connection(self.hass, full_input)
242
  if api:
243
  await self.async_set_unique_id(
244
+ api.smile.hostname or api.gateway_id,
245
+ raise_on_progress=False,
246
  )
247
  self._abort_if_unique_id_mismatch(reason="not_the_same_smile")
248
  return self.async_update_reload_and_abort(
 
259
  description_placeholders={"title": reconfigure_entry.title},
260
  errors=errors,
261
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/const.py RENAMED
@@ -6,156 +6,30 @@
6
 
7
  from homeassistant.const import Platform
8
 
9
- # Upstream basically the whole file excluding pw-beta options
10
-
11
  DOMAIN: Final = "plugwise"
12
 
13
  LOGGER = logging.getLogger(__package__)
14
 
 
15
  API: Final = "api"
16
- COORDINATOR: Final = "coordinator"
17
- CONF_HOMEKIT_EMULATION: Final = "homekit_emulation" # pw-beta options
18
- CONF_REFRESH_INTERVAL: Final = "refresh_interval" # pw-beta options
19
- CONF_MANUAL_PATH: Final = "Enter Manually"
 
20
  GATEWAY: Final = "gateway"
21
  LOCATION: Final = "location"
22
- MAC_ADDRESS: Final = "mac_address"
 
23
  REBOOT: Final = "reboot"
24
  SMILE: Final = "smile"
25
- STRETCH: Final = "stretch"
26
- STRETCH_USERNAME: Final = "stretch"
27
- SWITCH_GROUPS: Final[tuple[str, str]] = ("report", "switching")
28
- UNIQUE_IDS: Final = "unique_ids"
29
- ZIGBEE_MAC_ADDRESS: Final = "zigbee_mac_address"
30
-
31
- # Binary Sensor constants
32
- BINARY_SENSORS: Final = "binary_sensors"
33
- BATTERY_STATE: Final = "low_battery"
34
- COMPRESSOR_STATE: Final = "compressor_state"
35
- COOLING_ENABLED: Final = "cooling_enabled"
36
- COOLING_STATE: Final = "cooling_state"
37
- DHW_STATE: Final = "dhw_state"
38
- FLAME_STATE: Final = "flame_state"
39
- HEATING_STATE: Final = "heating_state"
40
- PLUGWISE_NOTIFICATION: Final = "plugwise_notification"
41
- SECONDARY_BOILER_STATE: Final = "secondary_boiler_state"
42
-
43
- # Climate constants
44
- ACTIVE_PRESET: Final = "active_preset"
45
- CLIMATE_MODE: Final = "climate_mode"
46
- CONTROL_STATE: Final = "control_state"
47
- COOLING_PRESENT: Final ="cooling_present"
48
- DEV_CLASS: Final = "dev_class"
49
- NONE : Final = "None"
50
- TARGET_TEMP: Final = "setpoint"
51
- TARGET_TEMP_HIGH: Final = "setpoint_high"
52
- TARGET_TEMP_LOW: Final = "setpoint_low"
53
- THERMOSTAT: Final = "thermostat"
54
-
55
- # Config_flow constants
56
- ANNA_WITH_ADAM: Final = "anna_with_adam"
57
- CONTEXT: Final = "context"
58
- FLOW_ID: Final = "flow_id"
59
- FLOW_NET: Final = "Network: Smile/Stretch"
60
- FLOW_SMILE: Final = "Smile (Adam/Anna/P1)"
61
- FLOW_STRETCH: Final = "Stretch (Stretch)"
62
- FLOW_TYPE: Final = "flow_type"
63
- INIT: Final = "init"
64
- PRODUCT: Final = "product"
65
  SMILE_OPEN_THERM: Final = "smile_open_therm"
66
  SMILE_THERMO: Final = "smile_thermo"
67
- TITLE_PLACEHOLDERS: Final = "title_placeholders"
68
- VERSION: Final = "version"
69
-
70
- # Entity constants
71
- AVAILABLE: Final = "available"
72
- FIRMWARE: Final = "firmware"
73
- HARDWARE: Final = "hardware"
74
- MODEL: Final = "model"
75
- MODEL_ID: Final = "model_id"
76
- VENDOR: Final = "vendor"
77
-
78
- # Number constants
79
- MAX_BOILER_TEMP: Final = "maximum_boiler_temperature"
80
- MAX_DHW_TEMP: Final = "max_dhw_temperature"
81
- LOWER_BOUND: Final = "lower_bound"
82
- RESOLUTION: Final = "resolution"
83
- TEMPERATURE_OFFSET: Final = "temperature_offset"
84
  UPPER_BOUND: Final = "upper_bound"
85
 
86
- # Sensor constants
87
- DHW_TEMP: Final = "dhw_temperature"
88
- DHW_SETPOINT: Final = "domestic_hot_water_setpoint"
89
- EL_CONSUMED: Final = "electricity_consumed"
90
- EL_CONS_INTERVAL: Final = "electricity_consumed_interval"
91
- EL_CONS_OP_CUMULATIVE: Final = "electricity_consumed_off_peak_cumulative"
92
- EL_CONS_OP_INTERVAL: Final = "electricity_consumed_off_peak_interval"
93
- EL_CONS_OP_POINT: Final = "electricity_consumed_off_peak_point"
94
- EL_CONS_P_CUMULATIVE: Final = "electricity_consumed_peak_cumulative"
95
- EL_CONS_P_INTERVAL: Final = "electricity_consumed_peak_interval"
96
- EL_CONS_P_POINT: Final = "electricity_consumed_peak_point"
97
- EL_CONS_POINT: Final = "electricity_consumed_point"
98
- EL_PH1_CONSUMED: Final = "electricity_phase_one_consumed"
99
- EL_PH2_CONSUMED: Final = "electricity_phase_two_consumed"
100
- EL_PH3_CONSUMED: Final = "electricity_phase_three_consumed"
101
- EL_PH1_PRODUCED: Final = "electricity_phase_one_produced"
102
- EL_PH2_PRODUCED: Final = "electricity_phase_two_produced"
103
- EL_PH3_PRODUCED: Final = "electricity_phase_three_produced"
104
- EL_PRODUCED: Final = "electricity_produced"
105
- EL_PROD_INTERVAL: Final = "electricity_produced_interval"
106
- EL_PROD_OP_CUMULATIVE: Final = "electricity_produced_off_peak_cumulative"
107
- EL_PROD_OP_INTERVAL: Final = "electricity_produced_off_peak_interval"
108
- EL_PROD_OP_POINT: Final = "electricity_produced_off_peak_point"
109
- EL_PROD_P_CUMULATIVE: Final = "electricity_produced_peak_cumulative"
110
- EL_PROD_P_INTERVAL: Final = "electricity_produced_peak_interval"
111
- EL_PROD_P_POINT: Final = "electricity_produced_peak_point"
112
- EL_PROD_POINT: Final = "electricity_produced_point"
113
- GAS_CONS_CUMULATIVE: Final = "gas_consumed_cumulative"
114
- GAS_CONS_INTERVAL: Final = "gas_consumed_interval"
115
- INTENDED_BOILER_TEMP: Final = "intended_boiler_temperature"
116
- MOD_LEVEL: Final = "modulation_level"
117
- NET_EL_POINT: Final = "net_electricity_point"
118
- NET_EL_CUMULATIVE: Final = "net_electricity_cumulative"
119
- OUTDOOR_AIR_TEMP: Final = "outdoor_air_temperature"
120
- OUTDOOR_TEMP: Final = "outdoor_temperature"
121
- RETURN_TEMP: Final = "return_temperature"
122
- SENSORS: Final = "sensors"
123
- TEMP_DIFF: Final = "temperature_difference"
124
- VALVE_POS: Final = "valve_position"
125
- VOLTAGE_PH1: Final = "voltage_phase_one"
126
- VOLTAGE_PH2: Final = "voltage_phase_two"
127
- VOLTAGE_PH3: Final = "voltage_phase_three"
128
- WATER_TEMP: Final = "water_temperature"
129
- WATER_PRESSURE: Final = "water_pressure"
130
-
131
- # Select constants
132
- AVAILABLE_SCHEDULES: Final = "available_schedules"
133
- DHW_MODES: Final = "dhw_modes"
134
- GATEWAY_MODES: Final = "gateway_modes"
135
- REGULATION_MODES: Final = "regulation_modes"
136
- ZONE_PROFILES: Final = "zone_profiles"
137
- SELECT_DHW_MODE: Final = "select_dhw_mode"
138
- SELECT_GATEWAY_MODE: Final = "select_gateway_mode"
139
- SELECT_REGULATION_MODE: Final = "select_regulation_mode"
140
- SELECT_SCHEDULE: Final = "select_schedule"
141
- SELECT_ZONE_PROFILE: Final = "select_zone_profile"
142
-
143
- # Switch constants
144
- DHW_CM_SWITCH: Final = "dhw_cm_switch"
145
- LOCK: Final = "lock"
146
- MEMBERS: Final ="members"
147
- RELAY: Final = "relay"
148
- COOLING_ENA_SWITCH: Final ="cooling_ena_switch"
149
- SWITCHES: Final = "switches"
150
-
151
- # Default directives
152
- DEFAULT_PORT: Final[int] = 80
153
- DEFAULT_TIMEOUT: Final[int] = 30
154
- DEFAULT_UPDATE_INTERVAL: Final = timedelta(seconds=60)
155
- DEFAULT_USERNAME: Final = "smile"
156
- P1_UPDATE_INTERVAL: Final = timedelta(seconds=10)
157
-
158
- # --- Const for Plugwise Smile and Stretch
159
  PLATFORMS: Final[list[str]] = [
160
  Platform.BINARY_SENSOR,
161
  Platform.BUTTON,
@@ -164,19 +38,8 @@
164
  Platform.SELECT,
165
  Platform.SENSOR,
166
  Platform.SWITCH,
 
167
  ]
168
- SERVICE_DELETE: Final = "delete_notification"
169
- SEVERITIES: Final[list[str]] = ["other", "info", "message", "warning", "error"]
170
-
171
- # Climate const:
172
- MASTER_THERMOSTATS: Final[list[str]] = [
173
- "thermostat",
174
- "zone_thermometer",
175
- "zone_thermostat",
176
- "thermostatic_radiator_valve",
177
- ]
178
-
179
- # Config_flow const:
180
  ZEROCONF_MAP: Final[dict[str, str]] = {
181
  "smile": "Smile P1",
182
  "smile_thermo": "Smile Anna",
@@ -184,18 +47,21 @@
184
  "stretch": "Stretch",
185
  }
186
 
 
 
187
  type NumberType = Literal[
188
- "maximum_boiler_temperature",
189
- "max_dhw_temperature",
190
  "temperature_offset",
191
  ]
192
 
193
  type SelectType = Literal[
 
194
  "select_dhw_mode",
195
  "select_gateway_mode",
196
  "select_regulation_mode",
197
  "select_schedule",
198
- "select_zone_profile"
199
  ]
200
  type SelectOptionsType = Literal[
201
  "available_schedules",
@@ -204,3 +70,30 @@
204
  "regulation_modes",
205
  "zone_profiles",
206
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  from homeassistant.const import Platform
8
 
 
 
9
  DOMAIN: Final = "plugwise"
10
 
11
  LOGGER = logging.getLogger(__package__)
12
 
13
+ ANNA_WITH_ADAM: Final = "anna_with_adam"
14
  API: Final = "api"
15
+ AVAILABLE: Final = "available"
16
+ DEV_CLASS: Final = "dev_class"
17
+ FLOW_SMILE: Final = "smile (Adam/Anna/P1)"
18
+ FLOW_STRETCH: Final = "stretch (Stretch)"
19
+ FLOW_TYPE: Final = "flow_type"
20
  GATEWAY: Final = "gateway"
21
  LOCATION: Final = "location"
22
+ LOWER_BOUND: Final = "lower_bound"
23
+ PW_TYPE: Final = "plugwise_type"
24
  REBOOT: Final = "reboot"
25
  SMILE: Final = "smile"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  SMILE_OPEN_THERM: Final = "smile_open_therm"
27
  SMILE_THERMO: Final = "smile_thermo"
28
+ STRETCH: Final = "stretch"
29
+ STRETCH_USERNAME: Final = "stretch"
30
+ UNKNOWN_SMILE: Final = "Unknown Smile"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  UPPER_BOUND: Final = "upper_bound"
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  PLATFORMS: Final[list[str]] = [
34
  Platform.BINARY_SENSOR,
35
  Platform.BUTTON,
 
38
  Platform.SELECT,
39
  Platform.SENSOR,
40
  Platform.SWITCH,
41
+ Platform.WATER_HEATER,
42
  ]
 
 
 
 
 
 
 
 
 
 
 
 
43
  ZEROCONF_MAP: Final[dict[str, str]] = {
44
  "smile": "Smile P1",
45
  "smile_thermo": "Smile Anna",
 
47
  "stretch": "Stretch",
48
  }
49
 
50
+ type BinarySensorType = Literal["dhw_state"]
51
+
52
  type NumberType = Literal[
53
+ "boiler_temperature",
54
+ "dhw_temperature",
55
  "temperature_offset",
56
  ]
57
 
58
  type SelectType = Literal[
59
+ "dhw_mode",
60
  "select_dhw_mode",
61
  "select_gateway_mode",
62
  "select_regulation_mode",
63
  "select_schedule",
64
+ "select_zone_profile",
65
  ]
66
  type SelectOptionsType = Literal[
67
  "available_schedules",
 
70
  "regulation_modes",
71
  "zone_profiles",
72
  ]
73
+ type WaterHeaterType = Literal["dhw_temperature"]
74
+
75
+ # Default directives
76
+ DEFAULT_MAX_TEMP: Final = 30
77
+ DEFAULT_MIN_TEMP: Final = 4
78
+ DEFAULT_PORT: Final = 80
79
+ DEFAULT_UPDATE_INTERVAL = timedelta(seconds=60)
80
+ DEFAULT_USERNAME: Final = "smile"
81
+ P1_UPDATE_INTERVAL = timedelta(seconds=10)
82
+
83
+ MASTER_THERMOSTATS: Final[list[str]] = [
84
+ "thermostat",
85
+ "thermostatic_radiator_valve",
86
+ "zone_thermometer",
87
+ "zone_thermostat",
88
+ ]
89
+
90
+ # Select constants
91
+ DHW_MODE: Final = "dhw_mode"
92
+ SELECT_DHW_MODE: Final = "select_dhw_mode"
93
+ SELECT_GATEWAY_MODE: Final = "select_gateway_mode"
94
+ SELECT_REGULATION_MODE: Final = "select_regulation_mode"
95
+ SELECT_SCHEDULE: Final = "select_schedule"
96
+ SELECT_ZONE_PROFILE: Final = "select_zone_profile"
97
+
98
+ # Water_heater constants
99
+ DHW_TEMP: Final = "dhw_temperature"
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/coordinator.py RENAMED
@@ -1,7 +1,8 @@
1
  """DataUpdateCoordinator for Plugwise."""
2
 
3
- from datetime import timedelta
4
 
 
5
  from plugwise import GwEntityData, Smile
6
  from plugwise.exceptions import (
7
  ConnectionFailedError,
@@ -14,28 +15,21 @@
14
  )
15
 
16
  from homeassistant.config_entries import ConfigEntry
17
- from homeassistant.const import (
18
- CONF_HOST,
19
- CONF_PASSWORD,
20
- CONF_PORT,
21
- CONF_SCAN_INTERVAL, # pw-beta options
22
- CONF_USERNAME,
23
- )
24
  from homeassistant.core import HomeAssistant
25
  from homeassistant.exceptions import ConfigEntryError
26
  from homeassistant.helpers import device_registry as dr
27
  from homeassistant.helpers.aiohttp_client import async_get_clientsession
28
  from homeassistant.helpers.debounce import Debouncer
29
  from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
30
- from packaging.version import Version
31
 
32
  from .const import (
 
33
  DEFAULT_UPDATE_INTERVAL,
34
- DEV_CLASS,
35
  DOMAIN,
36
  LOGGER,
37
  P1_UPDATE_INTERVAL,
38
- SWITCH_GROUPS,
39
  )
40
 
41
  type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator]
@@ -44,48 +38,38 @@
44
  class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData]]):
45
  """Class to manage fetching Plugwise data from single endpoint."""
46
 
47
- _connected: bool = False
48
- _current_devices: set[str]
49
- _stored_devices: set[str]
50
- new_devices: set[str]
51
-
52
  config_entry: PlugwiseConfigEntry
53
 
54
- def __init__(
55
- self,
56
- hass: HomeAssistant,
57
- cooldown: float,
58
- config_entry: PlugwiseConfigEntry,
59
- ) -> None: # pw-beta cooldown
60
  """Initialize the coordinator."""
61
  super().__init__(
62
  hass,
63
  LOGGER,
64
  config_entry=config_entry,
65
  name=DOMAIN,
66
- # Core directly updates from const's DEFAULT_SCAN_INTERVAL
67
- # Upstream check correct progress for adjusting
68
  update_interval=DEFAULT_UPDATE_INTERVAL,
69
  # Don't refresh immediately, give the device time to process
70
  # the change in state before we query it.
71
  request_refresh_debouncer=Debouncer(
72
  hass,
73
  LOGGER,
74
- cooldown=cooldown,
75
  immediate=False,
76
  ),
77
  )
78
 
79
  self.api = Smile(
80
  host=self.config_entry.data[CONF_HOST],
 
81
  password=self.config_entry.data[CONF_PASSWORD],
82
- port=self.config_entry.data[CONF_PORT],
83
- username=self.config_entry.data[CONF_USERNAME],
84
  websession=async_get_clientsession(hass, verify_ssl=False),
85
  )
86
- self._current_devices = set()
87
- self._stored_devices = set()
88
- self.new_devices = set()
 
 
89
 
90
  async def _connect(self) -> None:
91
  """Connect to the Plugwise Smile.
@@ -94,16 +78,10 @@
94
  """
95
  version = await self.api.connect()
96
  self._connected = isinstance(version, Version)
97
- if self._connected:
98
- if self.api.smile.type == "power":
99
- self.update_interval = P1_UPDATE_INTERVAL
100
- if (custom_time := self.config_entry.options.get(CONF_SCAN_INTERVAL)) is not None:
101
- self.update_interval = timedelta(
102
- seconds=int(custom_time)
103
- ) # pragma: no cover # pw-beta options
104
-
105
- LOGGER.debug("DUC update interval: %s", self.update_interval) # pw-beta options
106
 
 
107
  async def _async_setup(self) -> None:
108
  """Initialize the update_data process."""
109
  device_reg = dr.async_get(self.hass)
@@ -117,6 +95,7 @@
117
  if identifier[0] == DOMAIN
118
  }
119
 
 
120
  async def _async_update_data(self) -> dict[str, GwEntityData]:
121
  """Fetch data from Plugwise."""
122
  try:
@@ -154,54 +133,81 @@
154
  translation_key="unsupported_firmware",
155
  ) from err
156
 
157
- await self._async_add_remove_devices(data)
158
- LOGGER.debug("%s data: %s", self.api.smile.name, data)
159
  return data
160
 
161
- async def _async_add_remove_devices(self, data: dict[str, GwEntityData]) -> None:
162
  """Add new Plugwise devices, remove non-existing devices."""
163
- # Block switch-groups, use HA group helper instead to create switch-groups
164
- for device_id, device in data.copy().items():
165
- if device.get(DEV_CLASS) in SWITCH_GROUPS:
166
- data.pop(device_id)
167
-
168
- # Collect new or removed devices,
169
- # 'new_devices' contains all devices present in 'data' at init ('self._current_devices' is empty)
170
- # this is required for the initialization of the available platform entities.
171
  set_of_data = set(data)
 
 
 
 
 
172
  self.new_devices = set_of_data - self._current_devices
173
- current_devices = self._stored_devices if not self._current_devices else self._current_devices
 
 
 
 
 
174
  self._current_devices = set_of_data
175
- if (current_devices - set_of_data): # device(s) to remove
176
- await self._async_remove_devices(data)
177
 
178
- async def _async_remove_devices(self, data: dict[str, GwEntityData]) -> None:
179
  """Clean registries when removed devices found."""
180
  device_reg = dr.async_get(self.hass)
181
- device_list = dr.async_entries_for_config_entry(
182
- device_reg, self.config_entry.entry_id
183
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
- # First find the Plugwise via_device
186
- gateway_device = device_reg.async_get_device({(DOMAIN, self.api.gateway_id)})
187
- if gateway_device is None:
188
- return # pragma: no cover
189
-
190
- via_device_id = gateway_device.id
191
- # Then remove the connected orphaned device(s)
192
- for device_entry in device_list:
193
- for identifier in device_entry.identifiers:
194
- if (
195
- identifier[0] == DOMAIN
196
- and device_entry.via_device_id == via_device_id
197
- and identifier[1] not in data
198
- ):
199
- device_reg.async_update_device(
200
- device_entry.id, remove_config_entry_id=self.config_entry.entry_id
201
- )
202
- LOGGER.debug(
203
- "Removed %s device/zone %s %s from device_registry",
204
- DOMAIN,
205
- device_entry.model,
206
- identifier[1],
207
- )
 
1
  """DataUpdateCoordinator for Plugwise."""
2
 
3
+ from typing import override
4
 
5
+ from packaging.version import Version
6
  from plugwise import GwEntityData, Smile
7
  from plugwise.exceptions import (
8
  ConnectionFailedError,
 
15
  )
16
 
17
  from homeassistant.config_entries import ConfigEntry
18
+ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
 
 
 
 
 
 
19
  from homeassistant.core import HomeAssistant
20
  from homeassistant.exceptions import ConfigEntryError
21
  from homeassistant.helpers import device_registry as dr
22
  from homeassistant.helpers.aiohttp_client import async_get_clientsession
23
  from homeassistant.helpers.debounce import Debouncer
24
  from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
 
25
 
26
  from .const import (
27
+ DEFAULT_PORT,
28
  DEFAULT_UPDATE_INTERVAL,
29
+ DEFAULT_USERNAME,
30
  DOMAIN,
31
  LOGGER,
32
  P1_UPDATE_INTERVAL,
 
33
  )
34
 
35
  type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator]
 
38
  class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData]]):
39
  """Class to manage fetching Plugwise data from single endpoint."""
40
 
 
 
 
 
 
41
  config_entry: PlugwiseConfigEntry
42
 
43
+ def __init__(self, hass: HomeAssistant, config_entry: PlugwiseConfigEntry) -> None:
 
 
 
 
 
44
  """Initialize the coordinator."""
45
  super().__init__(
46
  hass,
47
  LOGGER,
48
  config_entry=config_entry,
49
  name=DOMAIN,
 
 
50
  update_interval=DEFAULT_UPDATE_INTERVAL,
51
  # Don't refresh immediately, give the device time to process
52
  # the change in state before we query it.
53
  request_refresh_debouncer=Debouncer(
54
  hass,
55
  LOGGER,
56
+ cooldown=1.5,
57
  immediate=False,
58
  ),
59
  )
60
 
61
  self.api = Smile(
62
  host=self.config_entry.data[CONF_HOST],
63
+ username=self.config_entry.data.get(CONF_USERNAME, DEFAULT_USERNAME),
64
  password=self.config_entry.data[CONF_PASSWORD],
65
+ port=self.config_entry.data.get(CONF_PORT, DEFAULT_PORT),
 
66
  websession=async_get_clientsession(hass, verify_ssl=False),
67
  )
68
+ self._connected: bool = False
69
+ self._current_devices: set[str] = set()
70
+ self._firmware_list: dict[str, str | None] = {}
71
+ self._stored_devices: set[str] = set()
72
+ self.new_devices: set[str] = set()
73
 
74
  async def _connect(self) -> None:
75
  """Connect to the Plugwise Smile.
 
78
  """
79
  version = await self.api.connect()
80
  self._connected = isinstance(version, Version)
81
+ if self._connected and self.api.smile.type == "power":
82
+ self.update_interval = P1_UPDATE_INTERVAL
 
 
 
 
 
 
 
83
 
84
+ @override
85
  async def _async_setup(self) -> None:
86
  """Initialize the update_data process."""
87
  device_reg = dr.async_get(self.hass)
 
95
  if identifier[0] == DOMAIN
96
  }
97
 
98
+ @override
99
  async def _async_update_data(self) -> dict[str, GwEntityData]:
100
  """Fetch data from Plugwise."""
101
  try:
 
133
  translation_key="unsupported_firmware",
134
  ) from err
135
 
136
+ self._add_remove_devices(data)
137
+ self._update_device_firmware(data)
138
  return data
139
 
140
+ def _add_remove_devices(self, data: dict[str, GwEntityData]) -> None:
141
  """Add new Plugwise devices, remove non-existing devices."""
 
 
 
 
 
 
 
 
142
  set_of_data = set(data)
143
+ # Check for new or removed devices,
144
+ # 'new_devices' contains all devices present in 'data'
145
+ # at init ('self._current_devices' is empty) this is
146
+ # required for the proper initialization of all the
147
+ # present platform entities.
148
  self.new_devices = set_of_data - self._current_devices
149
+ for device_id in self.new_devices:
150
+ self._firmware_list.setdefault(device_id, data[device_id].get("firmware"))
151
+
152
+ current_devices = (
153
+ self._stored_devices if not self._current_devices else self._current_devices
154
+ )
155
  self._current_devices = set_of_data
156
+ if removed_devices := (current_devices - set_of_data): # device(s) to remove
157
+ self._remove_devices(removed_devices)
158
 
159
+ def _remove_devices(self, removed_devices: set[str]) -> None:
160
  """Clean registries when removed devices found."""
161
  device_reg = dr.async_get(self.hass)
162
+ for device_id in removed_devices:
163
+ if (
164
+ device_entry := device_reg.async_get_device_by_identifier(
165
+ (DOMAIN, device_id), self.config_entry.entry_id
166
+ )
167
+ ) is not None:
168
+ device_reg.async_remove_device(device_entry.id)
169
+ LOGGER.debug(
170
+ "%s %s %s removed from device_registry",
171
+ DOMAIN,
172
+ device_entry.model,
173
+ device_id,
174
+ )
175
+
176
+ self._firmware_list.pop(device_id, None)
177
+
178
+ def _update_device_firmware(self, data: dict[str, GwEntityData]) -> None:
179
+ """Detect firmware changes and update the device registry."""
180
+ for device_id, device in data.items():
181
+ # Only update firmware when the key is present and not None, to avoid
182
+ # wiping stored firmware on partial or transient updates.
183
+ if "firmware" not in device:
184
+ continue
185
+ new_firmware = device.get("firmware")
186
+ if new_firmware is None:
187
+ continue
188
+ if (
189
+ device_id in self._firmware_list
190
+ and new_firmware != self._firmware_list[device_id]
191
+ ):
192
+ updated = self._update_firmware_in_dr(device_id, new_firmware)
193
+ if updated:
194
+ self._firmware_list[device_id] = new_firmware
195
+
196
+ def _update_firmware_in_dr(self, device_id: str, firmware: str | None) -> bool:
197
+ """Update device sw_version in device_registry."""
198
+ device_reg = dr.async_get(self.hass)
199
+ if (
200
+ device_entry := device_reg.async_get_device_by_identifier(
201
+ (DOMAIN, device_id), self.config_entry.entry_id
202
+ )
203
+ ) is not None:
204
+ device_reg.async_update_device(device_entry.id, sw_version=firmware)
205
+ LOGGER.debug(
206
+ "Firmware in device_registry updated for %s %s %s",
207
+ DOMAIN,
208
+ device_entry.model,
209
+ device_id,
210
+ )
211
+ return True
212
 
213
+ return False # pragma: no cover
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/diagnostics.py RENAMED
@@ -1,7 +1,5 @@
1
  """Diagnostics support for Plugwise."""
2
 
3
- from __future__ import annotations
4
-
5
  from typing import Any
6
 
7
  from homeassistant.core import HomeAssistant
 
1
  """Diagnostics support for Plugwise."""
2
 
 
 
3
  from typing import Any
4
 
5
  from homeassistant.core import HomeAssistant
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/entity.py RENAMED
@@ -1,30 +1,19 @@
1
  """Generic Plugwise Entity Class."""
2
 
3
- from __future__ import annotations
4
 
5
- from plugwise.constants import GwEntityData
6
 
7
- from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST
8
  from homeassistant.helpers.device_registry import (
9
  CONNECTION_NETWORK_MAC,
10
  CONNECTION_ZIGBEE,
11
  DeviceInfo,
 
12
  )
13
  from homeassistant.helpers.update_coordinator import CoordinatorEntity
14
 
15
- from .const import (
16
- AVAILABLE,
17
- DOMAIN,
18
- FIRMWARE,
19
- HARDWARE,
20
- MAC_ADDRESS,
21
- MODEL,
22
- MODEL_ID,
23
- VENDOR,
24
- ZIGBEE_MAC_ADDRESS,
25
- )
26
-
27
- # Upstream consts
28
  from .coordinator import PlugwiseDataUpdateCoordinator
29
 
30
 
@@ -54,10 +43,15 @@
54
  )
55
 
56
  # Build connections set
57
- connections = set()
58
- if mac := self.device.get(MAC_ADDRESS):
59
- connections.add((CONNECTION_NETWORK_MAC, mac))
60
- if zigbee_mac := self.device.get(ZIGBEE_MAC_ADDRESS):
 
 
 
 
 
61
  connections.add((CONNECTION_ZIGBEE, zigbee_mac))
62
 
63
  # Set base device info
@@ -65,12 +59,12 @@
65
  configuration_url=configuration_url,
66
  identifiers={(DOMAIN, device_id)},
67
  connections=connections,
68
- manufacturer=self.device.get(VENDOR),
69
- model=self.device.get(MODEL),
70
- model_id=self.device.get(MODEL_ID),
71
  name=api.smile.name,
72
- sw_version=self.device.get(FIRMWARE),
73
- hw_version=self.device.get(HARDWARE),
74
  )
75
 
76
  # Add extra info if not the gateway device
@@ -78,18 +72,21 @@
78
  self._attr_device_info.update(
79
  {
80
  ATTR_NAME: self.device.get(ATTR_NAME),
81
- ATTR_VIA_DEVICE: (DOMAIN, gateway_id),
 
 
 
 
82
  }
83
  )
84
 
85
  @property
 
86
  def available(self) -> bool:
87
  """Return if entity is available."""
88
  return (
89
- # Upstream: Do not change the AVAILABLE line below: some Plugwise devices and zones
90
- # Upstream: do not provide their availability-status!
91
  self._dev_id in self.coordinator.data
92
- and (self.device.get(AVAILABLE, True) is True)
93
  and super().available
94
  )
95
 
 
1
  """Generic Plugwise Entity Class."""
2
 
3
+ from typing import override
4
 
5
+ from plugwise import GwEntityData
6
 
7
+ from homeassistant.const import ATTR_NAME, CONF_HOST
8
  from homeassistant.helpers.device_registry import (
9
  CONNECTION_NETWORK_MAC,
10
  CONNECTION_ZIGBEE,
11
  DeviceInfo,
12
+ async_get_device_id_by_identifier,
13
  )
14
  from homeassistant.helpers.update_coordinator import CoordinatorEntity
15
 
16
+ from .const import AVAILABLE, DOMAIN
 
 
 
 
 
 
 
 
 
 
 
 
17
  from .coordinator import PlugwiseDataUpdateCoordinator
18
 
19
 
 
43
  )
44
 
45
  # Build connections set
46
+ connections = {
47
+ (CONNECTION_NETWORK_MAC, mac_address)
48
+ for mac_address in (
49
+ self.device.get("mac_address"),
50
+ self.device.get("wifi_mac_address"),
51
+ )
52
+ if mac_address is not None
53
+ }
54
+ if zigbee_mac := self.device.get("zigbee_mac_address"):
55
  connections.add((CONNECTION_ZIGBEE, zigbee_mac))
56
 
57
  # Set base device info
 
59
  configuration_url=configuration_url,
60
  identifiers={(DOMAIN, device_id)},
61
  connections=connections,
62
+ manufacturer=self.device.get("vendor"),
63
+ model=self.device.get("model"),
64
+ model_id=self.device.get("model_id"),
65
  name=api.smile.name,
66
+ sw_version=self.device.get("firmware"),
67
+ hw_version=self.device.get("hardware"),
68
  )
69
 
70
  # Add extra info if not the gateway device
 
72
  self._attr_device_info.update(
73
  {
74
  ATTR_NAME: self.device.get(ATTR_NAME),
75
+ "via_device_id": async_get_device_id_by_identifier(
76
+ coordinator.hass,
77
+ (DOMAIN, gateway_id),
78
+ config_entry_id=entry.entry_id,
79
+ ),
80
  }
81
  )
82
 
83
  @property
84
+ @override
85
  def available(self) -> bool:
86
  """Return if entity is available."""
87
  return (
 
 
88
  self._dev_id in self.coordinator.data
89
+ and (AVAILABLE not in self.device or self.device[AVAILABLE] is True)
90
  and super().available
91
  )
92
 
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/icons.json RENAMED
@@ -66,11 +66,11 @@
66
  "dhw_mode": {
67
  "default": "mdi:shower",
68
  "state": {
 
 
69
  "comfort": "mdi:sofa",
70
  "eco": "mdi:leaf",
71
- "off": "mdi:circle-off-outline",
72
- "boost": "mdi:rocket-launch",
73
- "auto": "mdi:auto-mode"
74
  }
75
  },
76
  "gateway_mode": {
@@ -84,11 +84,11 @@
84
  "regulation_mode": {
85
  "default": "mdi:hvac",
86
  "state": {
87
- "bleeding_hot": "mdi:fire-circle",
88
  "bleeding_cold": "mdi:water-circle",
89
- "off": "mdi:circle-off-outline",
 
90
  "heating": "mdi:radiator",
91
- "cooling": "mdi:snowflake"
92
  }
93
  },
94
  "select_schedule": {
@@ -120,8 +120,5 @@
120
  "default": "mdi:lock"
121
  }
122
  }
123
- },
124
- "services": {
125
- "delete_notification": "mdi:trash-can"
126
  }
127
  }
 
66
  "dhw_mode": {
67
  "default": "mdi:shower",
68
  "state": {
69
+ "auto": "mdi:auto-mode",
70
+ "boost": "mdi:rocket-launch",
71
  "comfort": "mdi:sofa",
72
  "eco": "mdi:leaf",
73
+ "off": "mdi:circle-off-outline"
 
 
74
  }
75
  },
76
  "gateway_mode": {
 
84
  "regulation_mode": {
85
  "default": "mdi:hvac",
86
  "state": {
 
87
  "bleeding_cold": "mdi:water-circle",
88
+ "bleeding_hot": "mdi:fire-circle",
89
+ "cooling": "mdi:snowflake",
90
  "heating": "mdi:radiator",
91
+ "off": "mdi:circle-off-outline"
92
  }
93
  },
94
  "select_schedule": {
 
120
  "default": "mdi:lock"
121
  }
122
  }
 
 
 
123
  }
124
  }
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/manifest.json RENAMED
@@ -1,13 +1,13 @@
1
  {
2
  "domain": "plugwise",
3
- "name": "Plugwise Beta",
4
  "codeowners": ["@CoMPaTech", "@bouwew"],
5
  "config_flow": true,
6
- "documentation": "https://github.com/plugwise/plugwise-beta",
7
  "integration_type": "hub",
8
  "iot_class": "local_polling",
9
  "loggers": ["plugwise"],
10
- "requirements": ["plugwise==1.11.2"],
11
- "version": "0.62.2",
12
  "zeroconf": ["_plugwise._tcp.local."]
13
  }
 
1
  {
2
  "domain": "plugwise",
3
+ "name": "Plugwise",
4
  "codeowners": ["@CoMPaTech", "@bouwew"],
5
  "config_flow": true,
6
+ "documentation": "https://www.home-assistant.io/integrations/plugwise",
7
  "integration_type": "hub",
8
  "iot_class": "local_polling",
9
  "loggers": ["plugwise"],
10
+ "quality_scale": "platinum",
11
+ "requirements": ["plugwise==1.14.7"],
12
  "zeroconf": ["_plugwise._tcp.local."]
13
  }
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/number.py RENAMED
@@ -1,8 +1,7 @@
1
  """Number platform for Plugwise integration."""
2
 
3
- from __future__ import annotations
4
-
5
  from dataclasses import dataclass
 
6
 
7
  from homeassistant.components.number import (
8
  NumberDeviceClass,
@@ -14,18 +13,7 @@
14
  from homeassistant.core import HomeAssistant, callback
15
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
16
 
17
- from .const import (
18
- LOGGER,
19
- LOWER_BOUND,
20
- MAX_BOILER_TEMP,
21
- MAX_DHW_TEMP,
22
- RESOLUTION,
23
- TEMPERATURE_OFFSET,
24
- UPPER_BOUND,
25
- NumberType,
26
- )
27
-
28
- # Upstream consts
29
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
30
  from .entity import PlugwiseEntity
31
  from .util import plugwise_command
@@ -40,25 +28,24 @@
40
  key: NumberType
41
 
42
 
43
- # Upstream + is there a reason we didn't rename this one prefixed?
44
  NUMBER_TYPES = (
45
  PlugwiseNumberEntityDescription(
46
- key=MAX_BOILER_TEMP,
47
- translation_key=MAX_BOILER_TEMP,
48
  device_class=NumberDeviceClass.TEMPERATURE,
49
  entity_category=EntityCategory.CONFIG,
50
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
51
  ),
52
  PlugwiseNumberEntityDescription(
53
- key=MAX_DHW_TEMP,
54
- translation_key=MAX_DHW_TEMP,
55
  device_class=NumberDeviceClass.TEMPERATURE,
56
  entity_category=EntityCategory.CONFIG,
57
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
58
  ),
59
  PlugwiseNumberEntityDescription(
60
- key=TEMPERATURE_OFFSET,
61
- translation_key=TEMPERATURE_OFFSET,
62
  device_class=NumberDeviceClass.TEMPERATURE,
63
  entity_category=EntityCategory.CONFIG,
64
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
@@ -71,8 +58,7 @@
71
  entry: PlugwiseConfigEntry,
72
  async_add_entities: AddConfigEntryEntitiesCallback,
73
  ) -> None:
74
- """Set up Plugwise number platform from a config entry."""
75
- # Upstream above to adhere to standard used
76
  coordinator = entry.runtime_data
77
 
78
  @callback
@@ -81,28 +67,12 @@
81
  if not coordinator.new_devices:
82
  return
83
 
84
- # Upstream consts
85
- # async_add_entities(
86
- # PlugwiseNumberEntity(coordinator, device_id, description)
87
- # for device_id in coordinator.new_devices
88
- # for description in NUMBER_TYPES
89
- # if description.key in coordinator.data.devices[device_id]
90
- # )
91
-
92
- # pw-beta alternative for debugging
93
- entities: list[PlugwiseNumberEntity] = []
94
- for device_id in coordinator.new_devices:
95
- device = coordinator.data[device_id]
96
- for description in NUMBER_TYPES:
97
- if description.key in device:
98
- entities.append(
99
- PlugwiseNumberEntity(coordinator, device_id, description)
100
- )
101
- LOGGER.debug(
102
- "Add %s %s number", device["name"], description.translation_key
103
- )
104
-
105
- async_add_entities(entities)
106
 
107
  _add_entities()
108
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
@@ -121,28 +91,28 @@
121
  ) -> None:
122
  """Initiate Plugwise Number."""
123
  super().__init__(coordinator, device_id)
 
 
 
 
124
  self.device_id = device_id
125
  self.entity_description = description
126
- self._attr_unique_id = f"{device_id}-{description.key}"
127
- self._attr_mode = NumberMode.BOX
128
- ctrl = self.device.get(description.key, {})
129
- self._attr_native_max_value = ctrl.get(UPPER_BOUND, 100.0) # Upstream const
130
- self._attr_native_min_value = ctrl.get(LOWER_BOUND, 0.0) # Upstream const
131
 
132
- native_step = ctrl.get(RESOLUTION, 0.5) # Upstream const
133
- if description.key != TEMPERATURE_OFFSET: # Upstream const
134
  native_step = max(native_step, 0.5)
135
  self._attr_native_step = native_step
136
 
137
  @property
138
- def native_value(self) -> float | None:
 
139
  """Return the present setpoint value."""
140
- return self.device.get(self.entity_description.key, {}).get("setpoint")
141
 
142
  @plugwise_command
 
143
  async def async_set_native_value(self, value: float) -> None:
144
  """Change to the new setpoint value."""
145
- await self.coordinator.api.set_number(self.device_id, self.entity_description.key, value)
146
- LOGGER.debug(
147
- "Setting %s to %s was successful", self.entity_description.key, value
148
  )
 
1
  """Number platform for Plugwise integration."""
2
 
 
 
3
  from dataclasses import dataclass
4
+ from typing import override
5
 
6
  from homeassistant.components.number import (
7
  NumberDeviceClass,
 
13
  from homeassistant.core import HomeAssistant, callback
14
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
15
 
16
+ from .const import NumberType
 
 
 
 
 
 
 
 
 
 
 
17
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
18
  from .entity import PlugwiseEntity
19
  from .util import plugwise_command
 
28
  key: NumberType
29
 
30
 
 
31
  NUMBER_TYPES = (
32
  PlugwiseNumberEntityDescription(
33
+ key="boiler_temperature",
34
+ translation_key="maximum_boiler_temperature",
35
  device_class=NumberDeviceClass.TEMPERATURE,
36
  entity_category=EntityCategory.CONFIG,
37
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
38
  ),
39
  PlugwiseNumberEntityDescription(
40
+ key="dhw_temperature",
41
+ translation_key="max_dhw_temperature",
42
  device_class=NumberDeviceClass.TEMPERATURE,
43
  entity_category=EntityCategory.CONFIG,
44
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
45
  ),
46
  PlugwiseNumberEntityDescription(
47
+ key="temperature_offset",
48
+ translation_key="temperature_offset",
49
  device_class=NumberDeviceClass.TEMPERATURE,
50
  entity_category=EntityCategory.CONFIG,
51
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
 
58
  entry: PlugwiseConfigEntry,
59
  async_add_entities: AddConfigEntryEntitiesCallback,
60
  ) -> None:
61
+ """Set up Plugwise number platform."""
 
62
  coordinator = entry.runtime_data
63
 
64
  @callback
 
67
  if not coordinator.new_devices:
68
  return
69
 
70
+ async_add_entities(
71
+ PlugwiseNumberEntity(coordinator, device_id, description)
72
+ for device_id in coordinator.new_devices
73
+ for description in NUMBER_TYPES
74
+ if description.key in coordinator.data[device_id]
75
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  _add_entities()
78
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
 
91
  ) -> None:
92
  """Initiate Plugwise Number."""
93
  super().__init__(coordinator, device_id)
94
+ self._attr_mode = NumberMode.BOX
95
+ self._attr_native_max_value = self.device[description.key]["upper_bound"]
96
+ self._attr_native_min_value = self.device[description.key]["lower_bound"]
97
+ self._attr_unique_id = f"{device_id}-{description.translation_key}"
98
  self.device_id = device_id
99
  self.entity_description = description
 
 
 
 
 
100
 
101
+ native_step = self.device[description.key]["resolution"]
102
+ if description.key != "temperature_offset":
103
  native_step = max(native_step, 0.5)
104
  self._attr_native_step = native_step
105
 
106
  @property
107
+ @override
108
+ def native_value(self) -> float:
109
  """Return the present setpoint value."""
110
+ return self.device[self.entity_description.key]["setpoint"]
111
 
112
  @plugwise_command
113
+ @override
114
  async def async_set_native_value(self, value: float) -> None:
115
  """Change to the new setpoint value."""
116
+ await self.coordinator.api.set_number(
117
+ self.device_id, self.entity_description.key, value
 
118
  )
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/select.py RENAMED
@@ -1,8 +1,10 @@
1
  """Plugwise Select component for Home Assistant."""
2
 
3
- from __future__ import annotations
4
-
5
  from dataclasses import dataclass
 
 
 
6
 
7
  from homeassistant.components.select import SelectEntity, SelectEntityDescription
8
  from homeassistant.const import STATE_ON, EntityCategory
@@ -10,23 +12,16 @@
10
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
11
 
12
  from .const import (
13
- AVAILABLE_SCHEDULES,
14
- DHW_MODES,
15
- GATEWAY_MODES,
16
  LOCATION,
17
- LOGGER,
18
- REGULATION_MODES,
19
  SELECT_DHW_MODE,
20
  SELECT_GATEWAY_MODE,
21
  SELECT_REGULATION_MODE,
22
  SELECT_SCHEDULE,
23
  SELECT_ZONE_PROFILE,
24
- ZONE_PROFILES,
25
  SelectOptionsType,
26
  SelectType,
27
  )
28
-
29
- # Upstream consts
30
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
31
  from .entity import PlugwiseEntity
32
  from .util import plugwise_command
@@ -40,38 +35,62 @@
40
 
41
  key: SelectType
42
  options_key: SelectOptionsType
 
43
 
44
 
45
- # Upstream
46
  SELECT_TYPES = (
47
  PlugwiseSelectEntityDescription(
48
- key=SELECT_SCHEDULE,
49
- translation_key=SELECT_SCHEDULE,
50
- options_key=AVAILABLE_SCHEDULES,
51
- ),
52
- PlugwiseSelectEntityDescription(
53
- key=SELECT_REGULATION_MODE,
54
- translation_key=SELECT_REGULATION_MODE,
55
  entity_category=EntityCategory.CONFIG,
56
- options_key=REGULATION_MODES,
 
 
 
57
  ),
58
  PlugwiseSelectEntityDescription(
59
  key=SELECT_DHW_MODE,
60
  translation_key=SELECT_DHW_MODE,
61
  entity_category=EntityCategory.CONFIG,
62
- options_key=DHW_MODES,
 
 
 
63
  ),
64
  PlugwiseSelectEntityDescription(
65
  key=SELECT_GATEWAY_MODE,
66
  translation_key=SELECT_GATEWAY_MODE,
67
  entity_category=EntityCategory.CONFIG,
68
- options_key=GATEWAY_MODES,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ),
70
  PlugwiseSelectEntityDescription(
71
  key=SELECT_ZONE_PROFILE,
72
  translation_key=SELECT_ZONE_PROFILE,
73
  entity_category=EntityCategory.CONFIG,
74
- options_key=ZONE_PROFILES,
 
 
 
75
  ),
76
  )
77
 
@@ -81,36 +100,25 @@
81
  entry: PlugwiseConfigEntry,
82
  async_add_entities: AddConfigEntryEntitiesCallback,
83
  ) -> None:
84
- """Set up Plugwise selector from a config entry."""
85
  coordinator = entry.runtime_data
86
 
87
  @callback
88
  def _add_entities() -> None:
89
- """Add Entities."""
90
  if not coordinator.new_devices:
91
  return
92
 
93
- # Upstream consts
94
- # async_add_entities(
95
- # PlugwiseSelectEntity(coordinator, device_id, description)
96
- # for device_id in coordinator.new_devices
97
- # for description in SELECT_TYPES
98
- # if description.options_key in coordinator.data.devices[device_id]
99
- # )
100
- # pw-beta alternative for debugging
101
- entities: list[PlugwiseSelectEntity] = []
102
- for device_id in coordinator.new_devices:
103
- device = coordinator.data[device_id]
104
- for description in SELECT_TYPES:
105
- if device.get(description.options_key):
106
- entities.append(
107
- PlugwiseSelectEntity(coordinator, device_id, description)
108
- )
109
- LOGGER.debug(
110
- "Add %s %s selector", device["name"], description.translation_key
111
- )
112
-
113
- async_add_entities(entities)
114
 
115
  _add_entities()
116
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
@@ -129,34 +137,47 @@
129
  ) -> None:
130
  """Initialise the selector."""
131
  super().__init__(coordinator, device_id)
132
- self._attr_unique_id = f"{device_id}-{entity_description.key}"
 
 
 
133
  self.entity_description = entity_description
134
 
135
- self._location = device_id
136
- if (location := self.device.get(LOCATION)) is not None:
137
- self._location = location
 
 
 
138
 
139
  @property
 
140
  def current_option(self) -> str | None:
141
  """Return the selected entity option to represent the entity state."""
142
- return self.device.get(self.entity_description.key)
143
 
144
  @property
 
145
  def options(self) -> list[str]:
146
  """Return the available select-options."""
147
- return self.device.get(self.entity_description.options_key, [])
148
 
149
  @plugwise_command
 
150
  async def async_select_option(self, option: str) -> None:
151
  """Change to the selected entity option.
152
 
153
- Location ID and STATE_ON are required for the thermostat-schedule select.
 
 
154
  """
155
- await self.coordinator.api.set_select(
156
- self.entity_description.key, self._location, option, STATE_ON
157
- )
158
- LOGGER.debug(
159
- "Set %s to %s was successful",
160
  self.entity_description.key,
 
161
  option,
 
162
  )
 
1
  """Plugwise Select component for Home Assistant."""
2
 
3
+ from collections.abc import Awaitable, Callable
 
4
  from dataclasses import dataclass
5
+ from typing import override
6
+
7
+ from plugwise import Smile
8
 
9
  from homeassistant.components.select import SelectEntity, SelectEntityDescription
10
  from homeassistant.const import STATE_ON, EntityCategory
 
12
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
13
 
14
  from .const import (
15
+ DHW_MODE,
 
 
16
  LOCATION,
 
 
17
  SELECT_DHW_MODE,
18
  SELECT_GATEWAY_MODE,
19
  SELECT_REGULATION_MODE,
20
  SELECT_SCHEDULE,
21
  SELECT_ZONE_PROFILE,
 
22
  SelectOptionsType,
23
  SelectType,
24
  )
 
 
25
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
26
  from .entity import PlugwiseEntity
27
  from .util import plugwise_command
 
35
 
36
  key: SelectType
37
  options_key: SelectOptionsType
38
+ set_value_fn: Callable[[Smile, str, str, str, int | str | None], Awaitable[None]]
39
 
40
 
 
41
  SELECT_TYPES = (
42
  PlugwiseSelectEntityDescription(
43
+ key=DHW_MODE,
44
+ translation_key=SELECT_DHW_MODE,
 
 
 
 
 
45
  entity_category=EntityCategory.CONFIG,
46
+ options_key="dhw_modes",
47
+ set_value_fn=lambda api, key, appl_id, option, length: api.set_dhw_mode(
48
+ key, appl_id, option, length
49
+ ),
50
  ),
51
  PlugwiseSelectEntityDescription(
52
  key=SELECT_DHW_MODE,
53
  translation_key=SELECT_DHW_MODE,
54
  entity_category=EntityCategory.CONFIG,
55
+ options_key="dhw_modes",
56
+ set_value_fn=lambda api, key, appl_or_loc_id, option, state: api.set_select(
57
+ key, appl_or_loc_id, option, state
58
+ ),
59
  ),
60
  PlugwiseSelectEntityDescription(
61
  key=SELECT_GATEWAY_MODE,
62
  translation_key=SELECT_GATEWAY_MODE,
63
  entity_category=EntityCategory.CONFIG,
64
+ options_key="gateway_modes",
65
+ set_value_fn=lambda api, key, appl_or_loc_id, option, state: api.set_select(
66
+ key, appl_or_loc_id, option, state
67
+ ),
68
+ ),
69
+ PlugwiseSelectEntityDescription(
70
+ key=SELECT_REGULATION_MODE,
71
+ translation_key=SELECT_REGULATION_MODE,
72
+ entity_category=EntityCategory.CONFIG,
73
+ options_key="regulation_modes",
74
+ set_value_fn=lambda api, key, appl_or_loc_id, option, state: api.set_select(
75
+ key, appl_or_loc_id, option, state
76
+ ),
77
+ ),
78
+ PlugwiseSelectEntityDescription(
79
+ key=SELECT_SCHEDULE,
80
+ translation_key=SELECT_SCHEDULE,
81
+ options_key="available_schedules",
82
+ set_value_fn=lambda api, key, appl_or_loc_id, option, state: api.set_select(
83
+ key, appl_or_loc_id, option, state
84
+ ),
85
  ),
86
  PlugwiseSelectEntityDescription(
87
  key=SELECT_ZONE_PROFILE,
88
  translation_key=SELECT_ZONE_PROFILE,
89
  entity_category=EntityCategory.CONFIG,
90
+ options_key="zone_profiles",
91
+ set_value_fn=lambda api, key, appl_or_loc_id, option, state: api.set_select(
92
+ key, appl_or_loc_id, option, state
93
+ ),
94
  ),
95
  )
96
 
 
100
  entry: PlugwiseConfigEntry,
101
  async_add_entities: AddConfigEntryEntitiesCallback,
102
  ) -> None:
103
+ """Set up the Smile selector from a config entry."""
104
  coordinator = entry.runtime_data
105
 
106
  @callback
107
  def _add_entities() -> None:
108
+ """Add entities."""
109
  if not coordinator.new_devices:
110
  return
111
 
112
+ async_add_entities(
113
+ PlugwiseSelectEntity(coordinator, device_id, description)
114
+ for device_id in coordinator.new_devices
115
+ for description in SELECT_TYPES
116
+ if (device := coordinator.data[device_id]).get(description.key)
117
+ and (
118
+ description.key not in (DHW_MODE, SELECT_DHW_MODE)
119
+ or len(device[description.options_key]) > 2
120
+ )
121
+ )
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  _add_entities()
124
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
 
137
  ) -> None:
138
  """Initialise the selector."""
139
  super().__init__(coordinator, device_id)
140
+ suffix = entity_description.key
141
+ if entity_description.key == DHW_MODE:
142
+ suffix = SELECT_DHW_MODE
143
+ self._attr_unique_id = f"{device_id}-{suffix}"
144
  self.entity_description = entity_description
145
 
146
+ self._device_or_location = device_id
147
+ if (
148
+ self.entity_description.key in (SELECT_SCHEDULE, SELECT_ZONE_PROFILE)
149
+ and (location := self.device.get(LOCATION)) is not None
150
+ ):
151
+ self._device_or_location = location
152
 
153
  @property
154
+ @override
155
  def current_option(self) -> str | None:
156
  """Return the selected entity option to represent the entity state."""
157
+ return self.device[self.entity_description.key]
158
 
159
  @property
160
+ @override
161
  def options(self) -> list[str]:
162
  """Return the available select-options."""
163
+ return self.device[self.entity_description.options_key]
164
 
165
  @plugwise_command
166
+ @override
167
  async def async_select_option(self, option: str) -> None:
168
  """Change to the selected entity option.
169
 
170
+ The appliance ID (= device_id) is required for the dhw_mode select.
171
+ The location ID is required for the thermostat schedule and zone_profile selects.
172
+ STATE_ON is required for the thermostat schedule select.
173
  """
174
+ options_count_or_state: int | str | None = len(self.options)
175
+ if self.entity_description.key != DHW_MODE:
176
+ options_count_or_state = STATE_ON
177
+ await self.entity_description.set_value_fn(
178
+ self.coordinator.api,
179
  self.entity_description.key,
180
+ self._device_or_location,
181
  option,
182
+ options_count_or_state,
183
  )
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/sensor.py RENAMED
@@ -1,8 +1,7 @@
1
  """Plugwise Sensor component for Home Assistant."""
2
 
3
- from __future__ import annotations
4
-
5
  from dataclasses import dataclass
 
6
 
7
  from plugwise.constants import SensorType
8
 
@@ -13,7 +12,6 @@
13
  SensorStateClass,
14
  )
15
  from homeassistant.const import (
16
- ATTR_TEMPERATURE, # Upstream
17
  LIGHT_LUX,
18
  PERCENTAGE,
19
  EntityCategory,
@@ -28,57 +26,6 @@
28
  from homeassistant.core import HomeAssistant, callback
29
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
30
 
31
- from .const import (
32
- DHW_SETPOINT,
33
- DHW_TEMP,
34
- EL_CONS_INTERVAL,
35
- EL_CONS_OP_CUMULATIVE,
36
- EL_CONS_OP_INTERVAL,
37
- EL_CONS_OP_POINT,
38
- EL_CONS_P_CUMULATIVE,
39
- EL_CONS_P_INTERVAL,
40
- EL_CONS_P_POINT,
41
- EL_CONS_POINT,
42
- EL_CONSUMED,
43
- EL_PH1_CONSUMED,
44
- EL_PH1_PRODUCED,
45
- EL_PH2_CONSUMED,
46
- EL_PH2_PRODUCED,
47
- EL_PH3_CONSUMED,
48
- EL_PH3_PRODUCED,
49
- EL_PROD_INTERVAL,
50
- EL_PROD_OP_CUMULATIVE,
51
- EL_PROD_OP_INTERVAL,
52
- EL_PROD_OP_POINT,
53
- EL_PROD_P_CUMULATIVE,
54
- EL_PROD_P_INTERVAL,
55
- EL_PROD_P_POINT,
56
- EL_PROD_POINT,
57
- EL_PRODUCED,
58
- GAS_CONS_CUMULATIVE,
59
- GAS_CONS_INTERVAL,
60
- INTENDED_BOILER_TEMP,
61
- LOGGER, # pw-beta
62
- MOD_LEVEL,
63
- NET_EL_CUMULATIVE,
64
- NET_EL_POINT,
65
- OUTDOOR_AIR_TEMP,
66
- OUTDOOR_TEMP,
67
- RETURN_TEMP,
68
- SENSORS,
69
- TARGET_TEMP,
70
- TARGET_TEMP_HIGH,
71
- TARGET_TEMP_LOW,
72
- TEMP_DIFF,
73
- VALVE_POS,
74
- VOLTAGE_PH1,
75
- VOLTAGE_PH2,
76
- VOLTAGE_PH3,
77
- WATER_PRESSURE,
78
- WATER_TEMP,
79
- )
80
-
81
- # Upstream consts
82
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
83
  from .entity import PlugwiseEntity
84
 
@@ -93,301 +40,299 @@
93
  key: SensorType
94
 
95
 
96
- # Upstream consts
97
- PLUGWISE_SENSORS: tuple[PlugwiseSensorEntityDescription, ...] = (
98
  PlugwiseSensorEntityDescription(
99
- key=TARGET_TEMP,
100
- translation_key=TARGET_TEMP,
101
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
102
  device_class=SensorDeviceClass.TEMPERATURE,
103
  state_class=SensorStateClass.MEASUREMENT,
104
  ),
105
  PlugwiseSensorEntityDescription(
106
- key=TARGET_TEMP_HIGH,
107
  translation_key="cooling_setpoint",
108
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
109
  device_class=SensorDeviceClass.TEMPERATURE,
110
  state_class=SensorStateClass.MEASUREMENT,
111
  ),
112
  PlugwiseSensorEntityDescription(
113
- key=TARGET_TEMP_LOW,
114
  translation_key="heating_setpoint",
115
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
116
  device_class=SensorDeviceClass.TEMPERATURE,
117
  state_class=SensorStateClass.MEASUREMENT,
118
  ),
119
  PlugwiseSensorEntityDescription(
120
- key=ATTR_TEMPERATURE,
121
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
122
  device_class=SensorDeviceClass.TEMPERATURE,
123
  state_class=SensorStateClass.MEASUREMENT,
124
  ),
125
  PlugwiseSensorEntityDescription(
126
- key=INTENDED_BOILER_TEMP,
127
- translation_key=INTENDED_BOILER_TEMP,
128
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
129
  device_class=SensorDeviceClass.TEMPERATURE,
130
  entity_category=EntityCategory.DIAGNOSTIC,
131
  state_class=SensorStateClass.MEASUREMENT,
132
  ),
133
  PlugwiseSensorEntityDescription(
134
- key=TEMP_DIFF,
135
- translation_key=TEMP_DIFF,
136
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
137
  device_class=SensorDeviceClass.TEMPERATURE,
138
  entity_category=EntityCategory.DIAGNOSTIC,
139
  state_class=SensorStateClass.MEASUREMENT,
140
  ),
141
  PlugwiseSensorEntityDescription(
142
- key=OUTDOOR_TEMP,
143
- translation_key=OUTDOOR_TEMP,
144
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
145
  device_class=SensorDeviceClass.TEMPERATURE,
146
  entity_category=EntityCategory.DIAGNOSTIC,
147
  state_class=SensorStateClass.MEASUREMENT,
148
- suggested_display_precision=1,
149
  ),
150
  PlugwiseSensorEntityDescription(
151
- key=OUTDOOR_AIR_TEMP,
152
- translation_key=OUTDOOR_AIR_TEMP,
153
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
154
  device_class=SensorDeviceClass.TEMPERATURE,
155
  entity_category=EntityCategory.DIAGNOSTIC,
156
  state_class=SensorStateClass.MEASUREMENT,
157
  ),
158
  PlugwiseSensorEntityDescription(
159
- key=WATER_TEMP,
160
- translation_key=WATER_TEMP,
161
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
162
  device_class=SensorDeviceClass.TEMPERATURE,
163
  entity_category=EntityCategory.DIAGNOSTIC,
164
  state_class=SensorStateClass.MEASUREMENT,
165
  ),
166
  PlugwiseSensorEntityDescription(
167
- key=RETURN_TEMP,
168
- translation_key=RETURN_TEMP,
169
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
170
  device_class=SensorDeviceClass.TEMPERATURE,
171
  entity_category=EntityCategory.DIAGNOSTIC,
172
  state_class=SensorStateClass.MEASUREMENT,
173
  ),
174
  PlugwiseSensorEntityDescription(
175
- key=EL_CONSUMED,
176
- translation_key=EL_CONSUMED,
177
  native_unit_of_measurement=UnitOfPower.WATT,
178
  device_class=SensorDeviceClass.POWER,
179
  state_class=SensorStateClass.MEASUREMENT,
180
  ),
181
  PlugwiseSensorEntityDescription(
182
- key=EL_PRODUCED,
183
- translation_key=EL_PRODUCED,
184
  native_unit_of_measurement=UnitOfPower.WATT,
185
  device_class=SensorDeviceClass.POWER,
186
  state_class=SensorStateClass.MEASUREMENT,
187
  entity_registry_enabled_default=False,
188
  ),
189
  PlugwiseSensorEntityDescription(
190
- key=EL_CONS_INTERVAL,
191
- translation_key=EL_CONS_INTERVAL,
192
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
193
  device_class=SensorDeviceClass.ENERGY,
194
  state_class=SensorStateClass.TOTAL,
195
  ),
196
  PlugwiseSensorEntityDescription(
197
- key=EL_CONS_P_INTERVAL,
198
- translation_key=EL_CONS_P_INTERVAL,
199
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
200
  device_class=SensorDeviceClass.ENERGY,
201
  state_class=SensorStateClass.TOTAL,
202
  ),
203
  PlugwiseSensorEntityDescription(
204
- key=EL_CONS_OP_INTERVAL,
205
- translation_key=EL_CONS_OP_INTERVAL,
206
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
207
  device_class=SensorDeviceClass.ENERGY,
208
  state_class=SensorStateClass.TOTAL,
209
  ),
210
  PlugwiseSensorEntityDescription(
211
- key=EL_PROD_INTERVAL,
212
- translation_key=EL_PROD_INTERVAL,
213
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
214
  device_class=SensorDeviceClass.ENERGY,
215
  state_class=SensorStateClass.TOTAL,
216
  entity_registry_enabled_default=False,
217
  ),
218
  PlugwiseSensorEntityDescription(
219
- key=EL_PROD_P_INTERVAL,
220
- translation_key=EL_PROD_P_INTERVAL,
221
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
222
  device_class=SensorDeviceClass.ENERGY,
223
  state_class=SensorStateClass.TOTAL,
224
  ),
225
  PlugwiseSensorEntityDescription(
226
- key=EL_PROD_OP_INTERVAL,
227
- translation_key=EL_PROD_OP_INTERVAL,
228
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
229
  device_class=SensorDeviceClass.ENERGY,
230
  state_class=SensorStateClass.TOTAL,
231
  ),
232
  PlugwiseSensorEntityDescription(
233
- key=EL_CONS_POINT,
234
- translation_key=EL_CONS_POINT,
235
  device_class=SensorDeviceClass.POWER,
236
  native_unit_of_measurement=UnitOfPower.WATT,
237
  state_class=SensorStateClass.MEASUREMENT,
238
  ),
239
  PlugwiseSensorEntityDescription(
240
- key=EL_CONS_OP_POINT,
241
- translation_key=EL_CONS_OP_POINT,
242
  native_unit_of_measurement=UnitOfPower.WATT,
243
  device_class=SensorDeviceClass.POWER,
244
  state_class=SensorStateClass.MEASUREMENT,
245
  ),
246
  PlugwiseSensorEntityDescription(
247
- key=EL_CONS_P_POINT,
248
- translation_key=EL_CONS_P_POINT,
249
  native_unit_of_measurement=UnitOfPower.WATT,
250
  device_class=SensorDeviceClass.POWER,
251
  state_class=SensorStateClass.MEASUREMENT,
252
  ),
253
  PlugwiseSensorEntityDescription(
254
- key=EL_CONS_OP_CUMULATIVE,
255
- translation_key=EL_CONS_OP_CUMULATIVE,
256
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
257
  device_class=SensorDeviceClass.ENERGY,
258
  state_class=SensorStateClass.TOTAL_INCREASING,
259
  ),
260
  PlugwiseSensorEntityDescription(
261
- key=EL_CONS_P_CUMULATIVE,
262
- translation_key=EL_CONS_P_CUMULATIVE,
263
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
264
  device_class=SensorDeviceClass.ENERGY,
265
  state_class=SensorStateClass.TOTAL_INCREASING,
266
  ),
267
  PlugwiseSensorEntityDescription(
268
- key=EL_PROD_POINT,
269
- translation_key=EL_PROD_POINT,
270
  device_class=SensorDeviceClass.POWER,
271
  native_unit_of_measurement=UnitOfPower.WATT,
272
  state_class=SensorStateClass.MEASUREMENT,
273
  ),
274
  PlugwiseSensorEntityDescription(
275
- key=EL_PROD_OP_POINT,
276
- translation_key=EL_PROD_OP_POINT,
277
  native_unit_of_measurement=UnitOfPower.WATT,
278
  device_class=SensorDeviceClass.POWER,
279
  state_class=SensorStateClass.MEASUREMENT,
280
  ),
281
  PlugwiseSensorEntityDescription(
282
- key=EL_PROD_P_POINT,
283
- translation_key=EL_PROD_P_POINT,
284
  native_unit_of_measurement=UnitOfPower.WATT,
285
  device_class=SensorDeviceClass.POWER,
286
  state_class=SensorStateClass.MEASUREMENT,
287
  ),
288
  PlugwiseSensorEntityDescription(
289
- key=EL_PROD_OP_CUMULATIVE,
290
- translation_key=EL_PROD_OP_CUMULATIVE,
291
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
292
  device_class=SensorDeviceClass.ENERGY,
293
  state_class=SensorStateClass.TOTAL_INCREASING,
294
  ),
295
  PlugwiseSensorEntityDescription(
296
- key=EL_PROD_P_CUMULATIVE,
297
- translation_key=EL_PROD_P_CUMULATIVE,
298
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
299
  device_class=SensorDeviceClass.ENERGY,
300
  state_class=SensorStateClass.TOTAL_INCREASING,
301
  ),
302
  PlugwiseSensorEntityDescription(
303
- key=EL_PH1_CONSUMED,
304
- translation_key=EL_PH1_CONSUMED,
305
  device_class=SensorDeviceClass.POWER,
306
  native_unit_of_measurement=UnitOfPower.WATT,
307
  state_class=SensorStateClass.MEASUREMENT,
308
  ),
309
  PlugwiseSensorEntityDescription(
310
- key=EL_PH2_CONSUMED,
311
- translation_key=EL_PH2_CONSUMED,
312
  device_class=SensorDeviceClass.POWER,
313
  native_unit_of_measurement=UnitOfPower.WATT,
314
  state_class=SensorStateClass.MEASUREMENT,
315
  ),
316
  PlugwiseSensorEntityDescription(
317
- key=EL_PH3_CONSUMED,
318
- translation_key=EL_PH3_CONSUMED,
319
  device_class=SensorDeviceClass.POWER,
320
  native_unit_of_measurement=UnitOfPower.WATT,
321
  state_class=SensorStateClass.MEASUREMENT,
322
  ),
323
  PlugwiseSensorEntityDescription(
324
- key=EL_PH1_PRODUCED,
325
- translation_key=EL_PH1_PRODUCED,
326
  device_class=SensorDeviceClass.POWER,
327
  native_unit_of_measurement=UnitOfPower.WATT,
328
  state_class=SensorStateClass.MEASUREMENT,
329
  ),
330
  PlugwiseSensorEntityDescription(
331
- key=EL_PH2_PRODUCED,
332
- translation_key=EL_PH2_PRODUCED,
333
  device_class=SensorDeviceClass.POWER,
334
  native_unit_of_measurement=UnitOfPower.WATT,
335
  state_class=SensorStateClass.MEASUREMENT,
336
  ),
337
  PlugwiseSensorEntityDescription(
338
- key=EL_PH3_PRODUCED,
339
- translation_key=EL_PH3_PRODUCED,
340
  device_class=SensorDeviceClass.POWER,
341
  native_unit_of_measurement=UnitOfPower.WATT,
342
  state_class=SensorStateClass.MEASUREMENT,
343
  ),
344
  PlugwiseSensorEntityDescription(
345
- key=VOLTAGE_PH1,
346
- translation_key=VOLTAGE_PH1,
347
  device_class=SensorDeviceClass.VOLTAGE,
348
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
349
  state_class=SensorStateClass.MEASUREMENT,
350
  entity_registry_enabled_default=False,
351
  ),
352
  PlugwiseSensorEntityDescription(
353
- key=VOLTAGE_PH2,
354
- translation_key=VOLTAGE_PH2,
355
  device_class=SensorDeviceClass.VOLTAGE,
356
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
357
  state_class=SensorStateClass.MEASUREMENT,
358
  entity_registry_enabled_default=False,
359
  ),
360
  PlugwiseSensorEntityDescription(
361
- key=VOLTAGE_PH3,
362
- translation_key=VOLTAGE_PH3,
363
  device_class=SensorDeviceClass.VOLTAGE,
364
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
365
  state_class=SensorStateClass.MEASUREMENT,
366
  entity_registry_enabled_default=False,
367
  ),
368
  PlugwiseSensorEntityDescription(
369
- key=GAS_CONS_INTERVAL,
370
- translation_key=GAS_CONS_INTERVAL,
371
  native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
372
  state_class=SensorStateClass.MEASUREMENT,
373
  ),
374
  PlugwiseSensorEntityDescription(
375
- key=GAS_CONS_CUMULATIVE,
376
- translation_key=GAS_CONS_CUMULATIVE,
377
  native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
378
  device_class=SensorDeviceClass.GAS,
379
  state_class=SensorStateClass.TOTAL,
380
  ),
381
  PlugwiseSensorEntityDescription(
382
- key=NET_EL_POINT,
383
- translation_key=NET_EL_POINT,
384
  native_unit_of_measurement=UnitOfPower.WATT,
385
  device_class=SensorDeviceClass.POWER,
386
  state_class=SensorStateClass.MEASUREMENT,
387
  ),
388
  PlugwiseSensorEntityDescription(
389
- key=NET_EL_CUMULATIVE,
390
- translation_key=NET_EL_CUMULATIVE,
391
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
392
  device_class=SensorDeviceClass.ENERGY,
393
  state_class=SensorStateClass.TOTAL,
@@ -407,22 +352,22 @@
407
  state_class=SensorStateClass.MEASUREMENT,
408
  ),
409
  PlugwiseSensorEntityDescription(
410
- key=MOD_LEVEL,
411
- translation_key=MOD_LEVEL,
412
  native_unit_of_measurement=PERCENTAGE,
413
  entity_category=EntityCategory.DIAGNOSTIC,
414
  state_class=SensorStateClass.MEASUREMENT,
415
  ),
416
  PlugwiseSensorEntityDescription(
417
- key=VALVE_POS,
418
- translation_key=VALVE_POS,
419
  native_unit_of_measurement=PERCENTAGE,
420
  entity_category=EntityCategory.DIAGNOSTIC,
421
  state_class=SensorStateClass.MEASUREMENT,
422
  ),
423
  PlugwiseSensorEntityDescription(
424
- key=WATER_PRESSURE,
425
- translation_key=WATER_PRESSURE,
426
  native_unit_of_measurement=UnitOfPressure.BAR,
427
  device_class=SensorDeviceClass.PRESSURE,
428
  entity_category=EntityCategory.DIAGNOSTIC,
@@ -435,16 +380,16 @@
435
  state_class=SensorStateClass.MEASUREMENT,
436
  ),
437
  PlugwiseSensorEntityDescription(
438
- key=DHW_TEMP,
439
- translation_key=DHW_TEMP,
440
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
441
  device_class=SensorDeviceClass.TEMPERATURE,
442
  entity_category=EntityCategory.DIAGNOSTIC,
443
  state_class=SensorStateClass.MEASUREMENT,
444
  ),
445
  PlugwiseSensorEntityDescription(
446
- key=DHW_SETPOINT,
447
- translation_key=DHW_SETPOINT,
448
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
449
  device_class=SensorDeviceClass.TEMPERATURE,
450
  entity_category=EntityCategory.DIAGNOSTIC,
@@ -458,8 +403,7 @@
458
  entry: PlugwiseConfigEntry,
459
  async_add_entities: AddConfigEntryEntitiesCallback,
460
  ) -> None:
461
- """Set up Plugwise sensors from a config entry."""
462
- # Upstream as Plugwise not Smile
463
  coordinator = entry.runtime_data
464
 
465
  @callback
@@ -468,29 +412,13 @@
468
  if not coordinator.new_devices:
469
  return
470
 
471
- # Upstream consts
472
- # async_add_entities(
473
- # PlugwiseSensorEntity(coordinator, device_id, description)
474
- # for device_id in coordinator.new_devices
475
- # if (sensors := coordinator.data.devices[device_id].get(SENSORS))
476
- # for description in PLUGWISE_SENSORS
477
- # if description.key in sensors
478
- # )
479
- # pw-beta alternative for debugging
480
- entities: list[PlugwiseSensorEntity] = []
481
- for device_id in coordinator.new_devices:
482
- device = coordinator.data[device_id]
483
- if not (sensors := device.get(SENSORS)):
484
- continue
485
- for description in PLUGWISE_SENSORS:
486
- if description.key not in sensors:
487
- continue
488
- entities.append(PlugwiseSensorEntity(coordinator, device_id, description))
489
- LOGGER.debug(
490
- "Add %s %s sensor", device["name"], description.translation_key or description.key
491
- )
492
-
493
- async_add_entities(entities)
494
 
495
  _add_entities()
496
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
@@ -509,10 +437,11 @@
509
  ) -> None:
510
  """Initialise the sensor."""
511
  super().__init__(coordinator, device_id)
512
- self.entity_description = description
513
  self._attr_unique_id = f"{device_id}-{description.key}"
 
514
 
515
  @property
516
- def native_value(self) -> int | float | None:
 
517
  """Return the value reported by the sensor."""
518
- return self.device.get(SENSORS, {}).get(self.entity_description.key) # Upstream consts
 
1
  """Plugwise Sensor component for Home Assistant."""
2
 
 
 
3
  from dataclasses import dataclass
4
+ from typing import override
5
 
6
  from plugwise.constants import SensorType
7
 
 
12
  SensorStateClass,
13
  )
14
  from homeassistant.const import (
 
15
  LIGHT_LUX,
16
  PERCENTAGE,
17
  EntityCategory,
 
26
  from homeassistant.core import HomeAssistant, callback
27
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
30
  from .entity import PlugwiseEntity
31
 
 
40
  key: SensorType
41
 
42
 
43
+ SENSORS: tuple[PlugwiseSensorEntityDescription, ...] = (
 
44
  PlugwiseSensorEntityDescription(
45
+ key="setpoint",
46
+ translation_key="setpoint",
47
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
48
  device_class=SensorDeviceClass.TEMPERATURE,
49
  state_class=SensorStateClass.MEASUREMENT,
50
  ),
51
  PlugwiseSensorEntityDescription(
52
+ key="setpoint_high",
53
  translation_key="cooling_setpoint",
54
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
55
  device_class=SensorDeviceClass.TEMPERATURE,
56
  state_class=SensorStateClass.MEASUREMENT,
57
  ),
58
  PlugwiseSensorEntityDescription(
59
+ key="setpoint_low",
60
  translation_key="heating_setpoint",
61
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
62
  device_class=SensorDeviceClass.TEMPERATURE,
63
  state_class=SensorStateClass.MEASUREMENT,
64
  ),
65
  PlugwiseSensorEntityDescription(
66
+ key="temperature",
67
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
68
  device_class=SensorDeviceClass.TEMPERATURE,
69
  state_class=SensorStateClass.MEASUREMENT,
70
  ),
71
  PlugwiseSensorEntityDescription(
72
+ key="intended_boiler_temperature",
73
+ translation_key="intended_boiler_temperature",
74
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
75
  device_class=SensorDeviceClass.TEMPERATURE,
76
  entity_category=EntityCategory.DIAGNOSTIC,
77
  state_class=SensorStateClass.MEASUREMENT,
78
  ),
79
  PlugwiseSensorEntityDescription(
80
+ key="temperature_difference",
81
+ translation_key="temperature_difference",
82
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
83
  device_class=SensorDeviceClass.TEMPERATURE,
84
  entity_category=EntityCategory.DIAGNOSTIC,
85
  state_class=SensorStateClass.MEASUREMENT,
86
  ),
87
  PlugwiseSensorEntityDescription(
88
+ key="outdoor_temperature",
89
+ translation_key="outdoor_temperature",
90
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
91
  device_class=SensorDeviceClass.TEMPERATURE,
92
  entity_category=EntityCategory.DIAGNOSTIC,
93
  state_class=SensorStateClass.MEASUREMENT,
 
94
  ),
95
  PlugwiseSensorEntityDescription(
96
+ key="outdoor_air_temperature",
97
+ translation_key="outdoor_air_temperature",
98
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
99
  device_class=SensorDeviceClass.TEMPERATURE,
100
  entity_category=EntityCategory.DIAGNOSTIC,
101
  state_class=SensorStateClass.MEASUREMENT,
102
  ),
103
  PlugwiseSensorEntityDescription(
104
+ key="water_temperature",
105
+ translation_key="water_temperature",
106
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
107
  device_class=SensorDeviceClass.TEMPERATURE,
108
  entity_category=EntityCategory.DIAGNOSTIC,
109
  state_class=SensorStateClass.MEASUREMENT,
110
  ),
111
  PlugwiseSensorEntityDescription(
112
+ key="return_temperature",
113
+ translation_key="return_temperature",
114
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
115
  device_class=SensorDeviceClass.TEMPERATURE,
116
  entity_category=EntityCategory.DIAGNOSTIC,
117
  state_class=SensorStateClass.MEASUREMENT,
118
  ),
119
  PlugwiseSensorEntityDescription(
120
+ key="electricity_consumed",
121
+ translation_key="electricity_consumed",
122
  native_unit_of_measurement=UnitOfPower.WATT,
123
  device_class=SensorDeviceClass.POWER,
124
  state_class=SensorStateClass.MEASUREMENT,
125
  ),
126
  PlugwiseSensorEntityDescription(
127
+ key="electricity_produced",
128
+ translation_key="electricity_produced",
129
  native_unit_of_measurement=UnitOfPower.WATT,
130
  device_class=SensorDeviceClass.POWER,
131
  state_class=SensorStateClass.MEASUREMENT,
132
  entity_registry_enabled_default=False,
133
  ),
134
  PlugwiseSensorEntityDescription(
135
+ key="electricity_consumed_interval",
136
+ translation_key="electricity_consumed_interval",
137
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
138
  device_class=SensorDeviceClass.ENERGY,
139
  state_class=SensorStateClass.TOTAL,
140
  ),
141
  PlugwiseSensorEntityDescription(
142
+ key="electricity_consumed_peak_interval",
143
+ translation_key="electricity_consumed_peak_interval",
144
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
145
  device_class=SensorDeviceClass.ENERGY,
146
  state_class=SensorStateClass.TOTAL,
147
  ),
148
  PlugwiseSensorEntityDescription(
149
+ key="electricity_consumed_off_peak_interval",
150
+ translation_key="electricity_consumed_off_peak_interval",
151
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
152
  device_class=SensorDeviceClass.ENERGY,
153
  state_class=SensorStateClass.TOTAL,
154
  ),
155
  PlugwiseSensorEntityDescription(
156
+ key="electricity_produced_interval",
157
+ translation_key="electricity_produced_interval",
158
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
159
  device_class=SensorDeviceClass.ENERGY,
160
  state_class=SensorStateClass.TOTAL,
161
  entity_registry_enabled_default=False,
162
  ),
163
  PlugwiseSensorEntityDescription(
164
+ key="electricity_produced_peak_interval",
165
+ translation_key="electricity_produced_peak_interval",
166
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
167
  device_class=SensorDeviceClass.ENERGY,
168
  state_class=SensorStateClass.TOTAL,
169
  ),
170
  PlugwiseSensorEntityDescription(
171
+ key="electricity_produced_off_peak_interval",
172
+ translation_key="electricity_produced_off_peak_interval",
173
  native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
174
  device_class=SensorDeviceClass.ENERGY,
175
  state_class=SensorStateClass.TOTAL,
176
  ),
177
  PlugwiseSensorEntityDescription(
178
+ key="electricity_consumed_point",
179
+ translation_key="electricity_consumed_point",
180
  device_class=SensorDeviceClass.POWER,
181
  native_unit_of_measurement=UnitOfPower.WATT,
182
  state_class=SensorStateClass.MEASUREMENT,
183
  ),
184
  PlugwiseSensorEntityDescription(
185
+ key="electricity_consumed_off_peak_point",
186
+ translation_key="electricity_consumed_off_peak_point",
187
  native_unit_of_measurement=UnitOfPower.WATT,
188
  device_class=SensorDeviceClass.POWER,
189
  state_class=SensorStateClass.MEASUREMENT,
190
  ),
191
  PlugwiseSensorEntityDescription(
192
+ key="electricity_consumed_peak_point",
193
+ translation_key="electricity_consumed_peak_point",
194
  native_unit_of_measurement=UnitOfPower.WATT,
195
  device_class=SensorDeviceClass.POWER,
196
  state_class=SensorStateClass.MEASUREMENT,
197
  ),
198
  PlugwiseSensorEntityDescription(
199
+ key="electricity_consumed_off_peak_cumulative",
200
+ translation_key="electricity_consumed_off_peak_cumulative",
201
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
202
  device_class=SensorDeviceClass.ENERGY,
203
  state_class=SensorStateClass.TOTAL_INCREASING,
204
  ),
205
  PlugwiseSensorEntityDescription(
206
+ key="electricity_consumed_peak_cumulative",
207
+ translation_key="electricity_consumed_peak_cumulative",
208
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
209
  device_class=SensorDeviceClass.ENERGY,
210
  state_class=SensorStateClass.TOTAL_INCREASING,
211
  ),
212
  PlugwiseSensorEntityDescription(
213
+ key="electricity_produced_point",
214
+ translation_key="electricity_produced_point",
215
  device_class=SensorDeviceClass.POWER,
216
  native_unit_of_measurement=UnitOfPower.WATT,
217
  state_class=SensorStateClass.MEASUREMENT,
218
  ),
219
  PlugwiseSensorEntityDescription(
220
+ key="electricity_produced_off_peak_point",
221
+ translation_key="electricity_produced_off_peak_point",
222
  native_unit_of_measurement=UnitOfPower.WATT,
223
  device_class=SensorDeviceClass.POWER,
224
  state_class=SensorStateClass.MEASUREMENT,
225
  ),
226
  PlugwiseSensorEntityDescription(
227
+ key="electricity_produced_peak_point",
228
+ translation_key="electricity_produced_peak_point",
229
  native_unit_of_measurement=UnitOfPower.WATT,
230
  device_class=SensorDeviceClass.POWER,
231
  state_class=SensorStateClass.MEASUREMENT,
232
  ),
233
  PlugwiseSensorEntityDescription(
234
+ key="electricity_produced_off_peak_cumulative",
235
+ translation_key="electricity_produced_off_peak_cumulative",
236
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
237
  device_class=SensorDeviceClass.ENERGY,
238
  state_class=SensorStateClass.TOTAL_INCREASING,
239
  ),
240
  PlugwiseSensorEntityDescription(
241
+ key="electricity_produced_peak_cumulative",
242
+ translation_key="electricity_produced_peak_cumulative",
243
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
244
  device_class=SensorDeviceClass.ENERGY,
245
  state_class=SensorStateClass.TOTAL_INCREASING,
246
  ),
247
  PlugwiseSensorEntityDescription(
248
+ key="electricity_phase_one_consumed",
249
+ translation_key="electricity_phase_one_consumed",
250
  device_class=SensorDeviceClass.POWER,
251
  native_unit_of_measurement=UnitOfPower.WATT,
252
  state_class=SensorStateClass.MEASUREMENT,
253
  ),
254
  PlugwiseSensorEntityDescription(
255
+ key="electricity_phase_two_consumed",
256
+ translation_key="electricity_phase_two_consumed",
257
  device_class=SensorDeviceClass.POWER,
258
  native_unit_of_measurement=UnitOfPower.WATT,
259
  state_class=SensorStateClass.MEASUREMENT,
260
  ),
261
  PlugwiseSensorEntityDescription(
262
+ key="electricity_phase_three_consumed",
263
+ translation_key="electricity_phase_three_consumed",
264
  device_class=SensorDeviceClass.POWER,
265
  native_unit_of_measurement=UnitOfPower.WATT,
266
  state_class=SensorStateClass.MEASUREMENT,
267
  ),
268
  PlugwiseSensorEntityDescription(
269
+ key="electricity_phase_one_produced",
270
+ translation_key="electricity_phase_one_produced",
271
  device_class=SensorDeviceClass.POWER,
272
  native_unit_of_measurement=UnitOfPower.WATT,
273
  state_class=SensorStateClass.MEASUREMENT,
274
  ),
275
  PlugwiseSensorEntityDescription(
276
+ key="electricity_phase_two_produced",
277
+ translation_key="electricity_phase_two_produced",
278
  device_class=SensorDeviceClass.POWER,
279
  native_unit_of_measurement=UnitOfPower.WATT,
280
  state_class=SensorStateClass.MEASUREMENT,
281
  ),
282
  PlugwiseSensorEntityDescription(
283
+ key="electricity_phase_three_produced",
284
+ translation_key="electricity_phase_three_produced",
285
  device_class=SensorDeviceClass.POWER,
286
  native_unit_of_measurement=UnitOfPower.WATT,
287
  state_class=SensorStateClass.MEASUREMENT,
288
  ),
289
  PlugwiseSensorEntityDescription(
290
+ key="voltage_phase_one",
291
+ translation_key="voltage_phase_one",
292
  device_class=SensorDeviceClass.VOLTAGE,
293
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
294
  state_class=SensorStateClass.MEASUREMENT,
295
  entity_registry_enabled_default=False,
296
  ),
297
  PlugwiseSensorEntityDescription(
298
+ key="voltage_phase_two",
299
+ translation_key="voltage_phase_two",
300
  device_class=SensorDeviceClass.VOLTAGE,
301
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
302
  state_class=SensorStateClass.MEASUREMENT,
303
  entity_registry_enabled_default=False,
304
  ),
305
  PlugwiseSensorEntityDescription(
306
+ key="voltage_phase_three",
307
+ translation_key="voltage_phase_three",
308
  device_class=SensorDeviceClass.VOLTAGE,
309
  native_unit_of_measurement=UnitOfElectricPotential.VOLT,
310
  state_class=SensorStateClass.MEASUREMENT,
311
  entity_registry_enabled_default=False,
312
  ),
313
  PlugwiseSensorEntityDescription(
314
+ key="gas_consumed_interval",
315
+ translation_key="gas_consumed_interval",
316
  native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
317
  state_class=SensorStateClass.MEASUREMENT,
318
  ),
319
  PlugwiseSensorEntityDescription(
320
+ key="gas_consumed_cumulative",
321
+ translation_key="gas_consumed_cumulative",
322
  native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
323
  device_class=SensorDeviceClass.GAS,
324
  state_class=SensorStateClass.TOTAL,
325
  ),
326
  PlugwiseSensorEntityDescription(
327
+ key="net_electricity_point",
328
+ translation_key="net_electricity_point",
329
  native_unit_of_measurement=UnitOfPower.WATT,
330
  device_class=SensorDeviceClass.POWER,
331
  state_class=SensorStateClass.MEASUREMENT,
332
  ),
333
  PlugwiseSensorEntityDescription(
334
+ key="net_electricity_cumulative",
335
+ translation_key="net_electricity_cumulative",
336
  native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
337
  device_class=SensorDeviceClass.ENERGY,
338
  state_class=SensorStateClass.TOTAL,
 
352
  state_class=SensorStateClass.MEASUREMENT,
353
  ),
354
  PlugwiseSensorEntityDescription(
355
+ key="modulation_level",
356
+ translation_key="modulation_level",
357
  native_unit_of_measurement=PERCENTAGE,
358
  entity_category=EntityCategory.DIAGNOSTIC,
359
  state_class=SensorStateClass.MEASUREMENT,
360
  ),
361
  PlugwiseSensorEntityDescription(
362
+ key="valve_position",
363
+ translation_key="valve_position",
364
  native_unit_of_measurement=PERCENTAGE,
365
  entity_category=EntityCategory.DIAGNOSTIC,
366
  state_class=SensorStateClass.MEASUREMENT,
367
  ),
368
  PlugwiseSensorEntityDescription(
369
+ key="water_pressure",
370
+ translation_key="water_pressure",
371
  native_unit_of_measurement=UnitOfPressure.BAR,
372
  device_class=SensorDeviceClass.PRESSURE,
373
  entity_category=EntityCategory.DIAGNOSTIC,
 
380
  state_class=SensorStateClass.MEASUREMENT,
381
  ),
382
  PlugwiseSensorEntityDescription(
383
+ key="dhw_temperature",
384
+ translation_key="dhw_temperature",
385
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
386
  device_class=SensorDeviceClass.TEMPERATURE,
387
  entity_category=EntityCategory.DIAGNOSTIC,
388
  state_class=SensorStateClass.MEASUREMENT,
389
  ),
390
  PlugwiseSensorEntityDescription(
391
+ key="domestic_hot_water_setpoint",
392
+ translation_key="domestic_hot_water_setpoint",
393
  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
394
  device_class=SensorDeviceClass.TEMPERATURE,
395
  entity_category=EntityCategory.DIAGNOSTIC,
 
403
  entry: PlugwiseConfigEntry,
404
  async_add_entities: AddConfigEntryEntitiesCallback,
405
  ) -> None:
406
+ """Set up the Smile sensors from a config entry."""
 
407
  coordinator = entry.runtime_data
408
 
409
  @callback
 
412
  if not coordinator.new_devices:
413
  return
414
 
415
+ async_add_entities(
416
+ PlugwiseSensorEntity(coordinator, device_id, description)
417
+ for device_id in coordinator.new_devices
418
+ if (sensors := coordinator.data[device_id].get("sensors"))
419
+ for description in SENSORS
420
+ if description.key in sensors
421
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
  _add_entities()
424
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
 
437
  ) -> None:
438
  """Initialise the sensor."""
439
  super().__init__(coordinator, device_id)
 
440
  self._attr_unique_id = f"{device_id}-{description.key}"
441
+ self.entity_description = description
442
 
443
  @property
444
+ @override
445
+ def native_value(self) -> int | float:
446
  """Return the value reported by the sensor."""
447
+ return self.device["sensors"][self.entity_description.key]
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/strings.json RENAMED
@@ -1,39 +1,45 @@
1
  {
2
  "config": {
3
  "abort": {
4
- "already_configured": "This device is already configured",
5
  "anna_with_adam": "Both Anna and Adam detected. Add your Adam instead of your Anna",
6
- "not_the_same_smile": "The configured Smile ID does not match the Smile ID on the requested IP address.",
7
- "reconfigure_successful": "Reconfiguration successful"
8
  },
9
  "error": {
10
- "cannot_connect": "Failed to connect",
11
- "invalid_auth": "Authentication failed",
12
  "invalid_setup": "Add your Adam instead of your Anna, see the documentation",
13
- "network_down": "Plugwise Zigbee network is down",
14
- "network_timeout": "Network communication timeout",
15
- "response_error": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch",
16
- "stick_init": "Initialization of Plugwise USB-stick failed",
17
- "unknown": "Unknown error!",
18
  "unsupported": "Device with unsupported firmware"
19
  },
20
  "step": {
21
  "reconfigure": {
22
  "data": {
23
- "host": "IP-address",
24
- "port": "Port number"
 
 
 
 
25
  },
26
  "description": "Update configuration for {title}."
27
  },
28
  "user": {
29
  "data": {
30
- "host": "IP-address",
31
- "password": "ID",
32
- "port": "Port number",
33
- "username": "Username"
 
 
 
 
 
 
34
  },
35
- "description": "Enter your Plugwise device: (setup can take up to 90s)",
36
- "title": "Set up Plugwise Adam/Smile/Stretch"
37
  }
38
  }
39
  },
@@ -46,7 +52,7 @@
46
  "name": "Cooling enabled"
47
  },
48
  "cooling_state": {
49
- "name": "Cooling"
50
  },
51
  "dhw_state": {
52
  "name": "DHW state"
@@ -55,7 +61,7 @@
55
  "name": "Flame state"
56
  },
57
  "heating_state": {
58
- "name": "Heating"
59
  },
60
  "plugwise_notification": {
61
  "name": "Plugwise notification"
@@ -72,14 +78,20 @@
72
  "climate": {
73
  "plugwise": {
74
  "state_attributes": {
 
 
 
75
  "preset_mode": {
76
  "state": {
77
  "asleep": "Night",
78
- "away": "Away",
79
- "home": "Home",
80
  "no_frost": "Anti-frost",
81
  "vacation": "Vacation"
82
  }
 
 
 
83
  }
84
  }
85
  }
@@ -99,17 +111,18 @@
99
  "select_dhw_mode": {
100
  "name": "DHW mode",
101
  "state": {
102
- "auto": "Auto",
103
  "boost": "Boost",
104
  "comfort": "Comfort",
105
- "off": "Off"
 
106
  }
107
  },
108
  "select_gateway_mode": {
109
  "name": "Gateway mode",
110
  "state": {
111
  "away": "Pause",
112
- "full": "Normal",
113
  "vacation": "Vacation"
114
  }
115
  },
@@ -118,22 +131,22 @@
118
  "state": {
119
  "bleeding_cold": "Bleeding cold",
120
  "bleeding_hot": "Bleeding hot",
121
- "cooling": "Cooling",
122
- "heating": "Heating",
123
- "off": "Off"
124
  }
125
  },
126
  "select_schedule": {
127
  "name": "Thermostat schedule",
128
  "state": {
129
- "off": "Off"
130
  }
131
  },
132
  "select_zone_profile": {
133
  "name": "Zone profile",
134
  "state": {
135
- "active": "Active",
136
- "off": "Off",
137
  "passive": "Passive"
138
  }
139
  }
@@ -233,7 +246,7 @@
233
  "name": "Intended boiler temperature"
234
  },
235
  "maximum_boiler_temperature": {
236
- "name": "Maximum boiler temperature setpoint"
237
  },
238
  "modulation_level": {
239
  "name": "Modulation level"
@@ -280,22 +293,27 @@
280
  },
281
  "switch": {
282
  "cooling_ena_switch": {
283
- "name": "Cooling"
284
  },
285
  "dhw_cm_switch": {
286
  "name": "DHW comfort mode"
287
  },
288
  "lock": {
289
- "name": "Lock"
290
  },
291
  "relay": {
292
  "name": "Relay"
293
  }
 
 
 
 
 
294
  }
295
  },
296
  "exceptions": {
297
  "authentication_failed": {
298
- "message": "Invalid authentication"
299
  },
300
  "data_incomplete_or_missing": {
301
  "message": "Data incomplete or missing."
@@ -304,42 +322,22 @@
304
  "message": "Error communicating with API: {error}."
305
  },
306
  "failed_to_connect": {
307
- "message": "Failed to connect"
308
  },
309
  "invalid_setup": {
310
  "message": "Add your Adam instead of your Anna, see the documentation"
311
  },
312
  "response_error": {
313
- "message": "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch"
314
  },
315
  "set_schedule_first": {
316
  "message": "Failed setting HVACMode, set a schedule first."
317
  },
 
 
 
318
  "unsupported_firmware": {
319
- "message": "Device with unsupported firmware"
320
- }
321
- },
322
- "options": {
323
- "step": {
324
- "init": {
325
- "data": {
326
- "cooling_on": "Anna: cooling-mode is on",
327
- "homekit_emulation": "Homekit emulation (i.e. on hvac_off => Away) *) beta-only option",
328
- "refresh_interval": "Frontend refresh-time (1.5 - 5 seconds) *) beta-only option",
329
- "scan_interval": "Scan Interval (seconds) *) beta-only option"
330
- },
331
- "description": "Adjust Smile/Stretch Options"
332
- },
333
- "none": {
334
- "description": "This Integration does not provide any Options",
335
- "title": "No Options available"
336
- }
337
- }
338
- },
339
- "services": {
340
- "delete_notification": {
341
- "description": "Deletes a Plugwise Notification",
342
- "name": "Delete Plugwise notification"
343
  }
344
  }
345
  }
 
1
  {
2
  "config": {
3
  "abort": {
4
+ "already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
5
  "anna_with_adam": "Both Anna and Adam detected. Add your Adam instead of your Anna",
6
+ "not_the_same_smile": "The configured Smile ID does not match the Smile ID on the requested IP address."
 
7
  },
8
  "error": {
9
+ "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
10
+ "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
11
  "invalid_setup": "Add your Adam instead of your Anna, see the documentation",
12
+ "response_error": "Invalid XML data, or error indication received",
13
+ "unknown": "[%key:common::config_flow::error::unknown%]",
 
 
 
14
  "unsupported": "Device with unsupported firmware"
15
  },
16
  "step": {
17
  "reconfigure": {
18
  "data": {
19
+ "host": "[%key:common::config_flow::data::ip%]",
20
+ "port": "[%key:common::config_flow::data::port%]"
21
+ },
22
+ "data_description": {
23
+ "host": "[%key:component::plugwise::config::step::user::data_description::host%]",
24
+ "port": "[%key:component::plugwise::config::step::user::data_description::port%]"
25
  },
26
  "description": "Update configuration for {title}."
27
  },
28
  "user": {
29
  "data": {
30
+ "host": "[%key:common::config_flow::data::ip%]",
31
+ "password": "Smile ID",
32
+ "port": "[%key:common::config_flow::data::port%]",
33
+ "username": "Smile username"
34
+ },
35
+ "data_description": {
36
+ "host": "The hostname or IP address of your Smile. You can find it in your router or the Plugwise app.",
37
+ "password": "The Smile ID printed on the label on the back of your Adam, Smile-T, or P1.",
38
+ "port": "By default your Smile uses port 80, normally you should not have to change this.",
39
+ "username": "Default is `smile`, or `stretch` for the legacy Stretch."
40
  },
41
+ "description": "Please enter",
42
+ "title": "Connect to the Smile"
43
  }
44
  }
45
  },
 
52
  "name": "Cooling enabled"
53
  },
54
  "cooling_state": {
55
+ "name": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::cooling%]"
56
  },
57
  "dhw_state": {
58
  "name": "DHW state"
 
61
  "name": "Flame state"
62
  },
63
  "heating_state": {
64
+ "name": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::heating%]"
65
  },
66
  "plugwise_notification": {
67
  "name": "Plugwise notification"
 
78
  "climate": {
79
  "plugwise": {
80
  "state_attributes": {
81
+ "available_schemas": {
82
+ "name": "Available schemas"
83
+ },
84
  "preset_mode": {
85
  "state": {
86
  "asleep": "Night",
87
+ "away": "[%key:common::state::not_home%]",
88
+ "home": "[%key:common::state::home%]",
89
  "no_frost": "Anti-frost",
90
  "vacation": "Vacation"
91
  }
92
+ },
93
+ "selected_schema": {
94
+ "name": "Selected schema"
95
  }
96
  }
97
  }
 
111
  "select_dhw_mode": {
112
  "name": "DHW mode",
113
  "state": {
114
+ "auto": "[%key:common::state::auto%]",
115
  "boost": "Boost",
116
  "comfort": "Comfort",
117
+ "eco": "Eco",
118
+ "off": "[%key:common::state::off%]"
119
  }
120
  },
121
  "select_gateway_mode": {
122
  "name": "Gateway mode",
123
  "state": {
124
  "away": "Pause",
125
+ "full": "[%key:common::state::normal%]",
126
  "vacation": "Vacation"
127
  }
128
  },
 
131
  "state": {
132
  "bleeding_cold": "Bleeding cold",
133
  "bleeding_hot": "Bleeding hot",
134
+ "cooling": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::cooling%]",
135
+ "heating": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::heating%]",
136
+ "off": "[%key:common::state::off%]"
137
  }
138
  },
139
  "select_schedule": {
140
  "name": "Thermostat schedule",
141
  "state": {
142
+ "off": "[%key:common::state::off%]"
143
  }
144
  },
145
  "select_zone_profile": {
146
  "name": "Zone profile",
147
  "state": {
148
+ "active": "[%key:common::state::active%]",
149
+ "off": "[%key:common::state::off%]",
150
  "passive": "Passive"
151
  }
152
  }
 
246
  "name": "Intended boiler temperature"
247
  },
248
  "maximum_boiler_temperature": {
249
+ "name": "Maximum boiler temperature"
250
  },
251
  "modulation_level": {
252
  "name": "Modulation level"
 
293
  },
294
  "switch": {
295
  "cooling_ena_switch": {
296
+ "name": "[%key:component::climate::entity_component::_::state_attributes::hvac_action::state::cooling%]"
297
  },
298
  "dhw_cm_switch": {
299
  "name": "DHW comfort mode"
300
  },
301
  "lock": {
302
+ "name": "[%key:component::lock::title%]"
303
  },
304
  "relay": {
305
  "name": "Relay"
306
  }
307
+ },
308
+ "water_heater": {
309
+ "dhw_temperature": {
310
+ "name": "Domestic hot water"
311
+ }
312
  }
313
  },
314
  "exceptions": {
315
  "authentication_failed": {
316
+ "message": "[%key:common::config_flow::error::invalid_auth%]"
317
  },
318
  "data_incomplete_or_missing": {
319
  "message": "Data incomplete or missing."
 
322
  "message": "Error communicating with API: {error}."
323
  },
324
  "failed_to_connect": {
325
+ "message": "[%key:common::config_flow::error::cannot_connect%]"
326
  },
327
  "invalid_setup": {
328
  "message": "Add your Adam instead of your Anna, see the documentation"
329
  },
330
  "response_error": {
331
+ "message": "[%key:component::plugwise::config::error::response_error%]"
332
  },
333
  "set_schedule_first": {
334
  "message": "Failed setting HVACMode, set a schedule first."
335
  },
336
+ "temperature_out_of_range": {
337
+ "message": "Temperature must be between {min_temp} and {max_temp} {temperature_unit}."
338
+ },
339
  "unsupported_firmware": {
340
+ "message": "[%key:component::plugwise::config::error::unsupported%]"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  }
342
  }
343
  }
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/switch.py RENAMED
@@ -1,9 +1,7 @@
1
  """Plugwise Switch component for HomeAssistant."""
2
 
3
- from __future__ import annotations
4
-
5
  from dataclasses import dataclass
6
- from typing import Any
7
 
8
  from plugwise.constants import SwitchType
9
 
@@ -16,17 +14,6 @@
16
  from homeassistant.core import HomeAssistant, callback
17
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
18
 
19
- from .const import (
20
- COOLING_ENA_SWITCH,
21
- DHW_CM_SWITCH,
22
- LOCK,
23
- LOGGER, # pw-beta
24
- MEMBERS,
25
- RELAY,
26
- SWITCHES,
27
- )
28
-
29
- # Upstream consts
30
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
31
  from .entity import PlugwiseEntity
32
  from .util import plugwise_command
@@ -41,29 +28,25 @@
41
  key: SwitchType
42
 
43
 
44
- # Upstream consts
45
- PLUGWISE_SWITCHES: tuple[PlugwiseSwitchEntityDescription, ...] = (
46
  PlugwiseSwitchEntityDescription(
47
- key=DHW_CM_SWITCH,
48
- translation_key=DHW_CM_SWITCH,
49
- device_class=SwitchDeviceClass.SWITCH,
50
  entity_category=EntityCategory.CONFIG,
51
  ),
52
  PlugwiseSwitchEntityDescription(
53
- key=LOCK,
54
- translation_key=LOCK,
55
- device_class=SwitchDeviceClass.SWITCH,
56
  entity_category=EntityCategory.CONFIG,
57
  ),
58
  PlugwiseSwitchEntityDescription(
59
- key=RELAY,
60
- translation_key=RELAY,
61
  device_class=SwitchDeviceClass.SWITCH,
62
  ),
63
  PlugwiseSwitchEntityDescription(
64
- key=COOLING_ENA_SWITCH,
65
- translation_key=COOLING_ENA_SWITCH,
66
- device_class=SwitchDeviceClass.SWITCH,
67
  entity_category=EntityCategory.CONFIG,
68
  ),
69
  )
@@ -74,7 +57,7 @@
74
  entry: PlugwiseConfigEntry,
75
  async_add_entities: AddConfigEntryEntitiesCallback,
76
  ) -> None:
77
- """Set up Plugwise switches from a config entry."""
78
  coordinator = entry.runtime_data
79
 
80
  @callback
@@ -83,28 +66,13 @@
83
  if not coordinator.new_devices:
84
  return
85
 
86
- # Upstream consts
87
- # async_add_entities(
88
- # PlugwiseSwitchEntity(coordinator, device_id, description)
89
- # for device_id in coordinator.new_devices
90
- # if (switches := coordinator.data.devices[device_id].get(SWITCHES))
91
- # for description in PLUGWISE_SWITCHES
92
- # if description.key in switches
93
- # )
94
- # pw-beta alternative for debugging
95
- entities: list[PlugwiseSwitchEntity] = []
96
- for device_id in coordinator.new_devices:
97
- device = coordinator.data[device_id]
98
- if not (switches := device.get(SWITCHES)):
99
- continue
100
- for description in PLUGWISE_SWITCHES:
101
- if description.key not in switches:
102
- continue
103
- entities.append(PlugwiseSwitchEntity(coordinator, device_id, description))
104
- LOGGER.debug(
105
- "Add %s %s switch", device["name"], description.translation_key
106
- )
107
- async_add_entities(entities)
108
 
109
  _add_entities()
110
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
@@ -123,30 +91,33 @@
123
  ) -> None:
124
  """Set up the Plugwise API."""
125
  super().__init__(coordinator, device_id)
126
- self.entity_description = description
127
  self._attr_unique_id = f"{device_id}-{description.key}"
 
128
 
129
  @property
130
- def is_on(self) -> bool | None:
 
131
  """Return True if entity is on."""
132
- return self.device.get(SWITCHES, {}).get(self.entity_description.key) # Upstream const
133
 
134
  @plugwise_command
 
135
  async def async_turn_on(self, **kwargs: Any) -> None:
136
  """Turn the device on."""
137
  await self.coordinator.api.set_switch_state(
138
  self._dev_id,
139
- self.device.get(MEMBERS),
140
  self.entity_description.key,
141
  "on",
142
- ) # Upstream const
143
 
144
  @plugwise_command
 
145
  async def async_turn_off(self, **kwargs: Any) -> None:
146
  """Turn the device off."""
147
  await self.coordinator.api.set_switch_state(
148
  self._dev_id,
149
- self.device.get(MEMBERS),
150
  self.entity_description.key,
151
  "off",
152
- ) # Upstream const
 
1
  """Plugwise Switch component for HomeAssistant."""
2
 
 
 
3
  from dataclasses import dataclass
4
+ from typing import Any, override
5
 
6
  from plugwise.constants import SwitchType
7
 
 
14
  from homeassistant.core import HomeAssistant, callback
15
  from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
16
 
 
 
 
 
 
 
 
 
 
 
 
17
  from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
18
  from .entity import PlugwiseEntity
19
  from .util import plugwise_command
 
28
  key: SwitchType
29
 
30
 
31
+ SWITCHES: tuple[PlugwiseSwitchEntityDescription, ...] = (
 
32
  PlugwiseSwitchEntityDescription(
33
+ key="dhw_cm_switch",
34
+ translation_key="dhw_cm_switch",
 
35
  entity_category=EntityCategory.CONFIG,
36
  ),
37
  PlugwiseSwitchEntityDescription(
38
+ key="lock",
39
+ translation_key="lock",
 
40
  entity_category=EntityCategory.CONFIG,
41
  ),
42
  PlugwiseSwitchEntityDescription(
43
+ key="relay",
44
+ translation_key="relay",
45
  device_class=SwitchDeviceClass.SWITCH,
46
  ),
47
  PlugwiseSwitchEntityDescription(
48
+ key="cooling_ena_switch",
49
+ translation_key="cooling_ena_switch",
 
50
  entity_category=EntityCategory.CONFIG,
51
  ),
52
  )
 
57
  entry: PlugwiseConfigEntry,
58
  async_add_entities: AddConfigEntryEntitiesCallback,
59
  ) -> None:
60
+ """Set up the Smile switches from a config entry."""
61
  coordinator = entry.runtime_data
62
 
63
  @callback
 
66
  if not coordinator.new_devices:
67
  return
68
 
69
+ async_add_entities(
70
+ PlugwiseSwitchEntity(coordinator, device_id, description)
71
+ for device_id in coordinator.new_devices
72
+ if (switches := coordinator.data[device_id].get("switches"))
73
+ for description in SWITCHES
74
+ if description.key in switches
75
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  _add_entities()
78
  entry.async_on_unload(coordinator.async_add_listener(_add_entities))
 
91
  ) -> None:
92
  """Set up the Plugwise API."""
93
  super().__init__(coordinator, device_id)
 
94
  self._attr_unique_id = f"{device_id}-{description.key}"
95
+ self.entity_description = description
96
 
97
  @property
98
+ @override
99
+ def is_on(self) -> bool:
100
  """Return True if entity is on."""
101
+ return self.device["switches"][self.entity_description.key]
102
 
103
  @plugwise_command
104
+ @override
105
  async def async_turn_on(self, **kwargs: Any) -> None:
106
  """Turn the device on."""
107
  await self.coordinator.api.set_switch_state(
108
  self._dev_id,
109
+ self.device.get("members"),
110
  self.entity_description.key,
111
  "on",
112
+ )
113
 
114
  @plugwise_command
115
+ @override
116
  async def async_turn_off(self, **kwargs: Any) -> None:
117
  """Turn the device off."""
118
  await self.coordinator.api.set_switch_state(
119
  self._dev_id,
120
+ self.device.get("members"),
121
  self.entity_description.key,
122
  "off",
123
+ )
/home/runner/work/progress/progress/clones/beta/{beta/custom_components → ha-core/homeassistant/components}/plugwise/util.py RENAMED
@@ -1,7 +1,5 @@
1
  """Utilities for Plugwise."""
2
 
3
- from __future__ import annotations
4
-
5
  from collections.abc import Awaitable, Callable, Coroutine
6
  from typing import Any, Concatenate
7
 
@@ -12,15 +10,10 @@
12
  from .const import DOMAIN
13
  from .entity import PlugwiseEntity
14
 
15
- # For reference:
16
- # PlugwiseEntityT = TypeVar("PlugwiseEntityT", bound=PlugwiseEntity)
17
- # R = TypeVar("_R")
18
- # P = ParamSpec("_P")
19
-
20
 
21
- def plugwise_command[PlugwiseEntityT: PlugwiseEntity, **P, R](
22
- func: Callable[Concatenate[PlugwiseEntityT, P], Awaitable[R]],
23
- ) -> Callable[Concatenate[PlugwiseEntityT, P], Coroutine[Any, Any, R]]:
24
  """Decorate Plugwise calls that send commands/make changes to the device.
25
 
26
  A decorator that wraps the passed in function, catches Plugwise errors,
@@ -28,8 +21,8 @@
28
  """
29
 
30
  async def handler(
31
- self: PlugwiseEntityT, *args: P.args, **kwargs: P.kwargs
32
- ) -> R:
33
  try:
34
  return await func(self, *args, **kwargs)
35
  except PlugwiseException as err:
 
1
  """Utilities for Plugwise."""
2
 
 
 
3
  from collections.abc import Awaitable, Callable, Coroutine
4
  from typing import Any, Concatenate
5
 
 
10
  from .const import DOMAIN
11
  from .entity import PlugwiseEntity
12
 
 
 
 
 
 
13
 
14
+ def plugwise_command[_PlugwiseEntityT: PlugwiseEntity, **_P, _R](
15
+ func: Callable[Concatenate[_PlugwiseEntityT, _P], Awaitable[_R]],
16
+ ) -> Callable[Concatenate[_PlugwiseEntityT, _P], Coroutine[Any, Any, _R]]:
17
  """Decorate Plugwise calls that send commands/make changes to the device.
18
 
19
  A decorator that wraps the passed in function, catches Plugwise errors,
 
21
  """
22
 
23
  async def handler(
24
+ self: _PlugwiseEntityT, *args: _P.args, **kwargs: _P.kwargs
25
+ ) -> _R:
26
  try:
27
  return await func(self, *args, **kwargs)
28
  except PlugwiseException as err: