mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Migrate progettihwsw to use runtime_data
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
6e567ced92
commit
8fe6072bff
@@ -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:
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user