mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Use runtime_data in isy994 (#144961)
This commit is contained in:
parent
50e6c83dd8
commit
d195726ed2
@ -10,7 +10,6 @@ from pyisy import ISY, ISYConnectionError, ISYInvalidAuthError, ISYResponseParse
|
||||
from pyisy.constants import CONFIG_NETWORKING, CONFIG_PORTAL
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
@ -46,7 +45,7 @@ from .const import (
|
||||
SCHEME_HTTPS,
|
||||
)
|
||||
from .helpers import _categorize_nodes, _categorize_programs
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry, IsyData
|
||||
from .services import async_setup_services, async_unload_services
|
||||
from .util import _async_cleanup_registry_entries
|
||||
|
||||
@ -56,13 +55,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: IsyConfigEntry) -> bool:
|
||||
"""Set up the ISY 994 integration."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
isy_data = hass.data[DOMAIN][entry.entry_id] = IsyData()
|
||||
|
||||
isy_config = entry.data
|
||||
isy_options = entry.options
|
||||
|
||||
@ -127,6 +121,7 @@ async def async_setup_entry(
|
||||
f"Invalid response ISY, device is likely still starting: {err}"
|
||||
) from err
|
||||
|
||||
isy_data = entry.runtime_data = IsyData()
|
||||
_categorize_nodes(isy_data, isy.nodes, ignore_identifier, sensor_identifier)
|
||||
_categorize_programs(isy_data, isy.programs)
|
||||
# Gather ISY Variables to be added.
|
||||
@ -156,7 +151,7 @@ async def async_setup_entry(
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
# Clean-up any old entities that we no longer provide.
|
||||
_async_cleanup_registry_entries(hass, entry.entry_id)
|
||||
_async_cleanup_registry_entries(hass, entry)
|
||||
|
||||
@callback
|
||||
def _async_stop_auto_update(event: Event) -> None:
|
||||
@ -178,16 +173,14 @@ async def async_setup_entry(
|
||||
return True
|
||||
|
||||
|
||||
async def _async_update_listener(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> None:
|
||||
async def _async_update_listener(hass: HomeAssistant, entry: IsyConfigEntry) -> None:
|
||||
"""Handle options update."""
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
@callback
|
||||
def _async_get_or_create_isy_device_in_registry(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry, isy: ISY
|
||||
hass: HomeAssistant, entry: IsyConfigEntry, isy: ISY
|
||||
) -> None:
|
||||
device_registry = dr.async_get(hass)
|
||||
device_registry.async_get_or_create(
|
||||
@ -221,34 +214,25 @@ def _create_service_device_info(isy: ISY, name: str, unique_id: str) -> DeviceIn
|
||||
)
|
||||
|
||||
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, entry: config_entries.ConfigEntry
|
||||
) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: IsyConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
isy = isy_data.root
|
||||
|
||||
_LOGGER.debug("ISY Stopping Event Stream and automatic updates")
|
||||
isy.websocket.stop()
|
||||
entry.runtime_data.root.websocket.stop()
|
||||
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
async_unload_services(hass)
|
||||
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
||||
async_unload_services(hass)
|
||||
|
||||
return unload_ok
|
||||
|
||||
|
||||
async def async_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
config_entry: config_entries.ConfigEntry,
|
||||
config_entry: IsyConfigEntry,
|
||||
device_entry: dr.DeviceEntry,
|
||||
) -> bool:
|
||||
"""Remove ISY config entry from a device."""
|
||||
isy_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
return not device_entry.identifiers.intersection(
|
||||
(DOMAIN, unique_id) for unique_id in isy_data.devices
|
||||
(DOMAIN, unique_id) for unique_id in config_entry.runtime_data.devices
|
||||
)
|
||||
|
@ -19,7 +19,6 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_ON, Platform
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
@ -31,7 +30,6 @@ from .const import (
|
||||
_LOGGER,
|
||||
BINARY_SENSOR_DEVICE_TYPES_ISY,
|
||||
BINARY_SENSOR_DEVICE_TYPES_ZWAVE,
|
||||
DOMAIN,
|
||||
SUBNODE_CLIMATE_COOL,
|
||||
SUBNODE_CLIMATE_HEAT,
|
||||
SUBNODE_DUSK_DAWN,
|
||||
@ -44,7 +42,7 @@ from .const import (
|
||||
TYPE_INSTEON_MOTION,
|
||||
)
|
||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
DEVICE_PARENT_REQUIRED = [
|
||||
BinarySensorDeviceClass.OPENING,
|
||||
@ -55,7 +53,7 @@ DEVICE_PARENT_REQUIRED = [
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY binary sensor platform."""
|
||||
@ -82,8 +80,8 @@ async def async_setup_entry(
|
||||
| ISYBinarySensorProgramEntity
|
||||
)
|
||||
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
for node in isy_data.nodes[Platform.BINARY_SENSOR]:
|
||||
assert isinstance(node, Node)
|
||||
device_info = devices.get(node.primary_node)
|
||||
|
@ -15,24 +15,23 @@ from pyisy.networking import NetworkCommand
|
||||
from pyisy.nodes import Node
|
||||
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import CONF_NETWORK, DOMAIN
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ISY/IoX button from config entry."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
isy: ISY = isy_data.root
|
||||
isy_data = config_entry.runtime_data
|
||||
isy = isy_data.root
|
||||
device_info = isy_data.devices
|
||||
entities: list[
|
||||
ISYNodeQueryButtonEntity
|
||||
|
@ -28,7 +28,6 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_TENTHS,
|
||||
@ -42,7 +41,6 @@ from homeassistant.util.enum import try_parse_enum
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
DOMAIN,
|
||||
HA_FAN_TO_ISY,
|
||||
HA_HVAC_TO_ISY,
|
||||
ISY_HVAC_MODES,
|
||||
@ -57,18 +55,18 @@ from .const import (
|
||||
)
|
||||
from .entity import ISYNodeEntity
|
||||
from .helpers import convert_isy_value_to_hass
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY thermostat platform."""
|
||||
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
|
||||
async_add_entities(
|
||||
ISYThermostatEntity(node, devices.get(node.primary_node))
|
||||
|
@ -16,7 +16,6 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_IGNORE,
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
@ -54,6 +53,7 @@ from .const import (
|
||||
SCHEME_HTTPS,
|
||||
UDN_UUID_PREFIX,
|
||||
)
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -137,12 +137,12 @@ class Isy994ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the ISY/IoX config flow."""
|
||||
self.discovered_conf: dict[str, str] = {}
|
||||
self._existing_entry: ConfigEntry | None = None
|
||||
self._existing_entry: IsyConfigEntry | None = None
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: IsyConfigEntry,
|
||||
) -> OptionsFlow:
|
||||
"""Get the options flow for this handler."""
|
||||
return OptionsFlowHandler()
|
||||
|
@ -11,25 +11,23 @@ from homeassistant.components.cover import (
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import _LOGGER, DOMAIN, UOM_8_BIT_RANGE
|
||||
from .const import _LOGGER, UOM_8_BIT_RANGE
|
||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY cover platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
entities: list[ISYCoverEntity | ISYCoverProgramEntity] = [
|
||||
ISYCoverEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.COVER]
|
||||
|
@ -8,10 +8,8 @@ from typing import Any
|
||||
from pyisy.constants import ISY_VALUE_UNKNOWN, PROTO_INSTEON
|
||||
|
||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
@ -19,21 +17,21 @@ from homeassistant.util.percentage import (
|
||||
)
|
||||
from homeassistant.util.scaling import int_states_in_range
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .const import _LOGGER
|
||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
SPEED_RANGE = (1, 255) # off is not included
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY fan platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
entities: list[ISYFanEntity | ISYFanProgramEntity] = [
|
||||
ISYFanEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.FAN]
|
||||
|
@ -9,28 +9,27 @@ from pyisy.helpers import NodeProperty
|
||||
from pyisy.nodes import Node
|
||||
|
||||
from homeassistant.components.light import ColorMode, LightEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .const import _LOGGER, CONF_RESTORE_LIGHT_STATE, DOMAIN, UOM_PERCENTAGE
|
||||
from .const import _LOGGER, CONF_RESTORE_LIGHT_STATE, UOM_PERCENTAGE
|
||||
from .entity import ISYNodeEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
ATTR_LAST_BRIGHTNESS = "last_brightness"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY light platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
isy_options = entry.options
|
||||
restore_light_state = isy_options.get(CONF_RESTORE_LIGHT_STATE, False)
|
||||
|
||||
|
@ -7,19 +7,16 @@ from typing import Any
|
||||
from pyisy.constants import ISY_VALUE_UNKNOWN
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
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,
|
||||
async_get_current_platform,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
from .services import (
|
||||
SERVICE_DELETE_USER_CODE_SCHEMA,
|
||||
SERVICE_DELETE_ZWAVE_LOCK_USER_CODE,
|
||||
@ -49,12 +46,12 @@ def async_setup_lock_services(hass: HomeAssistant) -> None:
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY lock platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
isy_data = entry.runtime_data
|
||||
devices = isy_data.devices
|
||||
entities: list[ISYLockEntity | ISYLockProgramEntity] = [
|
||||
ISYLockEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.LOCK]
|
||||
|
@ -12,6 +12,7 @@ from pyisy.nodes import Group, Node
|
||||
from pyisy.programs import Program
|
||||
from pyisy.variables import Variable
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
|
||||
@ -24,6 +25,8 @@ from .const import (
|
||||
VARIABLE_PLATFORMS,
|
||||
)
|
||||
|
||||
type IsyConfigEntry = ConfigEntry[IsyData]
|
||||
|
||||
|
||||
@dataclass
|
||||
class IsyData:
|
||||
|
@ -26,7 +26,6 @@ from homeassistant.components.number import (
|
||||
NumberMode,
|
||||
RestoreNumber,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_VARIABLES,
|
||||
PERCENTAGE,
|
||||
@ -44,15 +43,10 @@ from homeassistant.util.percentage import (
|
||||
ranged_value_to_percentage,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
CONF_VAR_SENSOR_STRING,
|
||||
DEFAULT_VAR_SENSOR_STRING,
|
||||
DOMAIN,
|
||||
UOM_8_BIT_RANGE,
|
||||
)
|
||||
from .const import CONF_VAR_SENSOR_STRING, DEFAULT_VAR_SENSOR_STRING, UOM_8_BIT_RANGE
|
||||
from .entity import ISYAuxControlEntity
|
||||
from .helpers import convert_isy_value_to_hass
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
ISY_MAX_SIZE = (2**32) / 2
|
||||
ON_RANGE = (1, 255) # Off is not included
|
||||
@ -79,11 +73,11 @@ BACKLIGHT_MEMORY_FILTER = {"memory": DEV_BL_ADDR, "cmd1": DEV_CMD_MEMORY_WRITE}
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ISY/IoX number entities from config entry."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
isy_data = config_entry.runtime_data
|
||||
device_info = isy_data.devices
|
||||
entities: list[
|
||||
ISYVariableNumberEntity | ISYAuxControlNumberEntity | ISYBacklightNumberEntity
|
||||
|
@ -23,7 +23,6 @@ from pyisy.helpers import EventListener, NodeProperty
|
||||
from pyisy.nodes import Node, NodeChangedEvent
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
@ -37,9 +36,9 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from .const import _LOGGER, DOMAIN, UOM_INDEX
|
||||
from .const import _LOGGER, UOM_INDEX
|
||||
from .entity import ISYAuxControlEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
def time_string(i: int) -> str:
|
||||
@ -55,11 +54,11 @@ BACKLIGHT_MEMORY_FILTER = {"memory": DEV_BL_ADDR, "cmd1": DEV_CMD_MEMORY_WRITE}
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up ISY/IoX select entities from config entry."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
isy_data = config_entry.runtime_data
|
||||
device_info = isy_data.devices
|
||||
entities: list[
|
||||
ISYAuxControlIndexSelectEntity
|
||||
|
@ -29,7 +29,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory, Platform, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
@ -37,7 +36,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
DOMAIN,
|
||||
UOM_DOUBLE_TEMP,
|
||||
UOM_FRIENDLY_NAME,
|
||||
UOM_INDEX,
|
||||
@ -46,7 +44,7 @@ from .const import (
|
||||
)
|
||||
from .entity import ISYNodeEntity
|
||||
from .helpers import convert_isy_value_to_hass
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
# Disable general purpose and redundant sensors by default
|
||||
AUX_DISABLED_BY_DEFAULT_MATCH = ["GV", "DO"]
|
||||
@ -109,13 +107,13 @@ ISY_CONTROL_TO_ENTITY_CATEGORY = {
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY sensor platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
isy_data = entry.runtime_data
|
||||
entities: list[ISYSensorEntity] = []
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
devices = isy_data.devices
|
||||
|
||||
for node in isy_data.nodes[Platform.SENSOR]:
|
||||
_LOGGER.debug("Loading %s", node.name)
|
||||
|
@ -21,7 +21,7 @@ from homeassistant.helpers.service import entity_service_call
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
# Common Services for All Platforms:
|
||||
SERVICE_SEND_PROGRAM_COMMAND = "send_program_command"
|
||||
@ -149,9 +149,9 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
command = service.data[CONF_COMMAND]
|
||||
isy_name = service.data.get(CONF_ISY)
|
||||
|
||||
for config_entry_id in hass.data[DOMAIN]:
|
||||
isy_data: IsyData = hass.data[DOMAIN][config_entry_id]
|
||||
isy = isy_data.root
|
||||
config_entry: IsyConfigEntry
|
||||
for config_entry in hass.config_entries.async_loaded_entries(DOMAIN):
|
||||
isy = config_entry.runtime_data.root
|
||||
if isy_name and isy_name != isy.conf["name"]:
|
||||
continue
|
||||
program = None
|
||||
@ -235,10 +235,6 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
@callback
|
||||
def async_unload_services(hass: HomeAssistant) -> None:
|
||||
"""Unload services for the ISY integration."""
|
||||
if hass.data[DOMAIN]:
|
||||
# There is still another config entry for this domain, don't remove services.
|
||||
return
|
||||
|
||||
existing_services = hass.services.async_services_for_domain(DOMAIN)
|
||||
if not existing_services or SERVICE_SEND_PROGRAM_COMMAND not in existing_services:
|
||||
return
|
||||
|
@ -20,16 +20,14 @@ from homeassistant.components.switch import (
|
||||
SwitchEntity,
|
||||
SwitchEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory, Platform
|
||||
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 .const import DOMAIN
|
||||
from .entity import ISYAuxControlEntity, ISYNodeEntity, ISYProgramEntity
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@ -43,11 +41,11 @@ class ISYSwitchEntityDescription(SwitchEntityDescription):
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: IsyConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the ISY switch platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
isy_data = entry.runtime_data
|
||||
entities: list[
|
||||
ISYSwitchProgramEntity | ISYSwitchEntity | ISYEnableSwitchEntity
|
||||
] = []
|
||||
|
@ -4,15 +4,12 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pyisy import ISY
|
||||
|
||||
from homeassistant.components import system_health
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from .const import DOMAIN, ISY_URL_POSTFIX
|
||||
from .models import IsyData
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
@callback
|
||||
@ -27,14 +24,9 @@ async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
|
||||
"""Get info for the info page."""
|
||||
|
||||
health_info = {}
|
||||
config_entry_id = next(
|
||||
iter(hass.data[DOMAIN])
|
||||
) # Only first ISY is supported for now
|
||||
isy_data: IsyData = hass.data[DOMAIN][config_entry_id]
|
||||
isy: ISY = isy_data.root
|
||||
entry: IsyConfigEntry = hass.config_entries.async_loaded_entries(DOMAIN)[0]
|
||||
isy = entry.runtime_data.root
|
||||
|
||||
entry = hass.config_entries.async_get_entry(config_entry_id)
|
||||
assert isinstance(entry, ConfigEntry)
|
||||
health_info["host_reachable"] = await system_health.async_check_can_reach_url(
|
||||
hass, f"{entry.data[CONF_HOST]}{ISY_URL_POSTFIX}"
|
||||
)
|
||||
|
@ -5,16 +5,19 @@ from __future__ import annotations
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .const import _LOGGER
|
||||
from .models import IsyConfigEntry
|
||||
|
||||
|
||||
@callback
|
||||
def _async_cleanup_registry_entries(hass: HomeAssistant, entry_id: str) -> None:
|
||||
def _async_cleanup_registry_entries(hass: HomeAssistant, entry: IsyConfigEntry) -> None:
|
||||
"""Remove extra entities that are no longer part of the integration."""
|
||||
entity_registry = er.async_get(hass)
|
||||
isy_data = hass.data[DOMAIN][entry_id]
|
||||
isy_data = entry.runtime_data
|
||||
|
||||
existing_entries = er.async_entries_for_config_entry(entity_registry, entry_id)
|
||||
existing_entries = er.async_entries_for_config_entry(
|
||||
entity_registry, entry.entry_id
|
||||
)
|
||||
entities = {
|
||||
(entity.domain, entity.unique_id): entity.entity_id
|
||||
for entity in existing_entries
|
||||
@ -31,5 +34,5 @@ def _async_cleanup_registry_entries(hass: HomeAssistant, entry_id: str) -> None:
|
||||
_LOGGER.debug(
|
||||
("Cleaning up ISY entities: removed %s extra entities for config entry %s"),
|
||||
len(extra_entities),
|
||||
entry_id,
|
||||
entry.entry_id,
|
||||
)
|
||||
|
@ -6,6 +6,7 @@ from unittest.mock import Mock
|
||||
from aiohttp import ClientError
|
||||
|
||||
from homeassistant.components.isy994.const import DOMAIN, ISY_URL_POSTFIX
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
@ -30,12 +31,14 @@ async def test_system_health(
|
||||
assert await async_setup_component(hass, "system_health", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
MockConfigEntry(
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
entry_id=MOCK_ENTRY_ID,
|
||||
data={CONF_HOST: f"http://{MOCK_HOSTNAME}"},
|
||||
unique_id=MOCK_UUID,
|
||||
).add_to_hass(hass)
|
||||
state=ConfigEntryState.LOADED,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
isy_data = Mock(
|
||||
root=Mock(
|
||||
@ -46,7 +49,7 @@ async def test_system_health(
|
||||
),
|
||||
)
|
||||
)
|
||||
hass.data[DOMAIN] = {MOCK_ENTRY_ID: isy_data}
|
||||
entry.runtime_data = isy_data
|
||||
|
||||
info = await get_system_health_info(hass, DOMAIN)
|
||||
|
||||
@ -70,12 +73,14 @@ async def test_system_health_failed_connect(
|
||||
assert await async_setup_component(hass, "system_health", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
MockConfigEntry(
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
entry_id=MOCK_ENTRY_ID,
|
||||
data={CONF_HOST: f"http://{MOCK_HOSTNAME}"},
|
||||
unique_id=MOCK_UUID,
|
||||
).add_to_hass(hass)
|
||||
state=ConfigEntryState.LOADED,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
isy_data = Mock(
|
||||
root=Mock(
|
||||
@ -86,7 +91,7 @@ async def test_system_health_failed_connect(
|
||||
),
|
||||
)
|
||||
)
|
||||
hass.data[DOMAIN] = {MOCK_ENTRY_ID: isy_data}
|
||||
entry.runtime_data = isy_data
|
||||
|
||||
info = await get_system_health_info(hass, DOMAIN)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user