From 8fe6072bff8850db2d55db8254cc655e7d1fc6a7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 2 Apr 2026 07:20:03 +0000 Subject: [PATCH] Migrate progettihwsw to use runtime_data Co-Authored-By: Claude Opus 4.6 (1M context) --- .../components/progettihwsw/__init__.py | 27 +++++++++---------- .../components/progettihwsw/binary_sensor.py | 11 ++++---- .../components/progettihwsw/switch.py | 11 ++++---- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/progettihwsw/__init__.py b/homeassistant/components/progettihwsw/__init__.py index 4d090f4d0c18..868f6c8766ef 100644 --- a/homeassistant/components/progettihwsw/__init__.py +++ b/homeassistant/components/progettihwsw/__init__.py @@ -8,33 +8,32 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from .const import DOMAIN - PLATFORMS = [Platform.BINARY_SENSOR, Platform.SWITCH] +type ProgettihwswConfigEntry = ConfigEntry[ProgettiHWSWAPI] -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: + +async def async_setup_entry( + hass: HomeAssistant, entry: ProgettihwswConfigEntry +) -> bool: """Set up ProgettiHWSW Automation from a config entry.""" - hass.data.setdefault(DOMAIN, {}) - hass.data[DOMAIN][entry.entry_id] = ProgettiHWSWAPI( - f"{entry.data['host']}:{entry.data['port']}" - ) + api = ProgettiHWSWAPI(f"{entry.data['host']}:{entry.data['port']}") # Check board validation again to load new values to API. - await hass.data[DOMAIN][entry.entry_id].check_board() + await api.check_board() + + entry.runtime_data = api await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry( + hass: HomeAssistant, entry: ProgettihwswConfigEntry +) -> bool: """Unload a config entry.""" - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - if unload_ok: - hass.data[DOMAIN].pop(entry.entry_id) - - return unload_ok + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) def setup_input(api: ProgettiHWSWAPI, input_number: int) -> Input: diff --git a/homeassistant/components/progettihwsw/binary_sensor.py b/homeassistant/components/progettihwsw/binary_sensor.py index aeec792cff1b..26d540531ad5 100644 --- a/homeassistant/components/progettihwsw/binary_sensor.py +++ b/homeassistant/components/progettihwsw/binary_sensor.py @@ -7,7 +7,6 @@ import logging from ProgettiHWSW.input import Input from homeassistant.components.binary_sensor import BinarySensorEntity -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -15,19 +14,19 @@ from homeassistant.helpers.update_coordinator import ( DataUpdateCoordinator, ) -from . import setup_input -from .const import DEFAULT_POLLING_INTERVAL_SEC, DOMAIN +from . import ProgettihwswConfigEntry, setup_input +from .const import DEFAULT_POLLING_INTERVAL_SEC -_LOGGER = logging.getLogger(DOMAIN) +_LOGGER = logging.getLogger(__name__) async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: ProgettihwswConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up the binary sensors from a config entry.""" - board_api = hass.data[DOMAIN][config_entry.entry_id] + board_api = config_entry.runtime_data input_count = config_entry.data["input_count"] async def async_update_data(): diff --git a/homeassistant/components/progettihwsw/switch.py b/homeassistant/components/progettihwsw/switch.py index b2f00d52439c..6319e18b45f9 100644 --- a/homeassistant/components/progettihwsw/switch.py +++ b/homeassistant/components/progettihwsw/switch.py @@ -8,7 +8,6 @@ from typing import Any from ProgettiHWSW.relay import Relay from homeassistant.components.switch import SwitchEntity -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.update_coordinator import ( @@ -16,19 +15,19 @@ from homeassistant.helpers.update_coordinator import ( DataUpdateCoordinator, ) -from . import setup_switch -from .const import DEFAULT_POLLING_INTERVAL_SEC, DOMAIN +from . import ProgettihwswConfigEntry, setup_switch +from .const import DEFAULT_POLLING_INTERVAL_SEC -_LOGGER = logging.getLogger(DOMAIN) +_LOGGER = logging.getLogger(__name__) async def async_setup_entry( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: ProgettihwswConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Set up the switches from a config entry.""" - board_api = hass.data[DOMAIN][config_entry.entry_id] + board_api = config_entry.runtime_data relay_count = config_entry.data["relay_count"] async def async_update_data():