From 684c0bb08cd349cd2739b55f4e40144ee4d47e94 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:05:39 +0200 Subject: [PATCH 01/22] Implement entry.runtime_data - 1 2 3 4 5 6 7 8 9 --- custom_components/plugwise/__init__.py | 18 ++++++++---------- custom_components/plugwise/binary_sensor.py | 8 +++++--- custom_components/plugwise/button.py | 9 +++++---- custom_components/plugwise/climate.py | 8 +++++--- custom_components/plugwise/diagnostics.py | 8 +++----- custom_components/plugwise/number.py | 8 +++++--- custom_components/plugwise/select.py | 8 +++++--- custom_components/plugwise/sensor.py | 8 +++++--- custom_components/plugwise/switch.py | 6 ++++-- 9 files changed, 45 insertions(+), 36 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 878cd9960..8c219826e 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -22,8 +22,10 @@ ) from .coordinator import PlugwiseDataUpdateCoordinator +type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator] -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + +async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Set up the Plugwise Device from a config entry.""" await er.async_migrate_entries(hass, entry.entry_id, async_migrate_entity_entry) @@ -43,10 +45,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: undo_listener = entry.add_update_listener(_update_listener) # pw-beta - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = { - COORDINATOR: coordinator, # pw-beta - UNDO_UPDATE_LISTENER: undo_listener, # pw-beta - } + entry.runtime_data[COORDINATOR] = coordinator # pw-beta + entry.runtime_data[UNDO_UPDATE_LISTENER] = undo_listener # pw-beta device_registry = dr.async_get(hass) device_registry.async_get_or_create( @@ -86,16 +86,14 @@ async def delete_notification( return True async def _update_listener( - hass: HomeAssistant, entry: ConfigEntry + hass: HomeAssistant, entry: PlugwiseConfigEntry ) -> None: # pragma: no cover # pw-beta """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" - if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): - hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) @callback def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None: diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index e1b772f5a..863ed52a4 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -16,11 +16,13 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( BINARY_SENSORS, COMPRESSOR_STATE, COOLING_ENABLED, COOLING_STATE, + COORDINATOR, DHW_STATE, DOMAIN, FLAME_STATE, @@ -32,7 +34,7 @@ SEVERITIES, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity PARALLEL_UPDATES = 0 @@ -90,11 +92,11 @@ class PlugwiseBinarySensorEntityDescription(BinarySensorEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise binary_sensors from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/button.py b/custom_components/plugwise/button.py index 8da6939c3..9580deb35 100644 --- a/custom_components/plugwise/button.py +++ b/custom_components/plugwise/button.py @@ -11,9 +11,10 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import GATEWAY_ID, LOGGER, REBOOT +from . import PlugwiseConfigEntry +from .const import COORDINATOR, GATEWAY_ID, LOGGER, REBOOT from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity from .util import plugwise_command BUTTON_TYPES: tuple[ButtonEntityDescription, ...] = ( @@ -28,11 +29,11 @@ async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise buttons from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/climate.py b/custom_components/plugwise/climate.py index b246156fb..e0b228123 100644 --- a/custom_components/plugwise/climate.py +++ b/custom_components/plugwise/climate.py @@ -20,6 +20,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( ACTIVE_PRESET, AVAILABLE_SCHEDULES, @@ -28,6 +29,7 @@ CONTROL_STATE, COOLING_PRESENT, COOLING_STATE, + COORDINATOR, DEV_CLASS, DOMAIN, GATEWAY_ID, @@ -48,17 +50,17 @@ UPPER_BOUND, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity from .util import plugwise_command async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile Thermostats from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] homekit_enabled: bool = entry.options.get( CONF_HOMEKIT_EMULATION, False ) # pw-beta homekit emulation diff --git a/custom_components/plugwise/diagnostics.py b/custom_components/plugwise/diagnostics.py index a09ecc398..563453759 100644 --- a/custom_components/plugwise/diagnostics.py +++ b/custom_components/plugwise/diagnostics.py @@ -10,16 +10,14 @@ COORDINATOR, # pw-beta DOMAIN, ) -from .coordinator import PlugwiseDataUpdateCoordinator +from . import PlugwiseConfigEntry async def async_get_config_entry_diagnostics( - hass: HomeAssistant, entry: ConfigEntry + hass: HomeAssistant, entry: PlugwiseConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - coordinator: PlugwiseDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][ - COORDINATOR - ] + coordinator = entry.runtime_data[COORDINATOR] return { "gateway": coordinator.data.gateway, "devices": coordinator.data.devices, diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index 835f943b0..cfb0b22f4 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -14,7 +14,9 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( + COORDINATOR, LOGGER, LOWER_BOUND, MAX_BOILER_TEMP, @@ -25,7 +27,7 @@ NumberType, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity from .util import plugwise_command @@ -63,11 +65,11 @@ class PlugwiseNumberEntityDescription(NumberEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise numbers from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index 7c11debcc..80e2ec4a6 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -9,8 +9,10 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( AVAILABLE_SCHEDULES, + COORDINATOR, DHW_MODE, DHW_MODES, GATEWAY_MODE, @@ -27,7 +29,7 @@ SelectType, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity from .util import plugwise_command PARALLEL_UPDATES = 0 @@ -70,11 +72,11 @@ class PlugwiseSelectEntityDescription(SelectEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile selector from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index b181e3109..ba31ce840 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -29,7 +29,9 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( + COORDINATOR, DHW_SETPOINT, DHW_TEMP, EL_CONS_INTERVAL, @@ -79,7 +81,7 @@ WATER_TEMP, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity PARALLEL_UPDATES = 0 @@ -455,11 +457,11 @@ class PlugwiseSensorEntityDescription(SensorEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile sensors from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index 8f13d15c2..af7c209ac 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -16,8 +16,10 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import PlugwiseConfigEntry from .const import ( COOLING_ENA_SWITCH, + COORDINATOR, DHW_CM_SWITCH, LOCK, LOGGER, @@ -66,11 +68,11 @@ class PlugwiseSwitchEntityDescription(SwitchEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: PlugwiseConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile switches from a ConfigEntry.""" - coordinator = get_coordinator(hass, entry.entry_id) + coordinator = entry.runtime_data[COORDINATOR] @callback def _add_entities() -> None: From 335eec7efc0b41d4ec98560d74604ac5176b12ac Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:06:14 +0200 Subject: [PATCH 02/22] Remove get_coordinator() function --- custom_components/plugwise/entity.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/custom_components/plugwise/entity.py b/custom_components/plugwise/entity.py index 26c809d15..69c52c486 100644 --- a/custom_components/plugwise/entity.py +++ b/custom_components/plugwise/entity.py @@ -28,17 +28,6 @@ from .coordinator import PlugwiseDataUpdateCoordinator -def get_coordinator( - hass: HomeAssistant, config_entry_id: str -) -> PlugwiseDataUpdateCoordinator: - """Get coordinator for given config entry id.""" - coordinator: PlugwiseDataUpdateCoordinator = hass.data[DOMAIN][config_entry_id][ - COORDINATOR - ] - - return coordinator - - class PlugwiseEntity(CoordinatorEntity[PlugwiseDataUpdateCoordinator]): """Represent a PlugWise Entity.""" From f67d689abc98fe666e15810cd39d4fb88f21bfec Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:16:01 +0200 Subject: [PATCH 03/22] Try --- custom_components/plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 8c219826e..32ed385db 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -86,7 +86,7 @@ async def delete_notification( return True async def _update_listener( - hass: HomeAssistant, entry: PlugwiseConfigEntry + hass: HomeAssistant, entry: ConfigEntry ) -> None: # pragma: no cover # pw-beta """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) From 9a5192369ec264e884602b6fe8a5a4157ff4047a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:37:56 +0200 Subject: [PATCH 04/22] Try 2 --- custom_components/plugwise/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 32ed385db..70662c4db 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -43,10 +43,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> # Migrate a changed sensor unique_id migrate_sensor_entities(hass, coordinator) - undo_listener = entry.add_update_listener(_update_listener) # pw-beta - - entry.runtime_data[COORDINATOR] = coordinator # pw-beta - entry.runtime_data[UNDO_UPDATE_LISTENER] = undo_listener # pw-beta + entry.runtime_data = coordinator # pw-beta + entry.async_on_unload( + entry.add_update_listener(async_options_updated) # pw-beta + ) device_registry = dr.async_get(hass) device_registry.async_get_or_create( @@ -85,16 +85,19 @@ async def delete_notification( return True -async def _update_listener( - hass: HomeAssistant, entry: ConfigEntry -) -> None: # pragma: no cover # pw-beta - """Handle options update.""" - await hass.config_entries.async_reload(entry.entry_id) - async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) +async def async_options_updated( + hass: HomeAssistant, entry: PlugwiseConfigEntry +) -> None: + """Triggered by config entry options updates.""" + coordinator = entry.runtime_data + if coordinator.event_unsub: + coordinator.event_unsub() + await coordinator.async_request_refresh() + @callback def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None: """Migrate Plugwise entity entries. From d5c145226206bf6cc6e8e62f7a13e100bb98af26 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:44:20 +0200 Subject: [PATCH 05/22] Clean-up --- custom_components/plugwise/__init__.py | 2 -- custom_components/plugwise/binary_sensor.py | 3 +-- custom_components/plugwise/button.py | 4 ++-- custom_components/plugwise/climate.py | 3 +-- custom_components/plugwise/diagnostics.py | 7 ++----- custom_components/plugwise/number.py | 3 +-- custom_components/plugwise/select.py | 3 +-- custom_components/plugwise/sensor.py | 3 +-- custom_components/plugwise/switch.py | 5 ++--- 9 files changed, 11 insertions(+), 22 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 70662c4db..1c2e5d273 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -13,12 +13,10 @@ from .const import ( CONF_REFRESH_INTERVAL, # pw-beta options - COORDINATOR, DOMAIN, LOGGER, PLATFORMS, SERVICE_DELETE, - UNDO_UPDATE_LISTENER, ) from .coordinator import PlugwiseDataUpdateCoordinator diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index 863ed52a4..088aae5cc 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -22,7 +22,6 @@ COMPRESSOR_STATE, COOLING_ENABLED, COOLING_STATE, - COORDINATOR, DHW_STATE, DOMAIN, FLAME_STATE, @@ -96,7 +95,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise binary_sensors from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/button.py b/custom_components/plugwise/button.py index 9580deb35..38e81f01e 100644 --- a/custom_components/plugwise/button.py +++ b/custom_components/plugwise/button.py @@ -12,7 +12,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import PlugwiseConfigEntry -from .const import COORDINATOR, GATEWAY_ID, LOGGER, REBOOT +from .const import GATEWAY_ID, LOGGER, REBOOT from .coordinator import PlugwiseDataUpdateCoordinator from .entity import PlugwiseEntity from .util import plugwise_command @@ -33,7 +33,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise buttons from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/climate.py b/custom_components/plugwise/climate.py index e0b228123..098631471 100644 --- a/custom_components/plugwise/climate.py +++ b/custom_components/plugwise/climate.py @@ -29,7 +29,6 @@ CONTROL_STATE, COOLING_PRESENT, COOLING_STATE, - COORDINATOR, DEV_CLASS, DOMAIN, GATEWAY_ID, @@ -60,7 +59,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile Thermostats from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data homekit_enabled: bool = entry.options.get( CONF_HOMEKIT_EMULATION, False ) # pw-beta homekit emulation diff --git a/custom_components/plugwise/diagnostics.py b/custom_components/plugwise/diagnostics.py index 563453759..cf4f578ec 100644 --- a/custom_components/plugwise/diagnostics.py +++ b/custom_components/plugwise/diagnostics.py @@ -6,10 +6,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from .const import ( - COORDINATOR, # pw-beta - DOMAIN, -) +from .const import DOMAIN from . import PlugwiseConfigEntry @@ -17,7 +14,7 @@ async def async_get_config_entry_diagnostics( hass: HomeAssistant, entry: PlugwiseConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data return { "gateway": coordinator.data.gateway, "devices": coordinator.data.devices, diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index cfb0b22f4..fc16cad51 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -16,7 +16,6 @@ from . import PlugwiseConfigEntry from .const import ( - COORDINATOR, LOGGER, LOWER_BOUND, MAX_BOILER_TEMP, @@ -69,7 +68,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Plugwise numbers from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index 80e2ec4a6..c2e937a9c 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -12,7 +12,6 @@ from . import PlugwiseConfigEntry from .const import ( AVAILABLE_SCHEDULES, - COORDINATOR, DHW_MODE, DHW_MODES, GATEWAY_MODE, @@ -76,7 +75,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile selector from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index ba31ce840..59b923282 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -31,7 +31,6 @@ from . import PlugwiseConfigEntry from .const import ( - COORDINATOR, DHW_SETPOINT, DHW_TEMP, EL_CONS_INTERVAL, @@ -461,7 +460,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile sensors from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index af7c209ac..37a208372 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -19,7 +19,6 @@ from . import PlugwiseConfigEntry from .const import ( COOLING_ENA_SWITCH, - COORDINATOR, DHW_CM_SWITCH, LOCK, LOGGER, @@ -28,7 +27,7 @@ SWITCHES, ) from .coordinator import PlugwiseDataUpdateCoordinator -from .entity import PlugwiseEntity, get_coordinator +from .entity import PlugwiseEntity from .util import plugwise_command @@ -72,7 +71,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Smile switches from a ConfigEntry.""" - coordinator = entry.runtime_data[COORDINATOR] + coordinator = entry.runtime_data @callback def _add_entities() -> None: From aee5bed0169cf3c4afa9f8411965236db40f65bf Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 15:59:53 +0200 Subject: [PATCH 06/22] Revert update_listener changes --- custom_components/plugwise/__init__.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 1c2e5d273..2b1aef237 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -17,6 +17,7 @@ LOGGER, PLATFORMS, SERVICE_DELETE, + UNDO_UPDATE_LISTENER, ) from .coordinator import PlugwiseDataUpdateCoordinator @@ -42,9 +43,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> migrate_sensor_entities(hass, coordinator) entry.runtime_data = coordinator # pw-beta - entry.async_on_unload( - entry.add_update_listener(async_options_updated) # pw-beta - ) + + undo_listener = entry.add_update_listener(_update_listener) # pw-beta + + hass.data.setdefault(DOMAIN, {})[entry.entry_id] = { + UNDO_UPDATE_LISTENER: undo_listener, # pw-beta + } device_registry = dr.async_get(hass) device_registry.async_get_or_create( @@ -83,19 +87,16 @@ async def delete_notification( return True +async def _update_listener( + hass: HomeAssistant, entry: ConfigEntry +) -> None: # pragma: no cover # pw-beta + """Handle options update.""" + await hass.config_entries.async_reload(entry.entry_id) + async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) -async def async_options_updated( - hass: HomeAssistant, entry: PlugwiseConfigEntry -) -> None: - """Triggered by config entry options updates.""" - coordinator = entry.runtime_data - if coordinator.event_unsub: - coordinator.event_unsub() - await coordinator.async_request_refresh() - @callback def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None: """Migrate Plugwise entity entries. From 0c98695326b8f8e145ea9cb66d4fc62d22012fa8 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 16:02:15 +0200 Subject: [PATCH 07/22] Try --- custom_components/plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 2b1aef237..39adf15f0 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -93,7 +93,7 @@ async def _update_listener( """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) -async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) From 863bf02839fec8ae05d19d4723c968e597290d08 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 16:03:40 +0200 Subject: [PATCH 08/22] Try 2 --- custom_components/plugwise/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 39adf15f0..0a4709c0a 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -88,12 +88,12 @@ async def delete_notification( return True async def _update_listener( - hass: HomeAssistant, entry: ConfigEntry + hass: HomeAssistant, entry: PlugwiseConfigEntry ) -> None: # pragma: no cover # pw-beta """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) From 4d8f9238211f85212fd513b1561b745f634c2490 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 16:06:20 +0200 Subject: [PATCH 09/22] Revert async_unload_entry() changes --- custom_components/plugwise/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 0a4709c0a..50fdb2198 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -95,7 +95,9 @@ async def _update_listener( async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" - return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): + hass.data[DOMAIN].pop(entry.entry_id) + return unload_ok @callback def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None: From c83b9934e38ea90415bd6d3fc4ed262a9bc85a9a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 16:07:47 +0200 Subject: [PATCH 10/22] Clean-up by ruff --- custom_components/plugwise/binary_sensor.py | 1 - custom_components/plugwise/button.py | 1 - custom_components/plugwise/climate.py | 1 - custom_components/plugwise/diagnostics.py | 2 -- custom_components/plugwise/entity.py | 2 -- custom_components/plugwise/number.py | 1 - custom_components/plugwise/select.py | 1 - custom_components/plugwise/sensor.py | 1 - custom_components/plugwise/switch.py | 1 - 9 files changed, 11 deletions(-) diff --git a/custom_components/plugwise/binary_sensor.py b/custom_components/plugwise/binary_sensor.py index 088aae5cc..dfdfac81c 100644 --- a/custom_components/plugwise/binary_sensor.py +++ b/custom_components/plugwise/binary_sensor.py @@ -11,7 +11,6 @@ BinarySensorEntity, BinarySensorEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME, EntityCategory from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback diff --git a/custom_components/plugwise/button.py b/custom_components/plugwise/button.py index 38e81f01e..9581d4fa3 100644 --- a/custom_components/plugwise/button.py +++ b/custom_components/plugwise/button.py @@ -6,7 +6,6 @@ ButtonEntity, ButtonEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME, EntityCategory from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback diff --git a/custom_components/plugwise/climate.py b/custom_components/plugwise/climate.py index 098631471..78c20c1a7 100644 --- a/custom_components/plugwise/climate.py +++ b/custom_components/plugwise/climate.py @@ -14,7 +14,6 @@ HVACAction, HVACMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, STATE_ON, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError diff --git a/custom_components/plugwise/diagnostics.py b/custom_components/plugwise/diagnostics.py index cf4f578ec..a74b4cfe0 100644 --- a/custom_components/plugwise/diagnostics.py +++ b/custom_components/plugwise/diagnostics.py @@ -3,10 +3,8 @@ from typing import Any -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant -from .const import DOMAIN from . import PlugwiseConfigEntry diff --git a/custom_components/plugwise/entity.py b/custom_components/plugwise/entity.py index 69c52c486..22b8cba65 100644 --- a/custom_components/plugwise/entity.py +++ b/custom_components/plugwise/entity.py @@ -4,7 +4,6 @@ from plugwise.constants import DeviceData from homeassistant.const import ATTR_NAME, ATTR_VIA_DEVICE, CONF_HOST -from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import ( CONNECTION_NETWORK_MAC, CONNECTION_ZIGBEE, @@ -14,7 +13,6 @@ from .const import ( AVAILABLE, - COORDINATOR, DOMAIN, FIRMWARE, GATEWAY_ID, diff --git a/custom_components/plugwise/number.py b/custom_components/plugwise/number.py index fc16cad51..3ba6878e0 100644 --- a/custom_components/plugwise/number.py +++ b/custom_components/plugwise/number.py @@ -9,7 +9,6 @@ NumberEntityDescription, NumberMode, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME, EntityCategory, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback diff --git a/custom_components/plugwise/select.py b/custom_components/plugwise/select.py index c2e937a9c..097841b5f 100644 --- a/custom_components/plugwise/select.py +++ b/custom_components/plugwise/select.py @@ -4,7 +4,6 @@ from dataclasses import dataclass from homeassistant.components.select import SelectEntity, SelectEntityDescription -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME, STATE_ON, EntityCategory from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback diff --git a/custom_components/plugwise/sensor.py b/custom_components/plugwise/sensor.py index 59b923282..eadbd7ce1 100644 --- a/custom_components/plugwise/sensor.py +++ b/custom_components/plugwise/sensor.py @@ -11,7 +11,6 @@ SensorEntityDescription, SensorStateClass, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_NAME, ATTR_TEMPERATURE, diff --git a/custom_components/plugwise/switch.py b/custom_components/plugwise/switch.py index 37a208372..a5b1e7199 100644 --- a/custom_components/plugwise/switch.py +++ b/custom_components/plugwise/switch.py @@ -11,7 +11,6 @@ SwitchEntity, SwitchEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_NAME, EntityCategory from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback From 87e0cd452873a3887c5d42c549f564a41cf63aa5 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 19 Jun 2024 16:10:09 +0200 Subject: [PATCH 11/22] Change to noqa: BLE001 --- custom_components/plugwise/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index 139254b7b..f2c3a7c10 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -140,7 +140,7 @@ async def async_step_zeroconf( CONF_PASSWORD: config_entry.data[CONF_PASSWORD], }, ) - except Exception: # pylint: disable=broad-except + except Exception: # noqa: BLE001 self._abort_if_unique_id_configured() else: self._abort_if_unique_id_configured( @@ -227,7 +227,7 @@ async def async_step_user( errors[CONF_BASE] = "response_error" except UnsupportedDeviceError: errors[CONF_BASE] = "unsupported" - except Exception: # pylint: disable=broad-except + except Exception: # noqa: BLE001 errors[CONF_BASE] = "unknown" if errors: From 511055cccbbc31b58c9147a676e2f8a561c631a8 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 08:34:25 +0200 Subject: [PATCH 12/22] Improve options-handling --- custom_components/plugwise/__init__.py | 14 +++----------- custom_components/plugwise/const.py | 1 - 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/custom_components/plugwise/__init__.py b/custom_components/plugwise/__init__.py index 50fdb2198..569e34f03 100644 --- a/custom_components/plugwise/__init__.py +++ b/custom_components/plugwise/__init__.py @@ -17,7 +17,6 @@ LOGGER, PLATFORMS, SERVICE_DELETE, - UNDO_UPDATE_LISTENER, ) from .coordinator import PlugwiseDataUpdateCoordinator @@ -44,12 +43,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> entry.runtime_data = coordinator # pw-beta - undo_listener = entry.add_update_listener(_update_listener) # pw-beta - - hass.data.setdefault(DOMAIN, {})[entry.entry_id] = { - UNDO_UPDATE_LISTENER: undo_listener, # pw-beta - } - device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, @@ -78,6 +71,7 @@ async def delete_notification( ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + entry.async_on_unload(entry.add_update_listener(update_listener)) for component in PLATFORMS: # pw-beta if component == Platform.BINARY_SENSOR: @@ -87,7 +81,7 @@ async def delete_notification( return True -async def _update_listener( +async def update_listener( hass: HomeAssistant, entry: PlugwiseConfigEntry ) -> None: # pragma: no cover # pw-beta """Handle options update.""" @@ -95,9 +89,7 @@ async def _update_listener( async def async_unload_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: """Unload a config entry.""" - if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): - hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) @callback def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None: diff --git a/custom_components/plugwise/const.py b/custom_components/plugwise/const.py index 3d7640106..246c20398 100644 --- a/custom_components/plugwise/const.py +++ b/custom_components/plugwise/const.py @@ -22,7 +22,6 @@ SMILE: Final = "smile" STRETCH: Final = "stretch" STRETCH_USERNAME: Final = "stretch" -UNDO_UPDATE_LISTENER: Final = "undo_update_listener" UNIQUE_IDS: Final = "unique_ids" ZIGBEE_MAC_ADDRESS: Final = "zigbee_mac_address" From 0e6aff186752dc0fb6271869043e112ea1030abc Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:09:47 +0200 Subject: [PATCH 13/22] Update coordinator to runtime_data --- custom_components/plugwise/config_flow.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index f2c3a7c10..f7c9f108c 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -256,13 +256,9 @@ def async_get_options_flow( # pw-beta - change the scan-interval via CONFIGURE # pw-beta - add homekit emulation via CONFIGURE # pw-beta - change the frontend refresh interval via CONFIGURE -class PlugwiseOptionsFlowHandler(config_entries.OptionsFlow): # pw-beta options +class PlugwiseOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry): # pw-beta options """Plugwise option flow.""" - def __init__(self, config_entry: ConfigEntry) -> None: # pragma: no cover - """Initialize options flow.""" - self.config_entry = config_entry - async def async_step_none( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: # pragma: no cover @@ -283,7 +279,7 @@ async def async_step_init( if user_input is not None: return self.async_create_entry(title="", data=user_input) - coordinator = self.hass.data[DOMAIN][self.config_entry.entry_id][COORDINATOR] + coordinator = self.config_entry.runtime_data interval: dt.timedelta = DEFAULT_SCAN_INTERVAL[ coordinator.api.smile_type ] # pw-beta options From a47c4a1d3d3a031716ebf116065acdd919c67ff6 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:12:21 +0200 Subject: [PATCH 14/22] Improve --- custom_components/plugwise/config_flow.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index f7c9f108c..c90ee6f61 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -22,6 +22,8 @@ ConfigEntry, ConfigFlow, ConfigFlowResult, + OptionsFlow, + OptionsFlowWithConfigEntry, ) from homeassistant.const import ( ATTR_CONFIGURATION_URL, @@ -248,7 +250,7 @@ async def async_step_user( @callback def async_get_options_flow( config_entry: ConfigEntry, - ) -> config_entries.OptionsFlow: # pw-beta options + ) -> OptionsFlow: # pw-beta options """Get the options flow for this handler.""" return PlugwiseOptionsFlowHandler(config_entry) @@ -256,7 +258,7 @@ def async_get_options_flow( # pw-beta - change the scan-interval via CONFIGURE # pw-beta - add homekit emulation via CONFIGURE # pw-beta - change the frontend refresh interval via CONFIGURE -class PlugwiseOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry): # pw-beta options +class PlugwiseOptionsFlowHandler(OptionsFlowWithConfigEntry): # pw-beta options """Plugwise option flow.""" async def async_step_none( From 8f151aa07823fadef0e483c9908a8c5a7e2c8533 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:22:02 +0200 Subject: [PATCH 15/22] Import PlugwiseConfigEntry --- custom_components/plugwise/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index c90ee6f61..285e2f985 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -19,7 +19,6 @@ from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.config_entries import ( SOURCE_USER, - ConfigEntry, ConfigFlow, ConfigFlowResult, OptionsFlow, @@ -39,6 +38,7 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession +from . import PlugwiseConfigEntry from .const import ( ANNA_WITH_ADAM, CONF_HOMEKIT_EMULATION, # pw-beta option @@ -249,7 +249,7 @@ async def async_step_user( @staticmethod @callback def async_get_options_flow( - config_entry: ConfigEntry, + config_entry: PlugwiseConfigEntry, ) -> OptionsFlow: # pw-beta options """Get the options flow for this handler.""" return PlugwiseOptionsFlowHandler(config_entry) From e99852f8d387b3866e1823ef419a60cf00aacd20 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:41:31 +0200 Subject: [PATCH 16/22] Try --- custom_components/plugwise/config_flow.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index 285e2f985..087a0e206 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -279,9 +279,12 @@ async def async_step_init( return await self.async_step_none(user_input) if user_input is not None: + self.hass.config_entries.async_update_entry( + self._config_entry, data=user_input + ) return self.async_create_entry(title="", data=user_input) - coordinator = self.config_entry.runtime_data + coordinator = self._config_entry.runtime_data interval: dt.timedelta = DEFAULT_SCAN_INTERVAL[ coordinator.api.smile_type ] # pw-beta options From 3389dbb2febb86bb5fd6203cae27e358502a04a2 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:44:38 +0200 Subject: [PATCH 17/22] Try 2 --- custom_components/plugwise/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index 087a0e206..ced0fcc23 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -284,7 +284,7 @@ async def async_step_init( ) return self.async_create_entry(title="", data=user_input) - coordinator = self._config_entry.runtime_data + coordinator = self.hass.data[DOMAIN][self.config_entry.entry_id][COORDINATOR] interval: dt.timedelta = DEFAULT_SCAN_INTERVAL[ coordinator.api.smile_type ] # pw-beta options From bb7a19902200d673d7975390ecd471089e1049da Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:45:33 +0200 Subject: [PATCH 18/22] Revert "Import PlugwiseConfigEntry" This reverts commit 8f151aa07823fadef0e483c9908a8c5a7e2c8533. --- custom_components/plugwise/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index ced0fcc23..9f4b08ee8 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -19,6 +19,7 @@ from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.config_entries import ( SOURCE_USER, + ConfigEntry, ConfigFlow, ConfigFlowResult, OptionsFlow, @@ -38,7 +39,6 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession -from . import PlugwiseConfigEntry from .const import ( ANNA_WITH_ADAM, CONF_HOMEKIT_EMULATION, # pw-beta option @@ -249,7 +249,7 @@ async def async_step_user( @staticmethod @callback def async_get_options_flow( - config_entry: PlugwiseConfigEntry, + config_entry: ConfigEntry, ) -> OptionsFlow: # pw-beta options """Get the options flow for this handler.""" return PlugwiseOptionsFlowHandler(config_entry) From 01e1b8d274d75b67fd0403a50d8269e481026a16 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:46:57 +0200 Subject: [PATCH 19/22] Revert more --- custom_components/plugwise/config_flow.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index 9f4b08ee8..f279a656c 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -279,9 +279,6 @@ async def async_step_init( return await self.async_step_none(user_input) if user_input is not None: - self.hass.config_entries.async_update_entry( - self._config_entry, data=user_input - ) return self.async_create_entry(title="", data=user_input) coordinator = self.hass.data[DOMAIN][self.config_entry.entry_id][COORDINATOR] From 1ac640a61137ed111192fc947a05ada5772b3a28 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:50:26 +0200 Subject: [PATCH 20/22] Use _options from OptionsFlowWithConfigEntry --- custom_components/plugwise/config_flow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index f279a656c..938204f1d 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -267,7 +267,7 @@ async def async_step_none( """No options available.""" if user_input is not None: # Apparently not possible to abort an options flow at the moment - return self.async_create_entry(title="", data=self.config_entry.options) + return self.async_create_entry(title="", data=self._options) return self.async_show_form(step_id="none") @@ -289,7 +289,7 @@ async def async_step_init( data = { vol.Optional( CONF_SCAN_INTERVAL, - default=self.config_entry.options.get( + default=self._options.get( CONF_SCAN_INTERVAL, interval.seconds ), ): vol.All(cv.positive_int, vol.Clamp(min=10)), @@ -302,13 +302,13 @@ async def async_step_init( { vol.Optional( CONF_HOMEKIT_EMULATION, - default=self.config_entry.options.get( + default=self._options.get( CONF_HOMEKIT_EMULATION, False ), ): cv.boolean, vol.Optional( CONF_REFRESH_INTERVAL, - default=self.config_entry.options.get(CONF_REFRESH_INTERVAL, 1.5), + default=self._options.get(CONF_REFRESH_INTERVAL, 1.5), ): vol.All(vol.Coerce(float), vol.Range(min=1.5, max=10.0)), } ) # pw-beta From f23bd334382226ae220d30543ca654ab3e8ad244 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 11:54:05 +0200 Subject: [PATCH 21/22] Clean-up --- custom_components/plugwise/config_flow.py | 1 - 1 file changed, 1 deletion(-) diff --git a/custom_components/plugwise/config_flow.py b/custom_components/plugwise/config_flow.py index 938204f1d..f9fb5f63d 100644 --- a/custom_components/plugwise/config_flow.py +++ b/custom_components/plugwise/config_flow.py @@ -15,7 +15,6 @@ ) import voluptuous as vol -from homeassistant import config_entries from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.config_entries import ( SOURCE_USER, From 779763564d7104d576de8cecd02fb8ed0dc282ef Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 20 Jun 2024 12:03:44 +0200 Subject: [PATCH 22/22] Update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6204c3821..a1a73cfe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## Versions from 0.40 and up -## v051.3 +## Ongoing + +- Implement various new Core features. + +## v0.51.3 - Implement fix for Core Issue #119686 via plugwise [v0.38.3](https://github.com/plugwise/python-plugwise/releases/tag/v0.38.3)