1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Migrate nobo_hub to use runtime_data (#166934)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
epenet
2026-03-31 11:16:19 +02:00
committed by GitHub
parent 0edc2cbbab
commit f3b64dcbe0
5 changed files with 18 additions and 20 deletions

View File

@@ -9,12 +9,14 @@ from homeassistant.const import CONF_IP_ADDRESS, EVENT_HOMEASSISTANT_STOP, Platf
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from .const import CONF_AUTO_DISCOVERED, CONF_SERIAL, DOMAIN
from .const import CONF_AUTO_DISCOVERED, CONF_SERIAL
PLATFORMS = [Platform.CLIMATE, Platform.SELECT, Platform.SENSOR]
type NoboHubConfigEntry = ConfigEntry[nobo]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: NoboHubConfigEntry) -> bool:
"""Set up Nobø Ecohub from a config entry."""
serial = entry.data[CONF_SERIAL]
@@ -29,8 +31,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
await hub.connect()
hass.data.setdefault(DOMAIN, {})
async def _async_close(event):
"""Close the Nobø Ecohub socket connection when HA stops."""
await hub.stop()
@@ -38,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry.async_on_unload(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_close)
)
hass.data[DOMAIN][entry.entry_id] = hub
entry.runtime_data = hub
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
@@ -47,12 +47,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: NoboHubConfigEntry) -> bool:
"""Unload a config entry."""
hub: nobo = hass.data[DOMAIN][entry.entry_id]
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
await hub.stop()
hass.data[DOMAIN].pop(entry.entry_id)
await entry.runtime_data.stop()
return unload_ok

View File

@@ -17,13 +17,13 @@ from homeassistant.components.climate import (
ClimateEntityFeature,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_NAME, PRECISION_TENTHS, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.util import dt as dt_util
from . import NoboHubConfigEntry
from .const import (
ATTR_SERIAL,
ATTR_TEMP_COMFORT_C,
@@ -45,13 +45,13 @@ MAX_TEMPERATURE = 30
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: NoboHubConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Nobø Ecohub platform from UI configuration."""
# Setup connection with hub
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
hub = config_entry.runtime_data
override_type = (
nobo.API.OVERRIDE_TYPE_NOW

View File

@@ -9,7 +9,6 @@ from pynobo import nobo
import voluptuous as vol
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlowWithReload,
@@ -18,6 +17,7 @@ from homeassistant.const import CONF_IP_ADDRESS
from homeassistant.core import callback
from homeassistant.exceptions import HomeAssistantError
from . import NoboHubConfigEntry
from .const import (
CONF_AUTO_DISCOVERED,
CONF_OVERRIDE_TYPE,
@@ -172,7 +172,7 @@ class NoboHubConfigFlow(ConfigFlow, domain=DOMAIN):
@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
config_entry: NoboHubConfigEntry,
) -> OptionsFlowHandler:
"""Get the options flow for this handler."""
return OptionsFlowHandler()

View File

@@ -5,13 +5,13 @@ from __future__ import annotations
from pynobo import nobo
from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_NAME
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import NoboHubConfigEntry
from .const import (
ATTR_HARDWARE_VERSION,
ATTR_SERIAL,
@@ -25,13 +25,13 @@ from .const import (
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: NoboHubConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up any temperature sensors connected to the Nobø Ecohub."""
# Setup connection with hub
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
hub = config_entry.runtime_data
override_type = (
nobo.API.OVERRIDE_TYPE_NOW

View File

@@ -9,25 +9,25 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_MODEL, ATTR_NAME, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import NoboHubConfigEntry
from .const import ATTR_SERIAL, ATTR_ZONE_ID, DOMAIN, NOBO_MANUFACTURER
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: NoboHubConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up any temperature sensors connected to the Nobø Ecohub."""
# Setup connection with hub
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
hub = config_entry.runtime_data
async_add_entities(
NoboTemperatureSensor(component["serial"], hub)