Skip to content
Snippets Groups Projects
Commit 33c8cba3 authored by SukramJ's avatar SukramJ Committed by Martin Hjelmare
Browse files

Enable transition time for HmIP-BSL - HomematicIP Cloud (#28201)

* Enable transition time for HmIP-BSL - HomematicIP Cloud

harden ACP
fix hao device name

* update test, initalize instance var
parent b7296c61
No related branches found
No related tags found
No related merge requests found
...@@ -312,7 +312,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool ...@@ -312,7 +312,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
device_registry = await dr.async_get_registry(hass) device_registry = await dr.async_get_registry(hass)
home = hap.home home = hap.home
# Add the HAP name from configuration if set. # 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( device_registry.async_get_or_create(
config_entry_id=home.id, config_entry_id=home.id,
identifiers={(DOMAIN, home.id)}, identifiers={(DOMAIN, home.id)},
......
...@@ -52,11 +52,13 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): ...@@ -52,11 +52,13 @@ class HomematicipAlarmControlPanel(AlarmControlPanel):
"""Initialize the alarm control panel.""" """Initialize the alarm control panel."""
self._home = hap.home self._home = hap.home
self.alarm_state = STATE_ALARM_DISARMED self.alarm_state = STATE_ALARM_DISARMED
self._internal_alarm_zone = None
self._external_alarm_zone = None
for security_zone in security_zones: for security_zone in security_zones:
if security_zone.label == "INTERNAL": if security_zone.label == "INTERNAL":
self._internal_alarm_zone = security_zone self._internal_alarm_zone = security_zone
else: elif security_zone.label == "EXTERNAL":
self._external_alarm_zone = security_zone self._external_alarm_zone = security_zone
@property @property
...@@ -110,8 +112,10 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): ...@@ -110,8 +112,10 @@ class HomematicipAlarmControlPanel(AlarmControlPanel):
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Register callbacks.""" """Register callbacks."""
self._internal_alarm_zone.on_update(self._async_device_changed) if self._internal_alarm_zone:
self._external_alarm_zone.on_update(self._async_device_changed) 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): def _async_device_changed(self, *args, **kwargs):
"""Handle device state changes.""" """Handle device state changes."""
...@@ -146,7 +150,7 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): ...@@ -146,7 +150,7 @@ class HomematicipAlarmControlPanel(AlarmControlPanel):
def _get_zone_alarm_state(security_zone) -> bool: def _get_zone_alarm_state(security_zone) -> bool:
if security_zone.active: if security_zone and security_zone.active:
if ( if (
security_zone.sabotage security_zone.sabotage
or security_zone.motionDetected or security_zone.motionDetected
......
...@@ -16,6 +16,7 @@ from homeassistant.components.light import ( ...@@ -16,6 +16,7 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_COLOR_NAME, ATTR_COLOR_NAME,
ATTR_HS_COLOR, ATTR_HS_COLOR,
ATTR_TRANSITION,
SUPPORT_BRIGHTNESS, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR, SUPPORT_COLOR,
Light, Light,
...@@ -225,13 +226,28 @@ class HomematicipNotificationLight(HomematicipGenericDevice, Light): ...@@ -225,13 +226,28 @@ class HomematicipNotificationLight(HomematicipGenericDevice, Light):
# Minimum brightness is 10, otherwise the led is disabled # Minimum brightness is 10, otherwise the led is disabled
brightness = max(10, brightness) brightness = max(10, brightness)
dim_level = brightness / 255.0 dim_level = brightness / 255.0
transition = kwargs.get(ATTR_TRANSITION, 0.5)
await self._device.set_rgb_dim_level(self.channel, simple_rgb_color, dim_level)
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): async def async_turn_off(self, **kwargs):
"""Turn the light off.""" """Turn the light off."""
simple_rgb_color = self._func_channel.simpleRGBColorState 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: def _convert_color(color) -> RGBColorState:
......
...@@ -79,10 +79,19 @@ async def test_hmip_notification_light(hass, default_mock_hap): ...@@ -79,10 +79,19 @@ async def test_hmip_notification_light(hass, default_mock_hap):
# Send all color via service call. # Send all color via service call.
await hass.services.async_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][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][1] == (2, RGBColorState.RED, 1.0) assert hmip_device.mock_calls[-1][2] == {
"channelIndex": 2,
"rgb": "RED",
"dimLevel": 1.0,
"onTime": 0,
"rampTime": 100.0,
}
color_list = { color_list = {
RGBColorState.WHITE: [0.0, 0.0], RGBColorState.WHITE: [0.0, 0.0],
...@@ -101,17 +110,17 @@ async def test_hmip_notification_light(hass, default_mock_hap): ...@@ -101,17 +110,17 @@ async def test_hmip_notification_light(hass, default_mock_hap):
{"entity_id": entity_id, "hs_color": hs_color}, {"entity_id": entity_id, "hs_color": hs_color},
blocking=True, blocking=True,
) )
assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level" assert hmip_device.mock_calls[-1][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][1] == (2, color, 0.0392156862745098) 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 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, "dimLevel", 1, 2)
await async_manipulate_test_data( await async_manipulate_test_data(
hass, hmip_device, "simpleRGBColorState", RGBColorState.PURPLE, 2 hass, hmip_device, "simpleRGBColorState", RGBColorState.PURPLE, 2
...@@ -122,11 +131,17 @@ async def test_hmip_notification_light(hass, default_mock_hap): ...@@ -122,11 +131,17 @@ async def test_hmip_notification_light(hass, default_mock_hap):
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255 assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
await hass.services.async_call( 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 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][0] == "set_rgb_dim_level_with_time"
assert hmip_device.mock_calls[-1][1] == (2, RGBColorState.PURPLE, 0.0) 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) await async_manipulate_test_data(hass, hmip_device, "dimLevel", 0, 2)
ha_state = hass.states.get(entity_id) ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF assert ha_state.state == STATE_OFF
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment