Use runtime_data in homematicip_cloud (#144892)

This commit is contained in:
epenet 2025-05-14 23:14:02 +02:00 committed by GitHub
parent 3b9d8e00bc
commit 34c7c3f384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 97 additions and 219 deletions

View File

@ -3,7 +3,6 @@
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import (
@ -21,7 +20,7 @@ from .const import (
HMIPC_HAPID,
HMIPC_NAME,
)
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
from .services import async_setup_services, async_unload_services
CONFIG_SCHEMA = vol.Schema(
@ -45,8 +44,6 @@ CONFIG_SCHEMA = vol.Schema(
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the HomematicIP Cloud component."""
hass.data[DOMAIN] = {}
accesspoints = config.get(DOMAIN, [])
for conf in accesspoints:
@ -69,7 +66,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: HomematicIPConfigEntry) -> bool:
"""Set up an access point from a config entry."""
# 0.104 introduced config entry unique id, this makes upgrading possible
@ -81,8 +78,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
hap = HomematicipHAP(hass, entry)
hass.data[DOMAIN][entry.unique_id] = hap
entry.runtime_data = hap
if not await hap.async_setup():
return False
@ -110,9 +107,12 @@ 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: HomematicIPConfigEntry
) -> bool:
"""Unload a config entry."""
hap = hass.data[DOMAIN].pop(entry.unique_id)
hap = entry.runtime_data
assert hap.reset_connection_listener is not None
hap.reset_connection_listener()
await async_unload_services(hass)
@ -122,7 +122,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@callback
def _async_remove_obsolete_entities(
hass: HomeAssistant, entry: ConfigEntry, hap: HomematicipHAP
hass: HomeAssistant, entry: HomematicIPConfigEntry, hap: HomematicipHAP
):
"""Remove obsolete entities from entity registry."""

View File

@ -11,13 +11,12 @@ from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntityFeature,
AlarmControlPanelState,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .hap import AsyncHome, HomematicipHAP
from .hap import AsyncHome, HomematicIPConfigEntry, HomematicipHAP
_LOGGER = logging.getLogger(__name__)
@ -26,11 +25,11 @@ CONST_ALARM_CONTROL_PANEL_NAME = "HmIP Alarm Control Panel"
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP alrm control panel from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
async_add_entities([HomematicipAlarmControlPanelEntity(hap)])

View File

@ -34,14 +34,13 @@ from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
ATTR_ACCELERATION_SENSOR_MODE = "acceleration_sensor_mode"
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION = "acceleration_sensor_neutral_position"
@ -75,11 +74,11 @@ SAM_DEVICE_ATTRIBUTES = {
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP Cloud binary sensor from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = [HomematicipCloudConnectionSensor(hap)]
for device in hap.home.devices:
if isinstance(device, AccelerationSensor):

View File

@ -5,22 +5,20 @@ from __future__ import annotations
from homematicip.device import WallMountedGarageDoorController
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP button from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
async_add_entities(
HomematicipGarageDoorControllerButton(hap, device)

View File

@ -24,7 +24,6 @@ from homeassistant.components.climate import (
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
@ -32,7 +31,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
HEATING_PROFILES = {"PROFILE_1": 0, "PROFILE_2": 1, "PROFILE_3": 2}
COOLING_PROFILES = {"PROFILE_4": 3, "PROFILE_5": 4, "PROFILE_6": 5}
@ -55,11 +54,11 @@ HMIP_ECO_CM = "ECO"
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP climate from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
async_add_entities(
HomematicipHeatingGroup(hap, device)

View File

@ -21,13 +21,11 @@ from homeassistant.components.cover import (
CoverDeviceClass,
CoverEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
HMIP_COVER_OPEN = 0
HMIP_COVER_CLOSED = 1
@ -37,11 +35,11 @@ HMIP_SLATS_CLOSED = 1
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP cover from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = [
HomematicipCoverShutterGroup(hap, group)
for group in hap.home.groups

View File

@ -13,13 +13,11 @@ from homeassistant.components.event import (
EventEntity,
EventEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
@dataclass(frozen=True, kw_only=True)
@ -44,11 +42,11 @@ EVENT_DESCRIPTIONS = {
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP cover from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = []
entities.extend(

View File

@ -25,6 +25,8 @@ from .errors import HmipcConnectionError
_LOGGER = logging.getLogger(__name__)
type HomematicIPConfigEntry = ConfigEntry[HomematicipHAP]
async def build_context_async(
hass: HomeAssistant, hapid: str | None, authtoken: str | None
@ -102,7 +104,9 @@ class HomematicipHAP:
home: AsyncHome
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
def __init__(
self, hass: HomeAssistant, config_entry: HomematicIPConfigEntry
) -> None:
"""Initialize HomematicIP Cloud connection."""
self.hass = hass
self.config_entry = config_entry

View File

@ -28,22 +28,20 @@ from homeassistant.components.light import (
LightEntity,
LightEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP Cloud lights from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, BrandSwitchMeasuring):

View File

@ -9,12 +9,11 @@ from homematicip.base.enums import LockState, MotorState
from homematicip.device import DoorLockDrive
from homeassistant.components.lock import LockEntity, LockEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicIPConfigEntry
from .helpers import handle_errors
_LOGGER = logging.getLogger(__name__)
@ -36,11 +35,11 @@ DEVICE_DLD_ATTRIBUTES = {
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP locks from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
async_add_entities(
HomematicipDoorLockDrive(hap, device)

View File

@ -44,7 +44,6 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
LIGHT_LUX,
@ -61,9 +60,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import StateType
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
from .helpers import get_channels_from_device
ATTR_CURRENT_ILLUMINATION = "current_illumination"
@ -96,11 +94,11 @@ ILLUMINATION_DEVICE_ATTRIBUTES = {
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP Cloud sensors from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, HomeControlAccessPoint):

View File

@ -22,6 +22,7 @@ from homeassistant.helpers.service import (
)
from .const import DOMAIN
from .hap import HomematicIPConfigEntry
_LOGGER = logging.getLogger(__name__)
@ -218,7 +219,7 @@ async def async_setup_services(hass: HomeAssistant) -> None:
async def async_unload_services(hass: HomeAssistant):
"""Unload HomematicIP Cloud services."""
if hass.data[DOMAIN]:
if hass.config_entries.async_loaded_entries(DOMAIN):
return
for hmipc_service in HMIPC_SERVICES:
@ -235,8 +236,9 @@ async def _async_activate_eco_mode_with_duration(
if home := _get_home(hass, hapid):
await home.activate_absence_with_duration_async(duration)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_absence_with_duration_async(duration)
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.activate_absence_with_duration_async(duration)
async def _async_activate_eco_mode_with_period(
@ -249,8 +251,9 @@ async def _async_activate_eco_mode_with_period(
if home := _get_home(hass, hapid):
await home.activate_absence_with_period_async(endtime)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_absence_with_period_async(endtime)
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.activate_absence_with_period_async(endtime)
async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) -> None:
@ -262,8 +265,9 @@ async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) ->
if home := _get_home(hass, hapid):
await home.activate_vacation_async(endtime, temperature)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_vacation_async(endtime, temperature)
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.activate_vacation_async(endtime, temperature)
async def _async_deactivate_eco_mode(hass: HomeAssistant, service: ServiceCall) -> None:
@ -272,8 +276,9 @@ async def _async_deactivate_eco_mode(hass: HomeAssistant, service: ServiceCall)
if home := _get_home(hass, hapid):
await home.deactivate_absence_async()
else:
for hap in hass.data[DOMAIN].values():
await hap.home.deactivate_absence_async()
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.deactivate_absence_async()
async def _async_deactivate_vacation(hass: HomeAssistant, service: ServiceCall) -> None:
@ -282,8 +287,9 @@ async def _async_deactivate_vacation(hass: HomeAssistant, service: ServiceCall)
if home := _get_home(hass, hapid):
await home.deactivate_vacation_async()
else:
for hap in hass.data[DOMAIN].values():
await hap.home.deactivate_vacation_async()
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.deactivate_vacation_async()
async def _set_active_climate_profile(
@ -293,14 +299,15 @@ async def _set_active_climate_profile(
entity_id_list = service.data[ATTR_ENTITY_ID]
climate_profile_index = service.data[ATTR_CLIMATE_PROFILE_INDEX] - 1
for hap in hass.data[DOMAIN].values():
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
if entity_id_list != "all":
for entity_id in entity_id_list:
group = hap.hmip_device_by_entity_id.get(entity_id)
group = entry.runtime_data.hmip_device_by_entity_id.get(entity_id)
if group and isinstance(group, HeatingGroup):
await group.set_active_profile_async(climate_profile_index)
else:
for group in hap.home.groups:
for group in entry.runtime_data.home.groups:
if isinstance(group, HeatingGroup):
await group.set_active_profile_async(climate_profile_index)
@ -313,8 +320,10 @@ async def _async_dump_hap_config(hass: HomeAssistant, service: ServiceCall) -> N
config_file_prefix = service.data[ATTR_CONFIG_OUTPUT_FILE_PREFIX]
anonymize = service.data[ATTR_ANONYMIZE]
for hap in hass.data[DOMAIN].values():
hap_sgtin = hap.config_entry.unique_id
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
hap_sgtin = entry.unique_id
assert hap_sgtin is not None
if anonymize:
hap_sgtin = hap_sgtin[-4:]
@ -323,7 +332,7 @@ async def _async_dump_hap_config(hass: HomeAssistant, service: ServiceCall) -> N
path = Path(config_path)
config_file = path / file_name
json_state = await hap.home.download_configuration_async()
json_state = await entry.runtime_data.home.download_configuration_async()
json_state = handle_config(json_state, anonymize)
config_file.write_text(json_state, encoding="utf8")
@ -333,14 +342,15 @@ async def _async_reset_energy_counter(hass: HomeAssistant, service: ServiceCall)
"""Service to reset the energy counter."""
entity_id_list = service.data[ATTR_ENTITY_ID]
for hap in hass.data[DOMAIN].values():
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
if entity_id_list != "all":
for entity_id in entity_id_list:
device = hap.hmip_device_by_entity_id.get(entity_id)
device = entry.runtime_data.hmip_device_by_entity_id.get(entity_id)
if device and isinstance(device, SwitchMeasuring):
await device.reset_energy_counter_async()
else:
for device in hap.home.devices:
for device in entry.runtime_data.home.devices:
if isinstance(device, SwitchMeasuring):
await device.reset_energy_counter_async()
@ -353,14 +363,17 @@ async def _async_set_home_cooling_mode(hass: HomeAssistant, service: ServiceCall
if home := _get_home(hass, hapid):
await home.set_cooling_async(cooling)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.set_cooling_async(cooling)
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
await entry.runtime_data.home.set_cooling_async(cooling)
def _get_home(hass: HomeAssistant, hapid: str) -> AsyncHome | None:
"""Return a HmIP home."""
if hap := hass.data[DOMAIN].get(hapid):
return hap.home
entry: HomematicIPConfigEntry
for entry in hass.config_entries.async_loaded_entries(DOMAIN):
if entry.unique_id == hapid:
return entry.runtime_data.home
raise ServiceValidationError(
translation_domain=DOMAIN,

View File

@ -23,22 +23,20 @@ from homematicip.device import (
from homematicip.group import ExtendedLinkedSwitchingGroup, SwitchingGroup
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import ATTR_GROUP_MEMBER_UNREACHABLE, HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP switch from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = [
HomematicipGroupSwitch(hap, group)
for group in hap.home.groups

View File

@ -18,14 +18,12 @@ from homeassistant.components.weather import (
ATTR_CONDITION_WINDY,
WeatherEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfSpeed, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DOMAIN
from .entity import HomematicipGenericEntity
from .hap import HomematicipHAP
from .hap import HomematicIPConfigEntry, HomematicipHAP
HOME_WEATHER_CONDITION = {
WeatherCondition.CLEAR: ATTR_CONDITION_SUNNY,
@ -48,11 +46,11 @@ HOME_WEATHER_CONDITION = {
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: HomematicIPConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the HomematicIP weather sensor from a config entry."""
hap = hass.data[DOMAIN][config_entry.unique_id]
hap = config_entry.runtime_data
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, WeatherSensorPro):

View File

@ -97,7 +97,8 @@ async def mock_hap_with_service_fixture(
mock_hap = await default_mock_hap_factory.async_get_mock_hap()
await hmip_async_setup(hass, dummy_config)
await hass.async_block_till_done()
hass.data[HMIPC_DOMAIN] = {HAPID: mock_hap}
entry = hass.config_entries.async_entries(HMIPC_DOMAIN)[0]
entry.runtime_data = mock_hap
return mock_hap

View File

@ -120,7 +120,7 @@ class HomeFactory:
await self.hass.async_block_till_done()
hap = self.hass.data[HMIPC_DOMAIN][HAPID]
hap = self.hmip_config_entry.runtime_data
mock_home.on_update(hap.async_update)
mock_home.on_create(hap.async_create_entity)
return hap

View File

@ -2,13 +2,8 @@
from homematicip.async_home import AsyncHome
from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
AlarmControlPanelState,
)
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.alarm_control_panel import AlarmControlPanelState
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, get_and_check_entity_basics
@ -39,17 +34,6 @@ async def _async_manipulate_security_zones(
await hass.async_block_till_done()
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass,
ALARM_CONTROL_PANEL_DOMAIN,
{ALARM_CONTROL_PANEL_DOMAIN: {"platform": HMIPC_DOMAIN}},
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_alarm_control_panel(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -2,8 +2,6 @@
from homematicip.base.enums import SmokeDetectorAlarmType, WindowState
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.binary_sensor import (
ATTR_ACCELERATION_SENSOR_MODE,
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION,
@ -25,21 +23,10 @@ from homeassistant.components.homematicip_cloud.entity import (
)
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass,
BINARY_SENSOR_DOMAIN,
{BINARY_SENSOR_DOMAIN: {"platform": HMIPC_DOMAIN}},
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_home_cloud_connection_sensor(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -12,7 +12,6 @@ from homeassistant.components.climate import (
ATTR_HVAC_ACTION,
ATTR_PRESET_MODE,
ATTR_PRESET_MODES,
DOMAIN as CLIMATE_DOMAIN,
PRESET_AWAY,
PRESET_BOOST,
PRESET_ECO,
@ -26,7 +25,6 @@ from homeassistant.components.homematicip_cloud.climate import (
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.setup import async_setup_component
from .helper import (
HAPID,
@ -36,14 +34,6 @@ from .helper import (
)
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, CLIMATE_DOMAIN, {CLIMATE_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_heating_group_heat(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -5,25 +5,14 @@ from homematicip.base.enums import DoorCommand, DoorState
from homeassistant.components.cover import (
ATTR_CURRENT_POSITION,
ATTR_CURRENT_TILT_POSITION,
DOMAIN as COVER_DOMAIN,
CoverState,
)
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.const import STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, COVER_DOMAIN, {COVER_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_cover_shutter(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -4,18 +4,12 @@ from unittest.mock import patch
from homematicip.base.enums import EventType
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .helper import (
HAPID,
HomeFactory,
async_manipulate_test_data,
get_and_check_entity_basics,
)
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
from tests.common import MockConfigEntry
@ -115,7 +109,7 @@ async def test_hmip_add_device(
assert len(device_registry.devices) == pre_device_count
assert len(entity_registry.entities) == pre_entity_count
new_hap = hass.data[HMIPC_DOMAIN][HAPID]
new_hap = hmip_config_entry.runtime_data
assert len(new_hap.hmip_device_by_entity_id) == pre_mapping_count

View File

@ -119,14 +119,13 @@ async def test_hap_reset_unloads_entry_if_setup(
) -> None:
"""Test calling reset while the entry has been setup."""
mock_hap = await default_mock_hap_factory.async_get_mock_hap()
assert hass.data[HMIPC_DOMAIN][HAPID] == mock_hap
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
assert len(config_entries) == 1
assert config_entries[0].runtime_data == mock_hap
# hap_reset is called during unload
await hass.config_entries.async_unload(config_entries[0].entry_id)
# entry is unloaded
assert config_entries[0].state is ConfigEntryState.NOT_LOADED
assert hass.data[HMIPC_DOMAIN] == {}
async def test_hap_create(

View File

@ -34,8 +34,6 @@ async def test_config_with_accesspoint_passed_to_config_entry(
}
# no config_entry exists
assert len(hass.config_entries.async_entries(HMIPC_DOMAIN)) == 0
# no acccesspoint exists
assert not hass.data.get(HMIPC_DOMAIN)
with patch(
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
@ -53,7 +51,7 @@ async def test_config_with_accesspoint_passed_to_config_entry(
"name": "name",
}
# defined access_point created for config_entry
assert isinstance(hass.data[HMIPC_DOMAIN]["ABC123"], HomematicipHAP)
assert isinstance(config_entries[0].runtime_data, HomematicipHAP)
async def test_config_already_registered_not_passed_to_config_entry(
@ -118,7 +116,7 @@ async def test_load_entry_fails_due_to_connection_error(
):
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id]
assert hmip_config_entry.runtime_data
assert hmip_config_entry.state is ConfigEntryState.SETUP_RETRY
@ -136,7 +134,7 @@ async def test_load_entry_fails_due_to_generic_exception(
):
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id]
assert hmip_config_entry.runtime_data
assert hmip_config_entry.state is ConfigEntryState.SETUP_ERROR
@ -159,14 +157,12 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
assert mock_hap.return_value.mock_calls[0][0] == "async_setup"
assert hass.data[HMIPC_DOMAIN]["ABC123"]
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
assert len(config_entries) == 1
assert config_entries[0].runtime_data
assert config_entries[0].state is ConfigEntryState.LOADED
await hass.config_entries.async_unload(config_entries[0].entry_id)
assert config_entries[0].state is ConfigEntryState.NOT_LOADED
# entry is unloaded
assert hass.data[HMIPC_DOMAIN] == {}
async def test_hmip_dump_hap_config_services(

View File

@ -2,7 +2,6 @@
from homematicip.base.enums import OpticalSignalBehaviour, RGBColorState
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
@ -10,25 +9,15 @@ from homeassistant.components.light import (
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
DOMAIN as LIGHT_DOMAIN,
ColorMode,
LightEntityFeature,
)
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_light(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -5,28 +5,14 @@ from unittest.mock import patch
from homematicip.base.enums import LockState as HomematicLockState, MotorState
import pytest
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.lock import (
DOMAIN as LOCK_DOMAIN,
LockEntityFeature,
LockState,
)
from homeassistant.components.lock import LockEntityFeature, LockState
from homeassistant.const import ATTR_SUPPORTED_FEATURES
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, LOCK_DOMAIN, {LOCK_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_doorlockdrive(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -2,7 +2,6 @@
from homematicip.base.enums import ValveState
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.entity import (
ATTR_CONFIG_PENDING,
ATTR_DEVICE_OVERHEATED,
@ -23,11 +22,7 @@ from homeassistant.components.homematicip_cloud.sensor import (
ATTR_WIND_DIRECTION,
ATTR_WIND_DIRECTION_VARIATION,
)
from homeassistant.components.sensor import (
ATTR_STATE_CLASS,
DOMAIN as SENSOR_DOMAIN,
SensorStateClass,
)
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
LIGHT_LUX,
@ -39,19 +34,10 @@ from homeassistant.const import (
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_accesspoint_status(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -1,25 +1,14 @@
"""Tests for HomematicIP Cloud switch."""
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.entity import (
ATTR_GROUP_MEMBER_UNREACHABLE,
)
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_switch(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:

View File

@ -1,28 +1,17 @@
"""Tests for HomematicIP Cloud weather."""
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.weather import (
ATTR_WEATHER_HUMIDITY,
ATTR_WEATHER_TEMPERATURE,
ATTR_WEATHER_WIND_BEARING,
ATTR_WEATHER_WIND_SPEED,
DOMAIN as WEATHER_DOMAIN,
)
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
"""Test that we do not set up an access point."""
assert await async_setup_component(
hass, WEATHER_DOMAIN, {WEATHER_DOMAIN: {"platform": HMIPC_DOMAIN}}
)
assert not hass.data.get(HMIPC_DOMAIN)
async def test_hmip_weather_sensor(
hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None: