diff --git a/homeassistant/components/homematicip_cloud/__init__.py b/homeassistant/components/homematicip_cloud/__init__.py index d6ae05c463a5c9c0a4479232da28162babe530bb..8cd41e0b980a7b2abe0a3bd29491761cc1bf3c33 100644 --- a/homeassistant/components/homematicip_cloud/__init__.py +++ b/homeassistant/components/homematicip_cloud/__init__.py @@ -312,7 +312,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool device_registry = await dr.async_get_registry(hass) home = hap.home # Add the HAP name from configuration if set. - hapname = home.label if not home.name else f"{home.label} {home.name}" + hapname = home.label if not home.name else f"{home.name} {home.label}" device_registry.async_get_or_create( config_entry_id=home.id, identifiers={(DOMAIN, home.id)}, diff --git a/homeassistant/components/homematicip_cloud/alarm_control_panel.py b/homeassistant/components/homematicip_cloud/alarm_control_panel.py index f61bf6f6b56d403fcdf80decc74727f30327fd41..a7b1beaec9386847441c321673d460b6518ca354 100644 --- a/homeassistant/components/homematicip_cloud/alarm_control_panel.py +++ b/homeassistant/components/homematicip_cloud/alarm_control_panel.py @@ -52,11 +52,13 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): """Initialize the alarm control panel.""" self._home = hap.home self.alarm_state = STATE_ALARM_DISARMED + self._internal_alarm_zone = None + self._external_alarm_zone = None for security_zone in security_zones: if security_zone.label == "INTERNAL": self._internal_alarm_zone = security_zone - else: + elif security_zone.label == "EXTERNAL": self._external_alarm_zone = security_zone @property @@ -110,8 +112,10 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): async def async_added_to_hass(self): """Register callbacks.""" - self._internal_alarm_zone.on_update(self._async_device_changed) - self._external_alarm_zone.on_update(self._async_device_changed) + if self._internal_alarm_zone: + self._internal_alarm_zone.on_update(self._async_device_changed) + if self._external_alarm_zone: + self._external_alarm_zone.on_update(self._async_device_changed) def _async_device_changed(self, *args, **kwargs): """Handle device state changes.""" @@ -146,7 +150,7 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): def _get_zone_alarm_state(security_zone) -> bool: - if security_zone.active: + if security_zone and security_zone.active: if ( security_zone.sabotage or security_zone.motionDetected diff --git a/homeassistant/components/homematicip_cloud/light.py b/homeassistant/components/homematicip_cloud/light.py index 044140e5582344f2b0ab661454c6e2e0209cf21e..c262b05d019bdec55004042278f56983fe22b9a7 100644 --- a/homeassistant/components/homematicip_cloud/light.py +++ b/homeassistant/components/homematicip_cloud/light.py @@ -16,6 +16,7 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_COLOR_NAME, ATTR_HS_COLOR, + ATTR_TRANSITION, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, Light, @@ -225,13 +226,28 @@ class HomematicipNotificationLight(HomematicipGenericDevice, Light): # Minimum brightness is 10, otherwise the led is disabled brightness = max(10, brightness) dim_level = brightness / 255.0 - - await self._device.set_rgb_dim_level(self.channel, simple_rgb_color, dim_level) + transition = kwargs.get(ATTR_TRANSITION, 0.5) + + await self._device.set_rgb_dim_level_with_time( + channelIndex=self.channel, + rgb=simple_rgb_color, + dimLevel=dim_level, + onTime=0, + rampTime=transition, + ) async def async_turn_off(self, **kwargs): """Turn the light off.""" simple_rgb_color = self._func_channel.simpleRGBColorState - await self._device.set_rgb_dim_level(self.channel, simple_rgb_color, 0.0) + transition = kwargs.get(ATTR_TRANSITION, 0.5) + + await self._device.set_rgb_dim_level_with_time( + channelIndex=self.channel, + rgb=simple_rgb_color, + dimLevel=0.0, + onTime=0, + rampTime=transition, + ) def _convert_color(color) -> RGBColorState: diff --git a/tests/components/homematicip_cloud/test_light.py b/tests/components/homematicip_cloud/test_light.py index a55d9ea9151b2f4673ff42a3443c42f9f8767a1c..632a6aac449e4d25331240b3337d1f7e23ca82d4 100644 --- a/tests/components/homematicip_cloud/test_light.py +++ b/tests/components/homematicip_cloud/test_light.py @@ -79,10 +79,19 @@ async def test_hmip_notification_light(hass, default_mock_hap): # Send all color via service call. await hass.services.async_call( - "light", "turn_on", {"entity_id": entity_id}, blocking=True + "light", + "turn_on", + {"entity_id": entity_id, "brightness_pct": "100", "transition": 100}, + blocking=True, ) - assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level" - assert hmip_device.mock_calls[-1][1] == (2, RGBColorState.RED, 1.0) + assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time" + assert hmip_device.mock_calls[-1][2] == { + "channelIndex": 2, + "rgb": "RED", + "dimLevel": 1.0, + "onTime": 0, + "rampTime": 100.0, + } color_list = { RGBColorState.WHITE: [0.0, 0.0], @@ -101,17 +110,17 @@ async def test_hmip_notification_light(hass, default_mock_hap): {"entity_id": entity_id, "hs_color": hs_color}, blocking=True, ) - assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level" - assert hmip_device.mock_calls[-1][1] == (2, color, 0.0392156862745098) + assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time" + assert hmip_device.mock_calls[-1][2] == { + "channelIndex": 2, + "dimLevel": 0.0392156862745098, + "onTime": 0, + "rampTime": 0.5, + "rgb": color, + } assert len(hmip_device.mock_calls) == service_call_counter + 8 - assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level" - assert hmip_device.mock_calls[-1][1] == ( - 2, - RGBColorState.PURPLE, - 0.0392156862745098, - ) await async_manipulate_test_data(hass, hmip_device, "dimLevel", 1, 2) await async_manipulate_test_data( hass, hmip_device, "simpleRGBColorState", RGBColorState.PURPLE, 2 @@ -122,11 +131,17 @@ async def test_hmip_notification_light(hass, default_mock_hap): assert ha_state.attributes[ATTR_BRIGHTNESS] == 255 await hass.services.async_call( - "light", "turn_off", {"entity_id": entity_id}, blocking=True + "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" - assert hmip_device.mock_calls[-1][1] == (2, RGBColorState.PURPLE, 0.0) + assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time" + assert hmip_device.mock_calls[-1][2] == { + "channelIndex": 2, + "dimLevel": 0.0, + "onTime": 0, + "rampTime": 100, + "rgb": "PURPLE", + } await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, 2) ha_state = hass.states.get(entity_id) assert ha_state.state == STATE_OFF