mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Migrate lupusec to use runtime_data (#147476)
This commit is contained in:
parent
10d1affd81
commit
2bcdc03661
@ -12,8 +12,6 @@ from homeassistant.core import HomeAssistant
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = "lupusec"
|
|
||||||
|
|
||||||
NOTIFICATION_ID = "lupusec_notification"
|
NOTIFICATION_ID = "lupusec_notification"
|
||||||
NOTIFICATION_TITLE = "Lupusec Security Setup"
|
NOTIFICATION_TITLE = "Lupusec Security Setup"
|
||||||
|
|
||||||
@ -24,8 +22,10 @@ PLATFORMS: list[Platform] = [
|
|||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
type LupusecConfigEntry = ConfigEntry[lupupy.Lupusec]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(hass: HomeAssistant, entry: LupusecConfigEntry) -> bool:
|
||||||
"""Set up this integration using UI."""
|
"""Set up this integration using UI."""
|
||||||
|
|
||||||
host = entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
@ -43,7 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
_LOGGER.error("Failed to connect to Lupusec device at %s", host)
|
_LOGGER.error("Failed to connect to Lupusec device at %s", host)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = lupusec_system
|
entry.runtime_data = lupusec_system
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@ from homeassistant.components.alarm_control_panel import (
|
|||||||
AlarmControlPanelEntityFeature,
|
AlarmControlPanelEntityFeature,
|
||||||
AlarmControlPanelState,
|
AlarmControlPanelState,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
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 DOMAIN
|
from . import LupusecConfigEntry
|
||||||
|
from .const import DOMAIN
|
||||||
from .entity import LupusecDevice
|
from .entity import LupusecDevice
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=2)
|
SCAN_INTERVAL = timedelta(seconds=2)
|
||||||
@ -24,11 +24,11 @@ SCAN_INTERVAL = timedelta(seconds=2)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LupusecConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up an alarm control panel for a Lupusec device."""
|
"""Set up an alarm control panel for a Lupusec device."""
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
|
|
||||||
alarm = await hass.async_add_executor_job(data.get_alarm)
|
alarm = await hass.async_add_executor_job(data.get_alarm)
|
||||||
|
|
||||||
|
@ -12,11 +12,10 @@ 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 AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import LupusecConfigEntry
|
||||||
from .entity import LupusecBaseSensor
|
from .entity import LupusecBaseSensor
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=2)
|
SCAN_INTERVAL = timedelta(seconds=2)
|
||||||
@ -26,12 +25,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LupusecConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a binary sensors for a Lupusec device."""
|
"""Set up a binary sensors for a Lupusec device."""
|
||||||
|
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
|
|
||||||
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
||||||
|
|
||||||
|
@ -9,11 +9,10 @@ from typing import Any
|
|||||||
import lupupy.constants as CONST
|
import lupupy.constants as CONST
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import LupusecConfigEntry
|
||||||
from .entity import LupusecBaseSensor
|
from .entity import LupusecBaseSensor
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=2)
|
SCAN_INTERVAL = timedelta(seconds=2)
|
||||||
@ -21,12 +20,12 @@ SCAN_INTERVAL = timedelta(seconds=2)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LupusecConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Lupusec switch devices."""
|
"""Set up Lupusec switch devices."""
|
||||||
|
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
|
|
||||||
device_types = CONST.TYPE_SWITCH
|
device_types = CONST.TYPE_SWITCH
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user