Refactor homematicip_cloud connection (#139081)

This commit is contained in:
hahn-th 2025-04-14 15:01:55 +02:00 committed by GitHub
parent 83c3275054
commit 6d74a6aa19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 508 additions and 475 deletions

View File

@ -82,15 +82,15 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
await self._home.set_security_zones_activation(False, False)
await self._home.set_security_zones_activation_async(False, False)
async def async_alarm_arm_home(self, code: str | None = None) -> None:
"""Send arm home command."""
await self._home.set_security_zones_activation(False, True)
await self._home.set_security_zones_activation_async(False, True)
async def async_alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command."""
await self._home.set_security_zones_activation(True, True)
await self._home.set_security_zones_activation_async(True, True)
async def async_added_to_hass(self) -> None:
"""Register callbacks."""

View File

@ -4,31 +4,31 @@ from __future__ import annotations
from typing import Any
from homematicip.aio.device import (
AsyncAccelerationSensor,
AsyncContactInterface,
AsyncDevice,
AsyncFullFlushContactInterface,
AsyncFullFlushContactInterface6,
AsyncMotionDetectorIndoor,
AsyncMotionDetectorOutdoor,
AsyncMotionDetectorPushButton,
AsyncPluggableMainsFailureSurveillance,
AsyncPresenceDetectorIndoor,
AsyncRainSensor,
AsyncRotaryHandleSensor,
AsyncShutterContact,
AsyncShutterContactMagnetic,
AsyncSmokeDetector,
AsyncTiltVibrationSensor,
AsyncWaterSensor,
AsyncWeatherSensor,
AsyncWeatherSensorPlus,
AsyncWeatherSensorPro,
AsyncWiredInput32,
)
from homematicip.aio.group import AsyncSecurityGroup, AsyncSecurityZoneGroup
from homematicip.base.enums import SmokeDetectorAlarmType, WindowState
from homematicip.device import (
AccelerationSensor,
ContactInterface,
Device,
FullFlushContactInterface,
FullFlushContactInterface6,
MotionDetectorIndoor,
MotionDetectorOutdoor,
MotionDetectorPushButton,
PluggableMainsFailureSurveillance,
PresenceDetectorIndoor,
RainSensor,
RotaryHandleSensor,
ShutterContact,
ShutterContactMagnetic,
SmokeDetector,
TiltVibrationSensor,
WaterSensor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
WiredInput32,
)
from homematicip.group import SecurityGroup, SecurityZoneGroup
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
@ -82,66 +82,60 @@ async def async_setup_entry(
hap = hass.data[DOMAIN][config_entry.unique_id]
entities: list[HomematicipGenericEntity] = [HomematicipCloudConnectionSensor(hap)]
for device in hap.home.devices:
if isinstance(device, AsyncAccelerationSensor):
if isinstance(device, AccelerationSensor):
entities.append(HomematicipAccelerationSensor(hap, device))
if isinstance(device, AsyncTiltVibrationSensor):
if isinstance(device, TiltVibrationSensor):
entities.append(HomematicipTiltVibrationSensor(hap, device))
if isinstance(device, AsyncWiredInput32):
if isinstance(device, WiredInput32):
entities.extend(
HomematicipMultiContactInterface(hap, device, channel=channel)
for channel in range(1, 33)
)
elif isinstance(device, AsyncFullFlushContactInterface6):
elif isinstance(device, FullFlushContactInterface6):
entities.extend(
HomematicipMultiContactInterface(hap, device, channel=channel)
for channel in range(1, 7)
)
elif isinstance(
device, (AsyncContactInterface, AsyncFullFlushContactInterface)
):
elif isinstance(device, (ContactInterface, FullFlushContactInterface)):
entities.append(HomematicipContactInterface(hap, device))
if isinstance(
device,
(AsyncShutterContact, AsyncShutterContactMagnetic),
(ShutterContact, ShutterContactMagnetic),
):
entities.append(HomematicipShutterContact(hap, device))
if isinstance(device, AsyncRotaryHandleSensor):
if isinstance(device, RotaryHandleSensor):
entities.append(HomematicipShutterContact(hap, device, True))
if isinstance(
device,
(
AsyncMotionDetectorIndoor,
AsyncMotionDetectorOutdoor,
AsyncMotionDetectorPushButton,
MotionDetectorIndoor,
MotionDetectorOutdoor,
MotionDetectorPushButton,
),
):
entities.append(HomematicipMotionDetector(hap, device))
if isinstance(device, AsyncPluggableMainsFailureSurveillance):
if isinstance(device, PluggableMainsFailureSurveillance):
entities.append(
HomematicipPluggableMainsFailureSurveillanceSensor(hap, device)
)
if isinstance(device, AsyncPresenceDetectorIndoor):
if isinstance(device, PresenceDetectorIndoor):
entities.append(HomematicipPresenceDetector(hap, device))
if isinstance(device, AsyncSmokeDetector):
if isinstance(device, SmokeDetector):
entities.append(HomematicipSmokeDetector(hap, device))
if isinstance(device, AsyncWaterSensor):
if isinstance(device, WaterSensor):
entities.append(HomematicipWaterDetector(hap, device))
if isinstance(
device, (AsyncRainSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
):
if isinstance(device, (RainSensor, WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipRainSensor(hap, device))
if isinstance(
device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
):
if isinstance(device, (WeatherSensor, WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipStormSensor(hap, device))
entities.append(HomematicipSunshineSensor(hap, device))
if isinstance(device, AsyncDevice) and device.lowBat is not None:
if isinstance(device, Device) and device.lowBat is not None:
entities.append(HomematicipBatterySensor(hap, device))
for group in hap.home.groups:
if isinstance(group, AsyncSecurityGroup):
if isinstance(group, SecurityGroup):
entities.append(HomematicipSecuritySensorGroup(hap, device=group))
elif isinstance(group, AsyncSecurityZoneGroup):
elif isinstance(group, SecurityZoneGroup):
entities.append(HomematicipSecurityZoneSensorGroup(hap, device=group))
async_add_entities(entities)

View File

@ -2,7 +2,7 @@
from __future__ import annotations
from homematicip.aio.device import AsyncWallMountedGarageDoorController
from homematicip.device import WallMountedGarageDoorController
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
@ -25,7 +25,7 @@ async def async_setup_entry(
async_add_entities(
HomematicipGarageDoorControllerButton(hap, device)
for device in hap.home.devices
if isinstance(device, AsyncWallMountedGarageDoorController)
if isinstance(device, WallMountedGarageDoorController)
)
@ -39,4 +39,4 @@ class HomematicipGarageDoorControllerButton(HomematicipGenericEntity, ButtonEnti
async def async_press(self) -> None:
"""Handle the button press."""
await self._device.send_start_impulse()
await self._device.send_start_impulse_async()

View File

@ -4,16 +4,15 @@ from __future__ import annotations
from typing import Any
from homematicip.aio.device import (
AsyncHeatingThermostat,
AsyncHeatingThermostatCompact,
AsyncHeatingThermostatEvo,
)
from homematicip.aio.group import AsyncHeatingGroup
from homematicip.base.enums import AbsenceType
from homematicip.device import Switch
from homematicip.device import (
HeatingThermostat,
HeatingThermostatCompact,
HeatingThermostatEvo,
Switch,
)
from homematicip.functionalHomes import IndoorClimateHome
from homematicip.group import HeatingCoolingProfile
from homematicip.group import HeatingCoolingProfile, HeatingGroup
from homeassistant.components.climate import (
PRESET_AWAY,
@ -65,7 +64,7 @@ async def async_setup_entry(
async_add_entities(
HomematicipHeatingGroup(hap, device)
for device in hap.home.groups
if isinstance(device, AsyncHeatingGroup)
if isinstance(device, HeatingGroup)
)
@ -82,7 +81,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
)
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None:
def __init__(self, hap: HomematicipHAP, device: HeatingGroup) -> None:
"""Initialize heating group."""
device.modelType = "HmIP-Heating-Group"
super().__init__(hap, device)
@ -214,7 +213,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
return
if self.min_temp <= temperature <= self.max_temp:
await self._device.set_point_temperature(temperature)
await self._device.set_point_temperature_async(temperature)
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
@ -222,23 +221,23 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
return
if hvac_mode == HVACMode.AUTO:
await self._device.set_control_mode(HMIP_AUTOMATIC_CM)
await self._device.set_control_mode_async(HMIP_AUTOMATIC_CM)
else:
await self._device.set_control_mode(HMIP_MANUAL_CM)
await self._device.set_control_mode_async(HMIP_MANUAL_CM)
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if self._device.boostMode and preset_mode != PRESET_BOOST:
await self._device.set_boost(False)
await self._device.set_boost_async(False)
if preset_mode == PRESET_BOOST:
await self._device.set_boost()
await self._device.set_boost_async()
if preset_mode == PRESET_ECO:
await self._device.set_control_mode(HMIP_ECO_CM)
await self._device.set_control_mode_async(HMIP_ECO_CM)
if preset_mode in self._device_profile_names:
profile_idx = self._get_profile_idx_by_name(preset_mode)
if self._device.controlMode != HMIP_AUTOMATIC_CM:
await self.async_set_hvac_mode(HVACMode.AUTO)
await self._device.set_active_profile(profile_idx)
await self._device.set_active_profile_async(profile_idx)
@property
def extra_state_attributes(self) -> dict[str, Any]:
@ -332,20 +331,15 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
@property
def _first_radiator_thermostat(
self,
) -> (
AsyncHeatingThermostat
| AsyncHeatingThermostatCompact
| AsyncHeatingThermostatEvo
| None
):
) -> HeatingThermostat | HeatingThermostatCompact | HeatingThermostatEvo | None:
"""Return the first radiator thermostat from the hmip heating group."""
for device in self._device.devices:
if isinstance(
device,
(
AsyncHeatingThermostat,
AsyncHeatingThermostatCompact,
AsyncHeatingThermostatEvo,
HeatingThermostat,
HeatingThermostatCompact,
HeatingThermostatEvo,
),
):
return device

View File

@ -4,16 +4,16 @@ from __future__ import annotations
from typing import Any
from homematicip.aio.device import (
AsyncBlindModule,
AsyncDinRailBlind4,
AsyncFullFlushBlind,
AsyncFullFlushShutter,
AsyncGarageDoorModuleTormatic,
AsyncHoermannDrivesModule,
)
from homematicip.aio.group import AsyncExtendedLinkedShutterGroup
from homematicip.base.enums import DoorCommand, DoorState
from homematicip.device import (
BlindModule,
DinRailBlind4,
FullFlushBlind,
FullFlushShutter,
GarageDoorModuleTormatic,
HoermannDrivesModule,
)
from homematicip.group import ExtendedLinkedShutterGroup
from homeassistant.components.cover import (
ATTR_POSITION,
@ -45,23 +45,21 @@ async def async_setup_entry(
entities: list[HomematicipGenericEntity] = [
HomematicipCoverShutterGroup(hap, group)
for group in hap.home.groups
if isinstance(group, AsyncExtendedLinkedShutterGroup)
if isinstance(group, ExtendedLinkedShutterGroup)
]
for device in hap.home.devices:
if isinstance(device, AsyncBlindModule):
if isinstance(device, BlindModule):
entities.append(HomematicipBlindModule(hap, device))
elif isinstance(device, AsyncDinRailBlind4):
elif isinstance(device, DinRailBlind4):
entities.extend(
HomematicipMultiCoverSlats(hap, device, channel=channel)
for channel in range(1, 5)
)
elif isinstance(device, AsyncFullFlushBlind):
elif isinstance(device, FullFlushBlind):
entities.append(HomematicipCoverSlats(hap, device))
elif isinstance(device, AsyncFullFlushShutter):
elif isinstance(device, FullFlushShutter):
entities.append(HomematicipCoverShutter(hap, device))
elif isinstance(
device, (AsyncHoermannDrivesModule, AsyncGarageDoorModuleTormatic)
):
elif isinstance(device, (HoermannDrivesModule, GarageDoorModuleTormatic)):
entities.append(HomematicipGarageDoorModule(hap, device))
async_add_entities(entities)
@ -91,14 +89,14 @@ class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity):
position = kwargs[ATTR_POSITION]
# HmIP cover is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_primary_shading_level(primaryShadingLevel=level)
await self._device.set_primary_shading_level_async(primaryShadingLevel=level)
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific tilt position."""
position = kwargs[ATTR_TILT_POSITION]
# HmIP slats is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_secondary_shading_level(
await self._device.set_secondary_shading_level_async(
primaryShadingLevel=self._device.primaryShadingLevel,
secondaryShadingLevel=level,
)
@ -112,37 +110,37 @@ class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity):
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self._device.set_primary_shading_level(
await self._device.set_primary_shading_level_async(
primaryShadingLevel=HMIP_COVER_OPEN
)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
await self._device.set_primary_shading_level(
await self._device.set_primary_shading_level_async(
primaryShadingLevel=HMIP_COVER_CLOSED
)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the device if in motion."""
await self._device.stop()
await self._device.stop_async()
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the slats."""
await self._device.set_secondary_shading_level(
await self._device.set_secondary_shading_level_async(
primaryShadingLevel=self._device.primaryShadingLevel,
secondaryShadingLevel=HMIP_SLATS_OPEN,
)
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the slats."""
await self._device.set_secondary_shading_level(
await self._device.set_secondary_shading_level_async(
primaryShadingLevel=self._device.primaryShadingLevel,
secondaryShadingLevel=HMIP_SLATS_CLOSED,
)
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop the device if in motion."""
await self._device.stop()
await self._device.stop_async()
class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity):
@ -176,7 +174,7 @@ class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity):
position = kwargs[ATTR_POSITION]
# HmIP cover is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_shutter_level(level, self._channel)
await self._device.set_shutter_level_async(level, self._channel)
@property
def is_closed(self) -> bool | None:
@ -190,15 +188,15 @@ class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity):
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self._device.set_shutter_level(HMIP_COVER_OPEN, self._channel)
await self._device.set_shutter_level_async(HMIP_COVER_OPEN, self._channel)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
await self._device.set_shutter_level(HMIP_COVER_CLOSED, self._channel)
await self._device.set_shutter_level_async(HMIP_COVER_CLOSED, self._channel)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the device if in motion."""
await self._device.set_shutter_stop(self._channel)
await self._device.set_shutter_stop_async(self._channel)
class HomematicipCoverShutter(HomematicipMultiCoverShutter, CoverEntity):
@ -238,23 +236,25 @@ class HomematicipMultiCoverSlats(HomematicipMultiCoverShutter, CoverEntity):
position = kwargs[ATTR_TILT_POSITION]
# HmIP slats is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_slats_level(slatsLevel=level, channelIndex=self._channel)
await self._device.set_slats_level_async(
slatsLevel=level, channelIndex=self._channel
)
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the slats."""
await self._device.set_slats_level(
await self._device.set_slats_level_async(
slatsLevel=HMIP_SLATS_OPEN, channelIndex=self._channel
)
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the slats."""
await self._device.set_slats_level(
await self._device.set_slats_level_async(
slatsLevel=HMIP_SLATS_CLOSED, channelIndex=self._channel
)
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop the device if in motion."""
await self._device.set_shutter_stop(self._channel)
await self._device.set_shutter_stop_async(self._channel)
class HomematicipCoverSlats(HomematicipMultiCoverSlats, CoverEntity):
@ -288,15 +288,15 @@ class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self._device.send_door_command(DoorCommand.OPEN)
await self._device.send_door_command_async(DoorCommand.OPEN)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
await self._device.send_door_command(DoorCommand.CLOSE)
await self._device.send_door_command_async(DoorCommand.CLOSE)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the cover."""
await self._device.send_door_command(DoorCommand.STOP)
await self._device.send_door_command_async(DoorCommand.STOP)
class HomematicipCoverShutterGroup(HomematicipGenericEntity, CoverEntity):
@ -335,35 +335,35 @@ class HomematicipCoverShutterGroup(HomematicipGenericEntity, CoverEntity):
position = kwargs[ATTR_POSITION]
# HmIP cover is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_shutter_level(level)
await self._device.set_shutter_level_async(level)
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific tilt position."""
position = kwargs[ATTR_TILT_POSITION]
# HmIP slats is closed:1 -> open:0
level = 1 - position / 100.0
await self._device.set_slats_level(level)
await self._device.set_slats_level_async(level)
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
await self._device.set_shutter_level(HMIP_COVER_OPEN)
await self._device.set_shutter_level_async(HMIP_COVER_OPEN)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Close the cover."""
await self._device.set_shutter_level(HMIP_COVER_CLOSED)
await self._device.set_shutter_level_async(HMIP_COVER_CLOSED)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Stop the group if in motion."""
await self._device.set_shutter_stop()
await self._device.set_shutter_stop_async()
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
"""Open the slats."""
await self._device.set_slats_level(HMIP_SLATS_OPEN)
await self._device.set_slats_level_async(HMIP_SLATS_OPEN)
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Close the slats."""
await self._device.set_slats_level(HMIP_SLATS_CLOSED)
await self._device.set_slats_level_async(HMIP_SLATS_CLOSED)
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop the group if in motion."""
await self._device.set_shutter_stop()
await self._device.set_shutter_stop_async()

View File

@ -5,9 +5,9 @@ from __future__ import annotations
import logging
from typing import Any
from homematicip.aio.device import AsyncDevice
from homematicip.aio.group import AsyncGroup
from homematicip.base.functionalChannels import FunctionalChannel
from homematicip.device import Device
from homematicip.group import Group
from homeassistant.const import ATTR_ID
from homeassistant.core import callback
@ -100,7 +100,7 @@ class HomematicipGenericEntity(Entity):
def device_info(self) -> DeviceInfo | None:
"""Return device specific attributes."""
# Only physical devices should be HA devices.
if isinstance(self._device, AsyncDevice):
if isinstance(self._device, Device):
return DeviceInfo(
identifiers={
# Serial numbers of Homematic IP device
@ -237,14 +237,14 @@ class HomematicipGenericEntity(Entity):
"""Return the state attributes of the generic entity."""
state_attr = {}
if isinstance(self._device, AsyncDevice):
if isinstance(self._device, Device):
for attr, attr_key in DEVICE_ATTRIBUTES.items():
if attr_value := getattr(self._device, attr, None):
state_attr[attr_key] = attr_value
state_attr[ATTR_IS_GROUP] = False
if isinstance(self._device, AsyncGroup):
if isinstance(self._device, Group):
for attr, attr_key in GROUP_ATTRIBUTES.items():
if attr_value := getattr(self._device, attr, None):
state_attr[attr_key] = attr_value

View File

@ -3,7 +3,7 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING
from homematicip.aio.device import Device
from homematicip.device import Device
from homeassistant.components.event import (
EventDeviceClass,

View File

@ -7,15 +7,18 @@ from collections.abc import Callable
import logging
from typing import Any
from homematicip.aio.auth import AsyncAuth
from homematicip.aio.home import AsyncHome
from homematicip.async_home import AsyncHome
from homematicip.auth import Auth
from homematicip.base.base_connection import HmipConnectionError
from homematicip.base.enums import EventType
from homematicip.connection.connection_context import ConnectionContextBuilder
from homematicip.connection.rest_connection import RestConnection
import homeassistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.httpx_client import get_async_client
from .const import HMIPC_AUTHTOKEN, HMIPC_HAPID, HMIPC_NAME, HMIPC_PIN, PLATFORMS
from .errors import HmipcConnectionError
@ -23,10 +26,25 @@ from .errors import HmipcConnectionError
_LOGGER = logging.getLogger(__name__)
async def build_context_async(
hass: HomeAssistant, hapid: str | None, authtoken: str | None
):
"""Create a HomematicIP context object."""
ssl_ctx = homeassistant.util.ssl.get_default_context()
client_session = get_async_client(hass)
return await ConnectionContextBuilder.build_context_async(
accesspoint_id=hapid,
auth_token=authtoken,
ssl_ctx=ssl_ctx,
httpx_client_session=client_session,
)
class HomematicipAuth:
"""Manages HomematicIP client registration."""
auth: AsyncAuth
auth: Auth
def __init__(self, hass: HomeAssistant, config: dict[str, str]) -> None:
"""Initialize HomematicIP Cloud client registration."""
@ -46,27 +64,34 @@ class HomematicipAuth:
async def async_checkbutton(self) -> bool:
"""Check blue butten has been pressed."""
try:
return await self.auth.isRequestAcknowledged()
return await self.auth.is_request_acknowledged()
except HmipConnectionError:
return False
async def async_register(self):
"""Register client at HomematicIP."""
try:
authtoken = await self.auth.requestAuthToken()
await self.auth.confirmAuthToken(authtoken)
authtoken = await self.auth.request_auth_token()
await self.auth.confirm_auth_token(authtoken)
except HmipConnectionError:
return False
return authtoken
async def get_auth(self, hass: HomeAssistant, hapid, pin):
"""Create a HomematicIP access point object."""
auth = AsyncAuth(hass.loop, async_get_clientsession(hass))
context = await build_context_async(hass, hapid, None)
connection = RestConnection(
context,
log_status_exceptions=False,
httpx_client_session=get_async_client(hass),
)
# hass.loop
auth = Auth(connection, context.client_auth_token, hapid)
try:
await auth.init(hapid)
if pin:
auth.pin = pin
await auth.connectionRequest("HomeAssistant")
auth.set_pin(pin)
result = await auth.connection_request(hapid)
_LOGGER.debug("Connection request result: %s", result)
except HmipConnectionError:
return None
return auth
@ -156,7 +181,7 @@ class HomematicipHAP:
async def get_state(self) -> None:
"""Update HMIP state and tell Home Assistant."""
await self.home.get_current_state()
await self.home.get_current_state_async()
self.update_all()
def get_state_finished(self, future) -> None:
@ -187,8 +212,8 @@ class HomematicipHAP:
retry_delay = 2 ** min(tries, 8)
try:
await self.home.get_current_state()
hmip_events = await self.home.enable_events()
await self.home.get_current_state_async()
hmip_events = self.home.enable_events()
tries = 0
await hmip_events
except HmipConnectionError:
@ -219,7 +244,7 @@ class HomematicipHAP:
self._ws_close_requested = True
if self._retry_task is not None:
self._retry_task.cancel()
await self.home.disable_events()
await self.home.disable_events_async()
_LOGGER.debug("Closed connection to HomematicIP cloud server")
await self.hass.config_entries.async_unload_platforms(
self.config_entry, PLATFORMS
@ -246,17 +271,17 @@ class HomematicipHAP:
name: str | None,
) -> AsyncHome:
"""Create a HomematicIP access point object."""
home = AsyncHome(hass.loop, async_get_clientsession(hass))
home = AsyncHome()
home.name = name
# Use the title of the config entry as title for the home.
home.label = self.config_entry.title
home.modelType = "HomematicIP Cloud Home"
home.set_auth_token(authtoken)
try:
await home.init(hapid)
await home.get_current_state()
context = await build_context_async(hass, hapid, authtoken)
home.init_with_context(context, True, get_async_client(hass))
await home.get_current_state_async()
except HmipConnectionError as err:
raise HmipcConnectionError from err
home.on_update(self.async_update)

View File

@ -4,18 +4,18 @@ from __future__ import annotations
from typing import Any
from homematicip.aio.device import (
AsyncBrandDimmer,
AsyncBrandSwitchMeasuring,
AsyncBrandSwitchNotificationLight,
AsyncDimmer,
AsyncDinRailDimmer3,
AsyncFullFlushDimmer,
AsyncPluggableDimmer,
AsyncWiredDimmer3,
)
from homematicip.base.enums import OpticalSignalBehaviour, RGBColorState
from homematicip.base.functionalChannels import NotificationLightChannel
from homematicip.device import (
BrandDimmer,
BrandSwitchMeasuring,
BrandSwitchNotificationLight,
Dimmer,
DinRailDimmer3,
FullFlushDimmer,
PluggableDimmer,
WiredDimmer3,
)
from packaging.version import Version
from homeassistant.components.light import (
@ -46,9 +46,9 @@ async def async_setup_entry(
hap = hass.data[DOMAIN][config_entry.unique_id]
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, AsyncBrandSwitchMeasuring):
if isinstance(device, BrandSwitchMeasuring):
entities.append(HomematicipLightMeasuring(hap, device))
elif isinstance(device, AsyncBrandSwitchNotificationLight):
elif isinstance(device, BrandSwitchNotificationLight):
device_version = Version(device.firmwareVersion)
entities.append(HomematicipLight(hap, device))
@ -65,14 +65,14 @@ async def async_setup_entry(
entity_class(hap, device, device.bottomLightChannelIndex, "Bottom")
)
elif isinstance(device, (AsyncWiredDimmer3, AsyncDinRailDimmer3)):
elif isinstance(device, (WiredDimmer3, DinRailDimmer3)):
entities.extend(
HomematicipMultiDimmer(hap, device, channel=channel)
for channel in range(1, 4)
)
elif isinstance(
device,
(AsyncDimmer, AsyncPluggableDimmer, AsyncBrandDimmer, AsyncFullFlushDimmer),
(Dimmer, PluggableDimmer, BrandDimmer, FullFlushDimmer),
):
entities.append(HomematicipDimmer(hap, device))
@ -96,11 +96,11 @@ class HomematicipLight(HomematicipGenericEntity, LightEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
await self._device.turn_on()
await self._device.turn_on_async()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the light off."""
await self._device.turn_off()
await self._device.turn_off_async()
class HomematicipLightMeasuring(HomematicipLight):
@ -141,15 +141,15 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the dimmer on."""
if ATTR_BRIGHTNESS in kwargs:
await self._device.set_dim_level(
await self._device.set_dim_level_async(
kwargs[ATTR_BRIGHTNESS] / 255.0, self._channel
)
else:
await self._device.set_dim_level(1, self._channel)
await self._device.set_dim_level_async(1, self._channel)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the dimmer off."""
await self._device.set_dim_level(0, self._channel)
await self._device.set_dim_level_async(0, self._channel)
class HomematicipDimmer(HomematicipMultiDimmer, LightEntity):
@ -239,7 +239,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
dim_level = brightness / 255.0
transition = kwargs.get(ATTR_TRANSITION, 0.5)
await self._device.set_rgb_dim_level_with_time(
await self._device.set_rgb_dim_level_with_time_async(
channelIndex=self._channel,
rgb=simple_rgb_color,
dimLevel=dim_level,
@ -252,7 +252,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
simple_rgb_color = self._func_channel.simpleRGBColorState
transition = kwargs.get(ATTR_TRANSITION, 0.5)
await self._device.set_rgb_dim_level_with_time(
await self._device.set_rgb_dim_level_with_time_async(
channelIndex=self._channel,
rgb=simple_rgb_color,
dimLevel=0.0,

View File

@ -5,8 +5,8 @@ from __future__ import annotations
import logging
from typing import Any
from homematicip.aio.device import AsyncDoorLockDrive
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
@ -45,7 +45,7 @@ async def async_setup_entry(
async_add_entities(
HomematicipDoorLockDrive(hap, device)
for device in hap.home.devices
if isinstance(device, AsyncDoorLockDrive)
if isinstance(device, DoorLockDrive)
)
@ -75,17 +75,17 @@ class HomematicipDoorLockDrive(HomematicipGenericEntity, LockEntity):
@handle_errors
async def async_lock(self, **kwargs: Any) -> None:
"""Lock the device."""
return await self._device.set_lock_state(LockState.LOCKED)
return await self._device.set_lock_state_async(LockState.LOCKED)
@handle_errors
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock the device."""
return await self._device.set_lock_state(LockState.UNLOCKED)
return await self._device.set_lock_state_async(LockState.UNLOCKED)
@handle_errors
async def async_open(self, **kwargs: Any) -> None:
"""Open the door latch."""
return await self._device.set_lock_state(LockState.OPEN)
return await self._device.set_lock_state_async(LockState.OPEN)
@property
def extra_state_attributes(self) -> dict[str, Any]:

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/homematicip_cloud",
"iot_class": "cloud_push",
"loggers": ["homematicip"],
"requirements": ["homematicip==1.1.7"]
"requirements": ["homematicip==2.0.0"]
}

View File

@ -5,39 +5,39 @@ from __future__ import annotations
from collections.abc import Callable
from typing import Any
from homematicip.aio.device import (
AsyncBrandSwitchMeasuring,
AsyncEnergySensorsInterface,
AsyncFloorTerminalBlock6,
AsyncFloorTerminalBlock10,
AsyncFloorTerminalBlock12,
AsyncFullFlushSwitchMeasuring,
AsyncHeatingThermostat,
AsyncHeatingThermostatCompact,
AsyncHeatingThermostatEvo,
AsyncHomeControlAccessPoint,
AsyncLightSensor,
AsyncMotionDetectorIndoor,
AsyncMotionDetectorOutdoor,
AsyncMotionDetectorPushButton,
AsyncPassageDetector,
AsyncPlugableSwitchMeasuring,
AsyncPresenceDetectorIndoor,
AsyncRoomControlDeviceAnalog,
AsyncTemperatureDifferenceSensor2,
AsyncTemperatureHumiditySensorDisplay,
AsyncTemperatureHumiditySensorOutdoor,
AsyncTemperatureHumiditySensorWithoutDisplay,
AsyncWeatherSensor,
AsyncWeatherSensorPlus,
AsyncWeatherSensorPro,
AsyncWiredFloorTerminalBlock12,
)
from homematicip.base.enums import FunctionalChannelType, ValveState
from homematicip.base.functionalChannels import (
FloorTerminalBlockMechanicChannel,
FunctionalChannel,
)
from homematicip.device import (
BrandSwitchMeasuring,
EnergySensorsInterface,
FloorTerminalBlock6,
FloorTerminalBlock10,
FloorTerminalBlock12,
FullFlushSwitchMeasuring,
HeatingThermostat,
HeatingThermostatCompact,
HeatingThermostatEvo,
HomeControlAccessPoint,
LightSensor,
MotionDetectorIndoor,
MotionDetectorOutdoor,
MotionDetectorPushButton,
PassageDetector,
PlugableSwitchMeasuring,
PresenceDetectorIndoor,
RoomControlDeviceAnalog,
TemperatureDifferenceSensor2,
TemperatureHumiditySensorDisplay,
TemperatureHumiditySensorOutdoor,
TemperatureHumiditySensorWithoutDisplay,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
WiredFloorTerminalBlock12,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
@ -102,14 +102,14 @@ async def async_setup_entry(
hap = hass.data[DOMAIN][config_entry.unique_id]
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, AsyncHomeControlAccessPoint):
if isinstance(device, HomeControlAccessPoint):
entities.append(HomematicipAccesspointDutyCycle(hap, device))
if isinstance(
device,
(
AsyncHeatingThermostat,
AsyncHeatingThermostatCompact,
AsyncHeatingThermostatEvo,
HeatingThermostat,
HeatingThermostatCompact,
HeatingThermostatEvo,
),
):
entities.append(HomematicipHeatingThermostat(hap, device))
@ -117,55 +117,53 @@ async def async_setup_entry(
if isinstance(
device,
(
AsyncTemperatureHumiditySensorDisplay,
AsyncTemperatureHumiditySensorWithoutDisplay,
AsyncTemperatureHumiditySensorOutdoor,
AsyncWeatherSensor,
AsyncWeatherSensorPlus,
AsyncWeatherSensorPro,
TemperatureHumiditySensorDisplay,
TemperatureHumiditySensorWithoutDisplay,
TemperatureHumiditySensorOutdoor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
),
):
entities.append(HomematicipTemperatureSensor(hap, device))
entities.append(HomematicipHumiditySensor(hap, device))
elif isinstance(device, (AsyncRoomControlDeviceAnalog,)):
elif isinstance(device, (RoomControlDeviceAnalog,)):
entities.append(HomematicipTemperatureSensor(hap, device))
if isinstance(
device,
(
AsyncLightSensor,
AsyncMotionDetectorIndoor,
AsyncMotionDetectorOutdoor,
AsyncMotionDetectorPushButton,
AsyncPresenceDetectorIndoor,
AsyncWeatherSensor,
AsyncWeatherSensorPlus,
AsyncWeatherSensorPro,
LightSensor,
MotionDetectorIndoor,
MotionDetectorOutdoor,
MotionDetectorPushButton,
PresenceDetectorIndoor,
WeatherSensor,
WeatherSensorPlus,
WeatherSensorPro,
),
):
entities.append(HomematicipIlluminanceSensor(hap, device))
if isinstance(
device,
(
AsyncPlugableSwitchMeasuring,
AsyncBrandSwitchMeasuring,
AsyncFullFlushSwitchMeasuring,
PlugableSwitchMeasuring,
BrandSwitchMeasuring,
FullFlushSwitchMeasuring,
),
):
entities.append(HomematicipPowerSensor(hap, device))
entities.append(HomematicipEnergySensor(hap, device))
if isinstance(
device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
):
if isinstance(device, (WeatherSensor, WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipWindspeedSensor(hap, device))
if isinstance(device, (AsyncWeatherSensorPlus, AsyncWeatherSensorPro)):
if isinstance(device, (WeatherSensorPlus, WeatherSensorPro)):
entities.append(HomematicipTodayRainSensor(hap, device))
if isinstance(device, AsyncPassageDetector):
if isinstance(device, PassageDetector):
entities.append(HomematicipPassageDetectorDeltaCounter(hap, device))
if isinstance(device, AsyncTemperatureDifferenceSensor2):
if isinstance(device, TemperatureDifferenceSensor2):
entities.append(HomematicpTemperatureExternalSensorCh1(hap, device))
entities.append(HomematicpTemperatureExternalSensorCh2(hap, device))
entities.append(HomematicpTemperatureExternalSensorDelta(hap, device))
if isinstance(device, AsyncEnergySensorsInterface):
if isinstance(device, EnergySensorsInterface):
for ch in get_channels_from_device(
device, FunctionalChannelType.ENERGY_SENSORS_INTERFACE_CHANNEL
):
@ -194,10 +192,10 @@ async def async_setup_entry(
if isinstance(
device,
(
AsyncFloorTerminalBlock6,
AsyncFloorTerminalBlock10,
AsyncFloorTerminalBlock12,
AsyncWiredFloorTerminalBlock12,
FloorTerminalBlock6,
FloorTerminalBlock10,
FloorTerminalBlock12,
WiredFloorTerminalBlock12,
),
):
entities.extend(

View File

@ -5,10 +5,10 @@ from __future__ import annotations
import logging
from pathlib import Path
from homematicip.aio.device import AsyncSwitchMeasuring
from homematicip.aio.group import AsyncHeatingGroup
from homematicip.aio.home import AsyncHome
from homematicip.async_home import AsyncHome
from homematicip.base.helpers import handle_config
from homematicip.device import SwitchMeasuring
from homematicip.group import HeatingGroup
import voluptuous as vol
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE
@ -233,10 +233,10 @@ async def _async_activate_eco_mode_with_duration(
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.activate_absence_with_duration(duration)
await home.activate_absence_with_duration_async(duration)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_absence_with_duration(duration)
await hap.home.activate_absence_with_duration_async(duration)
async def _async_activate_eco_mode_with_period(
@ -247,10 +247,10 @@ async def _async_activate_eco_mode_with_period(
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.activate_absence_with_period(endtime)
await home.activate_absence_with_period_async(endtime)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_absence_with_period(endtime)
await hap.home.activate_absence_with_period_async(endtime)
async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) -> None:
@ -260,30 +260,30 @@ async def _async_activate_vacation(hass: HomeAssistant, service: ServiceCall) ->
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.activate_vacation(endtime, temperature)
await home.activate_vacation_async(endtime, temperature)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.activate_vacation(endtime, temperature)
await hap.home.activate_vacation_async(endtime, temperature)
async def _async_deactivate_eco_mode(hass: HomeAssistant, service: ServiceCall) -> None:
"""Service to deactivate eco mode."""
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.deactivate_absence()
await home.deactivate_absence_async()
else:
for hap in hass.data[DOMAIN].values():
await hap.home.deactivate_absence()
await hap.home.deactivate_absence_async()
async def _async_deactivate_vacation(hass: HomeAssistant, service: ServiceCall) -> None:
"""Service to deactivate vacation."""
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.deactivate_vacation()
await home.deactivate_vacation_async()
else:
for hap in hass.data[DOMAIN].values():
await hap.home.deactivate_vacation()
await hap.home.deactivate_vacation_async()
async def _set_active_climate_profile(
@ -297,12 +297,12 @@ async def _set_active_climate_profile(
if entity_id_list != "all":
for entity_id in entity_id_list:
group = hap.hmip_device_by_entity_id.get(entity_id)
if group and isinstance(group, AsyncHeatingGroup):
await group.set_active_profile(climate_profile_index)
if group and isinstance(group, HeatingGroup):
await group.set_active_profile_async(climate_profile_index)
else:
for group in hap.home.groups:
if isinstance(group, AsyncHeatingGroup):
await group.set_active_profile(climate_profile_index)
if isinstance(group, HeatingGroup):
await group.set_active_profile_async(climate_profile_index)
async def _async_dump_hap_config(hass: HomeAssistant, service: ServiceCall) -> None:
@ -323,7 +323,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()
json_state = await hap.home.download_configuration_async()
json_state = handle_config(json_state, anonymize)
config_file.write_text(json_state, encoding="utf8")
@ -337,12 +337,12 @@ async def _async_reset_energy_counter(hass: HomeAssistant, service: ServiceCall)
if entity_id_list != "all":
for entity_id in entity_id_list:
device = hap.hmip_device_by_entity_id.get(entity_id)
if device and isinstance(device, AsyncSwitchMeasuring):
await device.reset_energy_counter()
if device and isinstance(device, SwitchMeasuring):
await device.reset_energy_counter_async()
else:
for device in hap.home.devices:
if isinstance(device, AsyncSwitchMeasuring):
await device.reset_energy_counter()
if isinstance(device, SwitchMeasuring):
await device.reset_energy_counter_async()
async def _async_set_home_cooling_mode(hass: HomeAssistant, service: ServiceCall):
@ -351,10 +351,10 @@ async def _async_set_home_cooling_mode(hass: HomeAssistant, service: ServiceCall
if hapid := service.data.get(ATTR_ACCESSPOINT_ID):
if home := _get_home(hass, hapid):
await home.set_cooling(cooling)
await home.set_cooling_async(cooling)
else:
for hap in hass.data[DOMAIN].values():
await hap.home.set_cooling(cooling)
await hap.home.set_cooling_async(cooling)
def _get_home(hass: HomeAssistant, hapid: str) -> AsyncHome | None:

View File

@ -4,23 +4,23 @@ from __future__ import annotations
from typing import Any
from homematicip.aio.device import (
AsyncBrandSwitch2,
AsyncBrandSwitchMeasuring,
AsyncDinRailSwitch,
AsyncDinRailSwitch4,
AsyncFullFlushInputSwitch,
AsyncFullFlushSwitchMeasuring,
AsyncHeatingSwitch2,
AsyncMultiIOBox,
AsyncOpenCollector8Module,
AsyncPlugableSwitch,
AsyncPlugableSwitchMeasuring,
AsyncPrintedCircuitBoardSwitch2,
AsyncPrintedCircuitBoardSwitchBattery,
AsyncWiredSwitch8,
from homematicip.device import (
BrandSwitch2,
BrandSwitchMeasuring,
DinRailSwitch,
DinRailSwitch4,
FullFlushInputSwitch,
FullFlushSwitchMeasuring,
HeatingSwitch2,
MultiIOBox,
OpenCollector8Module,
PlugableSwitch,
PlugableSwitchMeasuring,
PrintedCircuitBoardSwitch2,
PrintedCircuitBoardSwitchBattery,
WiredSwitch8,
)
from homematicip.aio.group import AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup
from homematicip.group import ExtendedLinkedSwitchingGroup, SwitchingGroup
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
@ -42,26 +42,24 @@ async def async_setup_entry(
entities: list[HomematicipGenericEntity] = [
HomematicipGroupSwitch(hap, group)
for group in hap.home.groups
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup))
if isinstance(group, (ExtendedLinkedSwitchingGroup, SwitchingGroup))
]
for device in hap.home.devices:
if isinstance(device, AsyncBrandSwitchMeasuring):
if isinstance(device, BrandSwitchMeasuring):
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring
# This entity is implemented in the light platform and will
# not be added in the switch platform
pass
elif isinstance(
device, (AsyncPlugableSwitchMeasuring, AsyncFullFlushSwitchMeasuring)
):
elif isinstance(device, (PlugableSwitchMeasuring, FullFlushSwitchMeasuring)):
entities.append(HomematicipSwitchMeasuring(hap, device))
elif isinstance(device, AsyncWiredSwitch8):
elif isinstance(device, WiredSwitch8):
entities.extend(
HomematicipMultiSwitch(hap, device, channel=channel)
for channel in range(1, 9)
)
elif isinstance(device, AsyncDinRailSwitch):
elif isinstance(device, DinRailSwitch):
entities.append(HomematicipMultiSwitch(hap, device, channel=1))
elif isinstance(device, AsyncDinRailSwitch4):
elif isinstance(device, DinRailSwitch4):
entities.extend(
HomematicipMultiSwitch(hap, device, channel=channel)
for channel in range(1, 5)
@ -69,13 +67,13 @@ async def async_setup_entry(
elif isinstance(
device,
(
AsyncPlugableSwitch,
AsyncPrintedCircuitBoardSwitchBattery,
AsyncFullFlushInputSwitch,
PlugableSwitch,
PrintedCircuitBoardSwitchBattery,
FullFlushInputSwitch,
),
):
entities.append(HomematicipSwitch(hap, device))
elif isinstance(device, AsyncOpenCollector8Module):
elif isinstance(device, OpenCollector8Module):
entities.extend(
HomematicipMultiSwitch(hap, device, channel=channel)
for channel in range(1, 9)
@ -83,10 +81,10 @@ async def async_setup_entry(
elif isinstance(
device,
(
AsyncBrandSwitch2,
AsyncPrintedCircuitBoardSwitch2,
AsyncHeatingSwitch2,
AsyncMultiIOBox,
BrandSwitch2,
PrintedCircuitBoardSwitch2,
HeatingSwitch2,
MultiIOBox,
),
):
entities.extend(
@ -119,11 +117,11 @@ class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
await self._device.turn_on(self._channel)
await self._device.turn_on_async(self._channel)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
await self._device.turn_off(self._channel)
await self._device.turn_off_async(self._channel)
class HomematicipSwitch(HomematicipMultiSwitch, SwitchEntity):
@ -168,11 +166,11 @@ class HomematicipGroupSwitch(HomematicipGenericEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the group on."""
await self._device.turn_on()
await self._device.turn_on_async()
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the group off."""
await self._device.turn_off()
await self._device.turn_off_async()
class HomematicipSwitchMeasuring(HomematicipSwitch):

View File

@ -2,12 +2,8 @@
from __future__ import annotations
from homematicip.aio.device import (
AsyncWeatherSensor,
AsyncWeatherSensorPlus,
AsyncWeatherSensorPro,
)
from homematicip.base.enums import WeatherCondition
from homematicip.device import WeatherSensor, WeatherSensorPlus, WeatherSensorPro
from homeassistant.components.weather import (
ATTR_CONDITION_CLOUDY,
@ -59,9 +55,9 @@ async def async_setup_entry(
hap = hass.data[DOMAIN][config_entry.unique_id]
entities: list[HomematicipGenericEntity] = []
for device in hap.home.devices:
if isinstance(device, AsyncWeatherSensorPro):
if isinstance(device, WeatherSensorPro):
entities.append(HomematicipWeatherSensorPro(hap, device))
elif isinstance(device, (AsyncWeatherSensor, AsyncWeatherSensorPlus)):
elif isinstance(device, (WeatherSensor, WeatherSensorPlus)):
entities.append(HomematicipWeatherSensor(hap, device))
entities.append(HomematicipHomeWeather(hap))

2
requirements_all.txt generated
View File

@ -1163,7 +1163,7 @@ home-assistant-frontend==20250411.0
home-assistant-intents==2025.3.28
# homeassistant.components.homematicip_cloud
homematicip==1.1.7
homematicip==2.0.0
# homeassistant.components.horizon
horimote==0.4.1

View File

@ -993,7 +993,7 @@ home-assistant-frontend==20250411.0
home-assistant-intents==2025.3.28
# homeassistant.components.homematicip_cloud
homematicip==1.1.7
homematicip==2.0.0
# homeassistant.components.remember_the_milk
httplib2==0.20.4

View File

@ -1,11 +1,11 @@
"""Initializer helpers for HomematicIP fake server."""
from unittest.mock import AsyncMock, MagicMock, Mock, patch
from unittest.mock import AsyncMock, Mock, patch
from homematicip.aio.auth import AsyncAuth
from homematicip.aio.connection import AsyncConnection
from homematicip.aio.home import AsyncHome
from homematicip.async_home import AsyncHome
from homematicip.auth import Auth
from homematicip.base.enums import WeatherCondition, WeatherDayTime
from homematicip.connection.rest_connection import RestConnection
import pytest
from homeassistant.components.homematicip_cloud import (
@ -30,16 +30,14 @@ from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture(name="mock_connection")
def mock_connection_fixture() -> AsyncConnection:
def mock_connection_fixture() -> RestConnection:
"""Return a mocked connection."""
connection = MagicMock(spec=AsyncConnection)
connection = AsyncMock(spec=RestConnection)
def _rest_call_side_effect(path, body=None):
def _rest_call_side_effect(path, body=None, custom_header=None):
return path, body
connection._rest_call.side_effect = _rest_call_side_effect
connection.api_call = AsyncMock(return_value=True)
connection.init = AsyncMock(side_effect=True)
connection.async_post.side_effect = _rest_call_side_effect
return connection
@ -107,7 +105,7 @@ async def mock_hap_with_service_fixture(
def simple_mock_home_fixture():
"""Return a simple mocked connection."""
mock_home = Mock(
mock_home = AsyncMock(
spec=AsyncHome,
name="Demo",
devices=[],
@ -128,6 +126,8 @@ def simple_mock_home_fixture():
dutyCycle=88,
connected=True,
currentAPVersion="2.0.36",
init_async=AsyncMock(),
get_current_state_async=AsyncMock(),
)
with patch(
@ -144,18 +144,15 @@ def mock_connection_init_fixture():
with (
patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.init",
return_value=None,
),
patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth.init",
"homeassistant.components.homematicip_cloud.hap.AsyncHome.init_async",
return_value=None,
new_callable=AsyncMock,
),
):
yield
@pytest.fixture(name="simple_mock_auth")
def simple_mock_auth_fixture() -> AsyncAuth:
def simple_mock_auth_fixture() -> Auth:
"""Return a simple AsyncAuth Mock."""
return Mock(spec=AsyncAuth, pin=HAPPIN, create=True)
return AsyncMock(spec=Auth, pin=HAPPIN, create=True)

View File

@ -4,15 +4,15 @@ import json
from typing import Any
from unittest.mock import Mock, patch
from homematicip.aio.class_maps import (
from homematicip.async_home import AsyncHome
from homematicip.base.homematicip_object import HomeMaticIPObject
from homematicip.class_maps import (
TYPE_CLASS_MAP,
TYPE_GROUP_MAP,
TYPE_SECURITY_EVENT_MAP,
)
from homematicip.aio.device import AsyncDevice
from homematicip.aio.group import AsyncGroup
from homematicip.aio.home import AsyncHome
from homematicip.base.homematicip_object import HomeMaticIPObject
from homematicip.device import Device
from homematicip.group import Group
from homematicip.home import Home
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
@ -49,9 +49,9 @@ def get_and_check_entity_basics(
hmip_device = mock_hap.hmip_device_by_entity_id.get(entity_id)
if hmip_device:
if isinstance(hmip_device, AsyncDevice):
if isinstance(hmip_device, Device):
assert ha_state.attributes[ATTR_IS_GROUP] is False
elif isinstance(hmip_device, AsyncGroup):
elif isinstance(hmip_device, Group):
assert ha_state.attributes[ATTR_IS_GROUP]
return ha_state, hmip_device
@ -174,12 +174,12 @@ class HomeTemplate(Home):
def init_home(self):
"""Init template with json."""
self.init_json_state = self._cleanup_json(json.loads(FIXTURE_DATA))
self.update_home(json_state=self.init_json_state, clearConfig=True)
self.update_home(json_state=self.init_json_state, clear_config=True)
return self
def update_home(self, json_state, clearConfig: bool = False):
def update_home(self, json_state, clear_config: bool = False):
"""Update home and ensure that mocks are created."""
result = super().update_home(json_state, clearConfig)
result = super().update_home(json_state, clear_config)
self._generate_mocks()
return result
@ -193,7 +193,7 @@ class HomeTemplate(Home):
self.groups = [_get_mock(group) for group in self.groups]
def download_configuration(self):
async def download_configuration_async(self):
"""Return the initial json config."""
return self.init_json_state

View File

@ -1,6 +1,6 @@
"""Tests for HomematicIP Cloud alarm control panel."""
from homematicip.aio.home import AsyncHome
from homematicip.async_home import AsyncHome
from homeassistant.components.alarm_control_panel import (
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
@ -73,7 +73,7 @@ async def test_hmip_alarm_control_panel(
await hass.services.async_call(
"alarm_control_panel", "alarm_arm_away", {"entity_id": entity_id}, blocking=True
)
assert home.mock_calls[-1][0] == "set_security_zones_activation"
assert home.mock_calls[-1][0] == "set_security_zones_activation_async"
assert home.mock_calls[-1][1] == (True, True)
await _async_manipulate_security_zones(
hass, home, internal_active=True, external_active=True
@ -83,7 +83,7 @@ async def test_hmip_alarm_control_panel(
await hass.services.async_call(
"alarm_control_panel", "alarm_arm_home", {"entity_id": entity_id}, blocking=True
)
assert home.mock_calls[-1][0] == "set_security_zones_activation"
assert home.mock_calls[-1][0] == "set_security_zones_activation_async"
assert home.mock_calls[-1][1] == (False, True)
await _async_manipulate_security_zones(hass, home, external_active=True)
assert hass.states.get(entity_id).state == AlarmControlPanelState.ARMED_HOME
@ -91,7 +91,7 @@ async def test_hmip_alarm_control_panel(
await hass.services.async_call(
"alarm_control_panel", "alarm_disarm", {"entity_id": entity_id}, blocking=True
)
assert home.mock_calls[-1][0] == "set_security_zones_activation"
assert home.mock_calls[-1][0] == "set_security_zones_activation_async"
assert home.mock_calls[-1][1] == (False, False)
await _async_manipulate_security_zones(hass, home)
assert hass.states.get(entity_id).state == AlarmControlPanelState.DISARMED
@ -99,7 +99,7 @@ async def test_hmip_alarm_control_panel(
await hass.services.async_call(
"alarm_control_panel", "alarm_arm_away", {"entity_id": entity_id}, blocking=True
)
assert home.mock_calls[-1][0] == "set_security_zones_activation"
assert home.mock_calls[-1][0] == "set_security_zones_activation_async"
assert home.mock_calls[-1][1] == (True, True)
await _async_manipulate_security_zones(
hass, home, internal_active=True, external_active=True, alarm_triggered=True
@ -109,7 +109,7 @@ async def test_hmip_alarm_control_panel(
await hass.services.async_call(
"alarm_control_panel", "alarm_arm_home", {"entity_id": entity_id}, blocking=True
)
assert home.mock_calls[-1][0] == "set_security_zones_activation"
assert home.mock_calls[-1][0] == "set_security_zones_activation_async"
assert home.mock_calls[-1][1] == (False, True)
await _async_manipulate_security_zones(
hass, home, external_active=True, alarm_triggered=True

View File

@ -83,7 +83,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_point_temperature"
assert hmip_device.mock_calls[-1][0] == "set_point_temperature_async"
assert hmip_device.mock_calls[-1][1] == (22.5,)
await async_manipulate_test_data(hass, hmip_device, "actualTemperature", 22.5)
ha_state = hass.states.get(entity_id)
@ -96,7 +96,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
ha_state = hass.states.get(entity_id)
@ -109,7 +109,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("AUTOMATIC",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTO")
ha_state = hass.states.get(entity_id)
@ -122,7 +122,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 7
assert hmip_device.mock_calls[-1][0] == "set_boost"
assert hmip_device.mock_calls[-1][0] == "set_boost_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "boostMode", True)
ha_state = hass.states.get(entity_id)
@ -135,7 +135,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 11
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (0,)
await async_manipulate_test_data(hass, hmip_device, "boostMode", False)
ha_state = hass.states.get(entity_id)
@ -176,7 +176,7 @@ async def test_hmip_heating_group_heat(
)
assert len(hmip_device.mock_calls) == service_call_counter + 18
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (1,)
mock_hap.home.get_functionalHome(
@ -194,7 +194,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 20
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
ha_state = hass.states.get(entity_id)
@ -208,7 +208,7 @@ async def test_hmip_heating_group_heat(
)
assert len(hmip_device.mock_calls) == service_call_counter + 23
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (1,)
hmip_device.activeProfile = hmip_device.profiles[0]
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTOMATIC")
@ -235,7 +235,7 @@ async def test_hmip_heating_group_heat(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 25
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("ECO",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "ECO")
ha_state = hass.states.get(entity_id)
@ -293,7 +293,7 @@ async def test_hmip_heating_group_cool(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("MANUAL",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "MANUAL")
ha_state = hass.states.get(entity_id)
@ -306,7 +306,7 @@ async def test_hmip_heating_group_cool(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "set_control_mode"
assert hmip_device.mock_calls[-1][0] == "set_control_mode_async"
assert hmip_device.mock_calls[-1][1] == ("AUTOMATIC",)
await async_manipulate_test_data(hass, hmip_device, "controlMode", "AUTO")
ha_state = hass.states.get(entity_id)
@ -320,7 +320,7 @@ async def test_hmip_heating_group_cool(
)
assert len(hmip_device.mock_calls) == service_call_counter + 6
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (4,)
hmip_device.activeProfile = hmip_device.profiles[4]
@ -373,7 +373,7 @@ async def test_hmip_heating_group_cool(
)
assert len(hmip_device.mock_calls) == service_call_counter + 17
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (4,)
@ -531,7 +531,7 @@ async def test_hmip_climate_services(
{"duration": 60, "accesspoint_id": HAPID},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_absence_with_duration"
assert home.mock_calls[-1][0] == "activate_absence_with_duration_async"
assert home.mock_calls[-1][1] == (60,)
assert len(home._connection.mock_calls) == 1
@ -541,7 +541,7 @@ async def test_hmip_climate_services(
{"duration": 60},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_absence_with_duration"
assert home.mock_calls[-1][0] == "activate_absence_with_duration_async"
assert home.mock_calls[-1][1] == (60,)
assert len(home._connection.mock_calls) == 2
@ -551,7 +551,7 @@ async def test_hmip_climate_services(
{"endtime": "2019-02-17 14:00", "accesspoint_id": HAPID},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_absence_with_period"
assert home.mock_calls[-1][0] == "activate_absence_with_period_async"
assert home.mock_calls[-1][1] == (datetime.datetime(2019, 2, 17, 14, 0),)
assert len(home._connection.mock_calls) == 3
@ -561,7 +561,7 @@ async def test_hmip_climate_services(
{"endtime": "2019-02-17 14:00"},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_absence_with_period"
assert home.mock_calls[-1][0] == "activate_absence_with_period_async"
assert home.mock_calls[-1][1] == (datetime.datetime(2019, 2, 17, 14, 0),)
assert len(home._connection.mock_calls) == 4
@ -571,7 +571,7 @@ async def test_hmip_climate_services(
{"endtime": "2019-02-17 14:00", "temperature": 18.5, "accesspoint_id": HAPID},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_vacation"
assert home.mock_calls[-1][0] == "activate_vacation_async"
assert home.mock_calls[-1][1] == (datetime.datetime(2019, 2, 17, 14, 0), 18.5)
assert len(home._connection.mock_calls) == 5
@ -581,7 +581,7 @@ async def test_hmip_climate_services(
{"endtime": "2019-02-17 14:00", "temperature": 18.5},
blocking=True,
)
assert home.mock_calls[-1][0] == "activate_vacation"
assert home.mock_calls[-1][0] == "activate_vacation_async"
assert home.mock_calls[-1][1] == (datetime.datetime(2019, 2, 17, 14, 0), 18.5)
assert len(home._connection.mock_calls) == 6
@ -591,14 +591,14 @@ async def test_hmip_climate_services(
{"accesspoint_id": HAPID},
blocking=True,
)
assert home.mock_calls[-1][0] == "deactivate_absence"
assert home.mock_calls[-1][0] == "deactivate_absence_async"
assert home.mock_calls[-1][1] == ()
assert len(home._connection.mock_calls) == 7
await hass.services.async_call(
"homematicip_cloud", "deactivate_eco_mode", blocking=True
)
assert home.mock_calls[-1][0] == "deactivate_absence"
assert home.mock_calls[-1][0] == "deactivate_absence_async"
assert home.mock_calls[-1][1] == ()
assert len(home._connection.mock_calls) == 8
@ -608,14 +608,14 @@ async def test_hmip_climate_services(
{"accesspoint_id": HAPID},
blocking=True,
)
assert home.mock_calls[-1][0] == "deactivate_vacation"
assert home.mock_calls[-1][0] == "deactivate_vacation_async"
assert home.mock_calls[-1][1] == ()
assert len(home._connection.mock_calls) == 9
await hass.services.async_call(
"homematicip_cloud", "deactivate_vacation", blocking=True
)
assert home.mock_calls[-1][0] == "deactivate_vacation"
assert home.mock_calls[-1][0] == "deactivate_vacation_async"
assert home.mock_calls[-1][1] == ()
assert len(home._connection.mock_calls) == 10
@ -646,7 +646,7 @@ async def test_hmip_set_home_cooling_mode(
{"accesspoint_id": HAPID, "cooling": False},
blocking=True,
)
assert home.mock_calls[-1][0] == "set_cooling"
assert home.mock_calls[-1][0] == "set_cooling_async"
assert home.mock_calls[-1][1] == (False,)
assert len(home._connection.mock_calls) == 1
@ -656,14 +656,14 @@ async def test_hmip_set_home_cooling_mode(
{"accesspoint_id": HAPID, "cooling": True},
blocking=True,
)
assert home.mock_calls[-1][0] == "set_cooling"
assert home.mock_calls[-1][0] == "set_cooling_async"
assert home.mock_calls[-1][1]
assert len(home._connection.mock_calls) == 2
await hass.services.async_call(
"homematicip_cloud", "set_home_cooling_mode", blocking=True
)
assert home.mock_calls[-1][0] == "set_cooling"
assert home.mock_calls[-1][0] == "set_cooling_async"
assert home.mock_calls[-1][1]
assert len(home._connection.mock_calls) == 3
@ -703,9 +703,9 @@ async def test_hmip_heating_group_services(
{"climate_profile_index": 2, "entity_id": "climate.badezimmer"},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (1,)
assert len(hmip_device._connection.mock_calls) == 2
assert len(hmip_device._connection.mock_calls) == 1
await hass.services.async_call(
"homematicip_cloud",
@ -713,6 +713,6 @@ async def test_hmip_heating_group_services(
{"climate_profile_index": 2, "entity_id": "all"},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_active_profile"
assert hmip_device.mock_calls[-1][0] == "set_active_profile_async"
assert hmip_device.mock_calls[-1][1] == (1,)
assert len(hmip_device._connection.mock_calls) == 4
assert len(hmip_device._connection.mock_calls) == 2

View File

@ -47,7 +47,7 @@ async def test_hmip_cover_shutter(
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0)
ha_state = hass.states.get(entity_id)
@ -61,7 +61,7 @@ async def test_hmip_cover_shutter(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (0.5, 1)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0.5)
ha_state = hass.states.get(entity_id)
@ -72,7 +72,7 @@ async def test_hmip_cover_shutter(
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 1)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 1)
ha_state = hass.states.get(entity_id)
@ -83,7 +83,7 @@ async def test_hmip_cover_shutter(
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 7
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
@ -115,7 +115,7 @@ async def test_hmip_cover_slats(
"cover", "open_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 1, "slatsLevel": 0}
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0)
@ -131,7 +131,7 @@ async def test_hmip_cover_slats(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 1, "slatsLevel": 0.5}
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0.5)
ha_state = hass.states.get(entity_id)
@ -143,7 +143,7 @@ async def test_hmip_cover_slats(
"cover", "close_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 6
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 1, "slatsLevel": 1}
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 1)
ha_state = hass.states.get(entity_id)
@ -155,7 +155,7 @@ async def test_hmip_cover_slats(
"cover", "stop_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 8
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", None)
@ -195,7 +195,7 @@ async def test_hmip_multi_cover_slats(
"cover", "open_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 4, "slatsLevel": 0}
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0, channel=4)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0, channel=4)
@ -211,7 +211,7 @@ async def test_hmip_multi_cover_slats(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 4, "slatsLevel": 0.5}
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0.5, channel=4)
ha_state = hass.states.get(entity_id)
@ -223,7 +223,7 @@ async def test_hmip_multi_cover_slats(
"cover", "close_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 6
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][2] == {"channelIndex": 4, "slatsLevel": 1}
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 1, channel=4)
ha_state = hass.states.get(entity_id)
@ -235,7 +235,7 @@ async def test_hmip_multi_cover_slats(
"cover", "stop_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 8
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop_async"
assert hmip_device.mock_calls[-1][1] == (4,)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", None, channel=4)
@ -271,7 +271,7 @@ async def test_hmip_blind_module(
"cover", "open_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_secondary_shading_level"
assert hmip_device.mock_calls[-1][0] == "set_secondary_shading_level_async"
assert hmip_device.mock_calls[-1][2] == {
"primaryShadingLevel": 0.94956,
"secondaryShadingLevel": 0,
@ -284,7 +284,7 @@ async def test_hmip_blind_module(
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_primary_shading_level"
assert hmip_device.mock_calls[-1][0] == "set_primary_shading_level_async"
assert hmip_device.mock_calls[-1][2] == {"primaryShadingLevel": 0}
ha_state = hass.states.get(entity_id)
@ -308,7 +308,7 @@ async def test_hmip_blind_module(
)
assert len(hmip_device.mock_calls) == service_call_counter + 8
assert hmip_device.mock_calls[-1][0] == "set_primary_shading_level"
assert hmip_device.mock_calls[-1][0] == "set_primary_shading_level_async"
assert hmip_device.mock_calls[-1][2] == {"primaryShadingLevel": 0.5}
ha_state = hass.states.get(entity_id)
assert ha_state.state == CoverState.OPEN
@ -325,7 +325,7 @@ async def test_hmip_blind_module(
)
assert len(hmip_device.mock_calls) == service_call_counter + 12
assert hmip_device.mock_calls[-1][0] == "set_secondary_shading_level"
assert hmip_device.mock_calls[-1][0] == "set_secondary_shading_level_async"
assert hmip_device.mock_calls[-1][2] == {
"primaryShadingLevel": 1,
"secondaryShadingLevel": 1,
@ -340,14 +340,14 @@ async def test_hmip_blind_module(
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 13
assert hmip_device.mock_calls[-1][0] == "stop"
assert hmip_device.mock_calls[-1][0] == "stop_async"
assert hmip_device.mock_calls[-1][1] == ()
await hass.services.async_call(
"cover", "stop_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 14
assert hmip_device.mock_calls[-1][0] == "stop"
assert hmip_device.mock_calls[-1][0] == "stop_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "secondaryShadingLevel", None)
@ -382,7 +382,7 @@ async def test_hmip_garage_door_tormatic(
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.OPEN,)
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.OPEN)
ha_state = hass.states.get(entity_id)
@ -393,7 +393,7 @@ async def test_hmip_garage_door_tormatic(
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.CLOSE,)
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.CLOSED)
ha_state = hass.states.get(entity_id)
@ -404,7 +404,7 @@ async def test_hmip_garage_door_tormatic(
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.STOP,)
@ -431,7 +431,7 @@ async def test_hmip_garage_door_hoermann(
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.OPEN,)
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.OPEN)
ha_state = hass.states.get(entity_id)
@ -442,7 +442,7 @@ async def test_hmip_garage_door_hoermann(
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.CLOSE,)
await async_manipulate_test_data(hass, hmip_device, "doorState", DoorState.CLOSED)
ha_state = hass.states.get(entity_id)
@ -453,7 +453,7 @@ async def test_hmip_garage_door_hoermann(
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "send_door_command"
assert hmip_device.mock_calls[-1][0] == "send_door_command_async"
assert hmip_device.mock_calls[-1][1] == (DoorCommand.STOP,)
@ -478,7 +478,7 @@ async def test_hmip_cover_shutter_group(
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (0,)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0)
ha_state = hass.states.get(entity_id)
@ -492,7 +492,7 @@ async def test_hmip_cover_shutter_group(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (0.5,)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0.5)
ha_state = hass.states.get(entity_id)
@ -503,7 +503,7 @@ async def test_hmip_cover_shutter_group(
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "set_shutter_level"
assert hmip_device.mock_calls[-1][0] == "set_shutter_level_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 1)
ha_state = hass.states.get(entity_id)
@ -514,7 +514,7 @@ async def test_hmip_cover_shutter_group(
"cover", "stop_cover", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 7
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", None)
@ -553,7 +553,7 @@ async def test_hmip_cover_slats_group(
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][1] == (0,)
await async_manipulate_test_data(hass, hmip_device, "shutterLevel", 0.5)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0)
@ -569,7 +569,7 @@ async def test_hmip_cover_slats_group(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 5
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][1] == (0.5,)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 0.5)
ha_state = hass.states.get(entity_id)
@ -581,7 +581,7 @@ async def test_hmip_cover_slats_group(
"cover", "close_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 7
assert hmip_device.mock_calls[-1][0] == "set_slats_level"
assert hmip_device.mock_calls[-1][0] == "set_slats_level_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "slatsLevel", 1)
ha_state = hass.states.get(entity_id)
@ -593,5 +593,5 @@ async def test_hmip_cover_slats_group(
"cover", "stop_cover_tilt", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 9
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop"
assert hmip_device.mock_calls[-1][0] == "set_shutter_stop_async"
assert hmip_device.mock_calls[-1][1] == ()

View File

@ -257,14 +257,14 @@ async def test_hmip_reset_energy_counter_services(
{"entity_id": "switch.pc"},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "reset_energy_counter"
assert len(hmip_device._connection.mock_calls) == 2
assert hmip_device.mock_calls[-1][0] == "reset_energy_counter_async"
assert len(hmip_device._connection.mock_calls) == 1
await hass.services.async_call(
"homematicip_cloud", "reset_energy_counter", {"entity_id": "all"}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "reset_energy_counter"
assert len(hmip_device._connection.mock_calls) == 4
assert hmip_device.mock_calls[-1][0] == "reset_energy_counter_async"
assert len(hmip_device._connection.mock_calls) == 2
async def test_hmip_multi_area_device(

View File

@ -2,8 +2,9 @@
from unittest.mock import Mock, patch
from homematicip.aio.auth import AsyncAuth
from homematicip.auth import Auth
from homematicip.base.base_connection import HmipConnectionError
from homematicip.connection.connection_context import ConnectionContext
import pytest
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
@ -48,13 +49,13 @@ async def test_auth_auth_check_and_register(hass: HomeAssistant) -> None:
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
hmip_auth.auth = Mock(spec=AsyncAuth)
hmip_auth.auth = Mock(spec=Auth)
with (
patch.object(hmip_auth.auth, "isRequestAcknowledged", return_value=True),
patch.object(hmip_auth.auth, "requestAuthToken", return_value="ABC"),
patch.object(hmip_auth.auth, "is_request_acknowledged", return_value=True),
patch.object(hmip_auth.auth, "request_auth_token", return_value="ABC"),
patch.object(
hmip_auth.auth,
"confirmAuthToken",
"confirm_auth_token",
),
):
assert await hmip_auth.async_checkbutton()
@ -65,13 +66,13 @@ async def test_auth_auth_check_and_register_with_exception(hass: HomeAssistant)
"""Test auth client registration."""
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
hmip_auth.auth = Mock(spec=AsyncAuth)
hmip_auth.auth = Mock(spec=Auth)
with (
patch.object(
hmip_auth.auth, "isRequestAcknowledged", side_effect=HmipConnectionError
hmip_auth.auth, "is_request_acknowledged", side_effect=HmipConnectionError
),
patch.object(
hmip_auth.auth, "requestAuthToken", side_effect=HmipConnectionError
hmip_auth.auth, "request_auth_token", side_effect=HmipConnectionError
),
):
assert not await hmip_auth.async_checkbutton()
@ -128,6 +129,10 @@ async def test_hap_reset_unloads_entry_if_setup(
assert hass.data[HMIPC_DOMAIN] == {}
@patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
)
async def test_hap_create(
hass: HomeAssistant, hmip_config_entry: MockConfigEntry, simple_mock_home
) -> None:
@ -140,6 +145,10 @@ async def test_hap_create(
assert await hap.async_setup()
@patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
)
async def test_hap_create_exception(
hass: HomeAssistant, hmip_config_entry: MockConfigEntry, mock_connection_init
) -> None:
@ -150,14 +159,14 @@ async def test_hap_create_exception(
assert hap
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state_async",
side_effect=Exception,
):
assert not await hap.async_setup()
with (
patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state_async",
side_effect=HmipConnectionError,
),
pytest.raises(ConfigEntryNotReady),
@ -171,9 +180,15 @@ async def test_auth_create(hass: HomeAssistant, simple_mock_auth) -> None:
hmip_auth = HomematicipAuth(hass, config)
assert hmip_auth
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
with (
patch(
"homeassistant.components.homematicip_cloud.hap.Auth",
return_value=simple_mock_auth,
),
patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
),
):
assert await hmip_auth.async_setup()
await hass.async_block_till_done()
@ -184,16 +199,28 @@ async def test_auth_create_exception(hass: HomeAssistant, simple_mock_auth) -> N
"""Mock AsyncAuth to execute get_auth."""
config = {HMIPC_HAPID: HAPID, HMIPC_PIN: HAPPIN, HMIPC_NAME: "hmip"}
hmip_auth = HomematicipAuth(hass, config)
simple_mock_auth.connectionRequest.side_effect = HmipConnectionError
simple_mock_auth.connection_request.side_effect = HmipConnectionError
assert hmip_auth
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
with (
patch(
"homeassistant.components.homematicip_cloud.hap.Auth",
return_value=simple_mock_auth,
),
patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
),
):
assert not await hmip_auth.async_setup()
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncAuth",
return_value=simple_mock_auth,
with (
patch(
"homeassistant.components.homematicip_cloud.hap.Auth",
return_value=simple_mock_auth,
),
patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
),
):
assert not await hmip_auth.get_auth(hass, HAPID, HAPPIN)

View File

@ -3,6 +3,7 @@
from unittest.mock import AsyncMock, Mock, patch
from homematicip.base.base_connection import HmipConnectionError
from homematicip.connection.connection_context import ConnectionContext
from homeassistant.components.homematicip_cloud.const import (
CONF_ACCESSPOINT,
@ -105,9 +106,15 @@ async def test_load_entry_fails_due_to_connection_error(
"""Test load entry fails due to connection error."""
hmip_config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
side_effect=HmipConnectionError,
with (
patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state_async",
side_effect=HmipConnectionError,
),
patch(
"homeassistant.components.homematicip_cloud.hap.ConnectionContextBuilder.build_context_async",
return_value=ConnectionContext(),
),
):
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
@ -123,12 +130,9 @@ async def test_load_entry_fails_due_to_generic_exception(
with (
patch(
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state_async",
side_effect=Exception,
),
patch(
"homematicip.aio.connection.AsyncConnection.init",
),
):
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
@ -175,7 +179,7 @@ async def test_hmip_dump_hap_config_services(
"homematicip_cloud", "dump_hap_config", {"anonymize": True}, blocking=True
)
home = mock_hap_with_service.home
assert home.mock_calls[-1][0] == "download_configuration"
assert home.mock_calls[-1][0] == "download_configuration_async"
assert home.mock_calls
assert write_mock.mock_calls

View File

@ -54,7 +54,7 @@ async def test_hmip_light(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", False)
@ -68,7 +68,7 @@ async def test_hmip_light(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", True)
@ -104,7 +104,7 @@ async def test_hmip_notification_light(
{"entity_id": entity_id, "brightness_pct": "100", "transition": 100},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time_async"
assert hmip_device.mock_calls[-1][2] == {
"channelIndex": 2,
"rgb": "RED",
@ -130,7 +130,7 @@ async def test_hmip_notification_light(
{"entity_id": entity_id, "hs_color": hs_color},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time_async"
assert hmip_device.mock_calls[-1][2] == {
"channelIndex": 2,
"dimLevel": 0.0392156862745098,
@ -157,7 +157,7 @@ async def test_hmip_notification_light(
"light", "turn_off", {"entity_id": entity_id, "transition": 100}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 11
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time_async"
assert hmip_device.mock_calls[-1][2] == {
"channelIndex": 2,
"dimLevel": 0.0,
@ -294,7 +294,7 @@ async def test_hmip_dimmer(
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 1)
await hass.services.async_call(
@ -304,7 +304,7 @@ async def test_hmip_dimmer(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1.0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1)
ha_state = hass.states.get(entity_id)
@ -318,7 +318,7 @@ async def test_hmip_dimmer(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0)
ha_state = hass.states.get(entity_id)
@ -355,7 +355,7 @@ async def test_hmip_light_measuring(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", True)
await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50)
@ -369,7 +369,7 @@ async def test_hmip_light_measuring(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -400,7 +400,7 @@ async def test_hmip_wired_multi_dimmer(
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 1)
await hass.services.async_call(
@ -410,7 +410,7 @@ async def test_hmip_wired_multi_dimmer(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
ha_state = hass.states.get(entity_id)
@ -424,7 +424,7 @@ async def test_hmip_wired_multi_dimmer(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
ha_state = hass.states.get(entity_id)
@ -459,7 +459,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 1)
await hass.services.async_call(
@ -469,7 +469,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=1)
ha_state = hass.states.get(entity_id)
@ -483,7 +483,7 @@ async def test_hmip_din_rail_dimmer_3_channel1(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 1)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=1)
ha_state = hass.states.get(entity_id)
@ -518,7 +518,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 2)
await hass.services.async_call(
@ -528,7 +528,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 2)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=2)
ha_state = hass.states.get(entity_id)
@ -542,7 +542,7 @@ async def test_hmip_din_rail_dimmer_3_channel2(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 2)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=2)
ha_state = hass.states.get(entity_id)
@ -577,7 +577,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (1, 3)
await hass.services.async_call(
@ -587,7 +587,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
blocking=True,
)
assert len(hmip_device.mock_calls) == service_call_counter + 2
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0.39215686274509803, 3)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, channel=3)
ha_state = hass.states.get(entity_id)
@ -601,7 +601,7 @@ async def test_hmip_din_rail_dimmer_3_channel3(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 4
assert hmip_device.mock_calls[-1][0] == "set_dim_level"
assert hmip_device.mock_calls[-1][0] == "set_dim_level_async"
assert hmip_device.mock_calls[-1][1] == (0, 3)
await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, channel=3)
ha_state = hass.states.get(entity_id)

View File

@ -50,7 +50,7 @@ async def test_hmip_doorlockdrive(
{"entity_id": entity_id},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_lock_state"
assert hmip_device.mock_calls[-1][0] == "set_lock_state_async"
assert hmip_device.mock_calls[-1][1] == (HomematicLockState.OPEN,)
await hass.services.async_call(
@ -59,7 +59,7 @@ async def test_hmip_doorlockdrive(
{"entity_id": entity_id},
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_lock_state"
assert hmip_device.mock_calls[-1][0] == "set_lock_state_async"
assert hmip_device.mock_calls[-1][1] == (HomematicLockState.LOCKED,)
await hass.services.async_call(
@ -69,7 +69,7 @@ async def test_hmip_doorlockdrive(
blocking=True,
)
assert hmip_device.mock_calls[-1][0] == "set_lock_state"
assert hmip_device.mock_calls[-1][0] == "set_lock_state_async"
assert hmip_device.mock_calls[-1][1] == (HomematicLockState.UNLOCKED,)
await async_manipulate_test_data(
@ -96,7 +96,7 @@ async def test_hmip_doorlockdrive_handle_errors(
test_devices=[entity_name]
)
with patch(
"homematicip.aio.device.AsyncDoorLockDrive.set_lock_state",
"homematicip.device.DoorLockDrive.set_lock_state_async",
return_value={
"errorCode": "INVALID_NUMBER_PARAMETER_VALUE",
"minValue": 0.0,

View File

@ -42,7 +42,7 @@ async def test_hmip_switch(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -52,7 +52,7 @@ async def test_hmip_switch(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)
@ -81,7 +81,7 @@ async def test_hmip_switch_input(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -91,7 +91,7 @@ async def test_hmip_switch_input(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)
@ -120,7 +120,7 @@ async def test_hmip_switch_measuring(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -130,7 +130,7 @@ async def test_hmip_switch_measuring(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", True)
await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50)
@ -158,7 +158,7 @@ async def test_hmip_group_switch(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -168,7 +168,7 @@ async def test_hmip_group_switch(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == ()
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)
@ -208,7 +208,7 @@ async def test_hmip_multi_switch(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)
@ -218,7 +218,7 @@ async def test_hmip_multi_switch(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -259,7 +259,7 @@ async def test_hmip_wired_multi_switch(
"switch", "turn_off", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 1
assert hmip_device.mock_calls[-1][0] == "turn_off"
assert hmip_device.mock_calls[-1][0] == "turn_off_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
@ -269,7 +269,7 @@ async def test_hmip_wired_multi_switch(
"switch", "turn_on", {"entity_id": entity_id}, blocking=True
)
assert len(hmip_device.mock_calls) == service_call_counter + 3
assert hmip_device.mock_calls[-1][0] == "turn_on"
assert hmip_device.mock_calls[-1][0] == "turn_on_async"
assert hmip_device.mock_calls[-1][1] == (1,)
await async_manipulate_test_data(hass, hmip_device, "on", True)
ha_state = hass.states.get(entity_id)