mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add device attribute for homematicip_cloud rotary handle (#39144)
This commit is contained in:
parent
77490287e9
commit
b5c2c9ec9b
@ -87,11 +87,10 @@ async def async_setup_entry(
|
||||
entities.append(HomematicipAccelerationSensor(hap, device))
|
||||
if isinstance(device, (AsyncContactInterface, AsyncFullFlushContactInterface)):
|
||||
entities.append(HomematicipContactInterface(hap, device))
|
||||
if isinstance(
|
||||
device,
|
||||
(AsyncShutterContact, AsyncShutterContactMagnetic, AsyncRotaryHandleSensor),
|
||||
):
|
||||
if isinstance(device, (AsyncShutterContact, AsyncShutterContactMagnetic),):
|
||||
entities.append(HomematicipShutterContact(hap, device))
|
||||
if isinstance(device, AsyncRotaryHandleSensor):
|
||||
entities.append(HomematicipShutterContact(hap, device, True))
|
||||
if isinstance(
|
||||
device,
|
||||
(
|
||||
@ -176,6 +175,13 @@ class HomematicipContactInterface(HomematicipGenericEntity, BinarySensorEntity):
|
||||
class HomematicipShutterContact(HomematicipGenericEntity, BinarySensorEntity):
|
||||
"""Representation of the HomematicIP shutter contact."""
|
||||
|
||||
def __init__(
|
||||
self, hap: HomematicipHAP, device, has_additional_state: bool = False
|
||||
) -> None:
|
||||
"""Initialize the shutter contact."""
|
||||
super().__init__(hap, device)
|
||||
self.has_additional_state = has_additional_state
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
"""Return the class of this sensor."""
|
||||
@ -188,6 +194,18 @@ class HomematicipShutterContact(HomematicipGenericEntity, BinarySensorEntity):
|
||||
return None
|
||||
return self._device.windowState != WindowState.CLOSED
|
||||
|
||||
@property
|
||||
def device_state_attributes(self) -> Dict[str, Any]:
|
||||
"""Return the state attributes of the Shutter Contact."""
|
||||
state_attr = super().device_state_attributes
|
||||
|
||||
if self.has_additional_state:
|
||||
window_state = getattr(self._device, "windowState", None)
|
||||
if window_state and window_state != WindowState.CLOSED:
|
||||
state_attr[ATTR_WINDOW_STATE] = window_state
|
||||
|
||||
return state_attr
|
||||
|
||||
|
||||
class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
|
||||
"""Representation of the HomematicIP motion detector."""
|
||||
|
@ -112,11 +112,19 @@ async def test_hmip_shutter_contact(hass, default_mock_hap_factory):
|
||||
)
|
||||
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.attributes[ATTR_WINDOW_STATE] == WindowState.TILTED
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "windowState", WindowState.OPEN)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_ON
|
||||
assert ha_state.attributes[ATTR_WINDOW_STATE] == WindowState.OPEN
|
||||
|
||||
await async_manipulate_test_data(
|
||||
hass, hmip_device, "windowState", WindowState.CLOSED
|
||||
)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
assert ha_state.state == STATE_OFF
|
||||
assert not ha_state.attributes.get(ATTR_WINDOW_STATE)
|
||||
|
||||
await async_manipulate_test_data(hass, hmip_device, "windowState", None)
|
||||
ha_state = hass.states.get(entity_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user