mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use runtime_data in bosch_shc (#136356)
This commit is contained in:
parent
8dba4affa9
commit
29c528ee54
@ -12,13 +12,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .const import (
|
from .const import CONF_SSL_CERTIFICATE, CONF_SSL_KEY, DOMAIN
|
||||||
CONF_SSL_CERTIFICATE,
|
|
||||||
CONF_SSL_KEY,
|
|
||||||
DATA_POLLING_HANDLER,
|
|
||||||
DATA_SESSION,
|
|
||||||
DOMAIN,
|
|
||||||
)
|
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -30,7 +24,10 @@ PLATFORMS = [
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
type BoschConfigEntry = ConfigEntry[SHCSession]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: BoschConfigEntry) -> bool:
|
||||||
"""Set up Bosch SHC from a config entry."""
|
"""Set up Bosch SHC from a config entry."""
|
||||||
data = entry.data
|
data = entry.data
|
||||||
|
|
||||||
@ -53,10 +50,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
if shc_info.updateState.name == "UPDATE_AVAILABLE":
|
if shc_info.updateState.name == "UPDATE_AVAILABLE":
|
||||||
_LOGGER.warning("Please check for software updates in the Bosch Smart Home App")
|
_LOGGER.warning("Please check for software updates in the Bosch Smart Home App")
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
entry.runtime_data = session
|
||||||
hass.data[DOMAIN][entry.entry_id] = {
|
|
||||||
DATA_SESSION: session,
|
|
||||||
}
|
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
@ -76,23 +70,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.async_add_executor_job(session.stop_polling)
|
await hass.async_add_executor_job(session.stop_polling)
|
||||||
|
|
||||||
await hass.async_add_executor_job(session.start_polling)
|
await hass.async_add_executor_job(session.start_polling)
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_POLLING_HANDLER] = (
|
entry.async_on_unload(
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_polling)
|
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_polling)
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: BoschConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
session: SHCSession = hass.data[DOMAIN][entry.entry_id][DATA_SESSION]
|
await hass.async_add_executor_job(entry.runtime_data.stop_polling)
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_POLLING_HANDLER]()
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN][entry.entry_id].pop(DATA_POLLING_HANDLER)
|
|
||||||
await hass.async_add_executor_job(session.stop_polling)
|
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -2,28 +2,27 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from boschshcpy import SHCBatteryDevice, SHCSession, SHCShutterContact
|
from boschshcpy import SHCBatteryDevice, SHCShutterContact
|
||||||
from boschshcpy.device import SHCDevice
|
from boschshcpy.device import SHCDevice
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_SESSION, DOMAIN
|
from . import BoschConfigEntry
|
||||||
from .entity import SHCEntity
|
from .entity import SHCEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: BoschConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SHC binary sensor platform."""
|
"""Set up the SHC binary sensor platform."""
|
||||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
session = config_entry.runtime_data
|
||||||
|
|
||||||
entities: list[BinarySensorEntity] = [
|
entities: list[BinarySensorEntity] = [
|
||||||
ShutterContactSensor(
|
ShutterContactSensor(
|
||||||
|
@ -6,7 +6,4 @@ CONF_SHC_KEY = "bosch_shc-key.pem"
|
|||||||
CONF_SSL_CERTIFICATE = "ssl_certificate"
|
CONF_SSL_CERTIFICATE = "ssl_certificate"
|
||||||
CONF_SSL_KEY = "ssl_key"
|
CONF_SSL_KEY = "ssl_key"
|
||||||
|
|
||||||
DATA_SESSION = "session"
|
|
||||||
DATA_POLLING_HANDLER = "polling_handler"
|
|
||||||
|
|
||||||
DOMAIN = "bosch_shc"
|
DOMAIN = "bosch_shc"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from boschshcpy import SHCSession, SHCShutterControl
|
from boschshcpy import SHCShutterControl
|
||||||
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
@ -10,22 +10,20 @@ from homeassistant.components.cover import (
|
|||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DATA_SESSION, DOMAIN
|
from . import BoschConfigEntry
|
||||||
from .entity import SHCEntity
|
from .entity import SHCEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: BoschConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SHC cover platform."""
|
"""Set up the SHC cover platform."""
|
||||||
|
session = config_entry.runtime_data
|
||||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
ShutterControlCover(
|
ShutterControlCover(
|
||||||
|
@ -6,7 +6,6 @@ from collections.abc import Callable
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from boschshcpy import SHCSession
|
|
||||||
from boschshcpy.device import SHCDevice
|
from boschshcpy.device import SHCDevice
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
@ -15,7 +14,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -27,7 +25,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import DATA_SESSION, DOMAIN
|
from . import BoschConfigEntry
|
||||||
from .entity import SHCEntity
|
from .entity import SHCEntity
|
||||||
|
|
||||||
|
|
||||||
@ -127,11 +125,11 @@ SENSOR_DESCRIPTIONS: dict[str, SHCSensorEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: BoschConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SHC sensor platform."""
|
"""Set up the SHC sensor platform."""
|
||||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
session = config_entry.runtime_data
|
||||||
|
|
||||||
entities: list[SensorEntity] = [
|
entities: list[SensorEntity] = [
|
||||||
SHCSensor(
|
SHCSensor(
|
||||||
|
@ -9,7 +9,6 @@ from boschshcpy import (
|
|||||||
SHCCamera360,
|
SHCCamera360,
|
||||||
SHCCameraEyes,
|
SHCCameraEyes,
|
||||||
SHCLightSwitch,
|
SHCLightSwitch,
|
||||||
SHCSession,
|
|
||||||
SHCSmartPlug,
|
SHCSmartPlug,
|
||||||
SHCSmartPlugCompact,
|
SHCSmartPlugCompact,
|
||||||
)
|
)
|
||||||
@ -20,13 +19,12 @@ from homeassistant.components.switch import (
|
|||||||
SwitchEntity,
|
SwitchEntity,
|
||||||
SwitchEntityDescription,
|
SwitchEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import DATA_SESSION, DOMAIN
|
from . import BoschConfigEntry
|
||||||
from .entity import SHCEntity
|
from .entity import SHCEntity
|
||||||
|
|
||||||
|
|
||||||
@ -80,11 +78,11 @@ SWITCH_TYPES: dict[str, SHCSwitchEntityDescription] = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: BoschConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SHC switch platform."""
|
"""Set up the SHC switch platform."""
|
||||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
session = config_entry.runtime_data
|
||||||
|
|
||||||
entities: list[SwitchEntity] = [
|
entities: list[SwitchEntity] = [
|
||||||
SHCSwitch(
|
SHCSwitch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user