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:
@@ -9,12 +9,14 @@ from homeassistant.const import CONF_IP_ADDRESS, EVENT_HOMEASSISTANT_STOP, Platf
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import dt as dt_util
|
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]
|
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."""
|
"""Set up Nobø Ecohub from a config entry."""
|
||||||
|
|
||||||
serial = entry.data[CONF_SERIAL]
|
serial = entry.data[CONF_SERIAL]
|
||||||
@@ -29,8 +31,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
await hub.connect()
|
await hub.connect()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
|
|
||||||
async def _async_close(event):
|
async def _async_close(event):
|
||||||
"""Close the Nobø Ecohub socket connection when HA stops."""
|
"""Close the Nobø Ecohub socket connection when HA stops."""
|
||||||
await hub.stop()
|
await hub.stop()
|
||||||
@@ -38,7 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
entry.async_on_unload(
|
entry.async_on_unload(
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_close)
|
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)
|
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
|
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."""
|
"""Unload a config entry."""
|
||||||
|
|
||||||
hub: nobo = hass.data[DOMAIN][entry.entry_id]
|
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
await hub.stop()
|
await entry.runtime_data.stop()
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ from homeassistant.components.climate import (
|
|||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_NAME, PRECISION_TENTHS, UnitOfTemperature
|
from homeassistant.const import ATTR_NAME, PRECISION_TENTHS, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from . import NoboHubConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_SERIAL,
|
ATTR_SERIAL,
|
||||||
ATTR_TEMP_COMFORT_C,
|
ATTR_TEMP_COMFORT_C,
|
||||||
@@ -45,13 +45,13 @@ MAX_TEMPERATURE = 30
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: NoboHubConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Nobø Ecohub platform from UI configuration."""
|
"""Set up the Nobø Ecohub platform from UI configuration."""
|
||||||
|
|
||||||
# Setup connection with hub
|
# Setup connection with hub
|
||||||
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
override_type = (
|
override_type = (
|
||||||
nobo.API.OVERRIDE_TYPE_NOW
|
nobo.API.OVERRIDE_TYPE_NOW
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from pynobo import nobo
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
ConfigEntry,
|
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
OptionsFlowWithReload,
|
OptionsFlowWithReload,
|
||||||
@@ -18,6 +17,7 @@ from homeassistant.const import CONF_IP_ADDRESS
|
|||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
|
from . import NoboHubConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_AUTO_DISCOVERED,
|
CONF_AUTO_DISCOVERED,
|
||||||
CONF_OVERRIDE_TYPE,
|
CONF_OVERRIDE_TYPE,
|
||||||
@@ -172,7 +172,7 @@ class NoboHubConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(
|
def async_get_options_flow(
|
||||||
config_entry: ConfigEntry,
|
config_entry: NoboHubConfigEntry,
|
||||||
) -> OptionsFlowHandler:
|
) -> OptionsFlowHandler:
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return OptionsFlowHandler()
|
return OptionsFlowHandler()
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ from __future__ import annotations
|
|||||||
from pynobo import nobo
|
from pynobo import nobo
|
||||||
|
|
||||||
from homeassistant.components.select import SelectEntity
|
from homeassistant.components.select import SelectEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_NAME
|
from homeassistant.const import ATTR_NAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
|
from . import NoboHubConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_HARDWARE_VERSION,
|
ATTR_HARDWARE_VERSION,
|
||||||
ATTR_SERIAL,
|
ATTR_SERIAL,
|
||||||
@@ -25,13 +25,13 @@ from .const import (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: NoboHubConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up any temperature sensors connected to the Nobø Ecohub."""
|
"""Set up any temperature sensors connected to the Nobø Ecohub."""
|
||||||
|
|
||||||
# Setup connection with hub
|
# Setup connection with hub
|
||||||
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
override_type = (
|
override_type = (
|
||||||
nobo.API.OVERRIDE_TYPE_NOW
|
nobo.API.OVERRIDE_TYPE_NOW
|
||||||
|
|||||||
@@ -9,25 +9,25 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_MODEL, ATTR_NAME, UnitOfTemperature
|
from homeassistant.const import ATTR_MODEL, ATTR_NAME, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
|
from . import NoboHubConfigEntry
|
||||||
from .const import ATTR_SERIAL, ATTR_ZONE_ID, DOMAIN, NOBO_MANUFACTURER
|
from .const import ATTR_SERIAL, ATTR_ZONE_ID, DOMAIN, NOBO_MANUFACTURER
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: NoboHubConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up any temperature sensors connected to the Nobø Ecohub."""
|
"""Set up any temperature sensors connected to the Nobø Ecohub."""
|
||||||
|
|
||||||
# Setup connection with hub
|
# Setup connection with hub
|
||||||
hub: nobo = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
NoboTemperatureSensor(component["serial"], hub)
|
NoboTemperatureSensor(component["serial"], hub)
|
||||||
|
|||||||
Reference in New Issue
Block a user