Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from homematicip.aio.device import (
AsyncAccelerationSensor,
AsyncContactInterface,
AsyncDevice,
AsyncFullFlushContactInterface,
Expand All @@ -28,6 +29,7 @@
DEVICE_CLASS_LIGHT,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_MOVING,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_PRESENCE,
DEVICE_CLASS_SAFETY,
Expand All @@ -42,6 +44,10 @@

_LOGGER = logging.getLogger(__name__)

ATTR_ACCELERATION_SENSOR_MODE = "acceleration_sensor_mode"
ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION = "acceleration_sensor_neutral_position"
ATTR_ACCELERATION_SENSOR_SENSITIVITY = "acceleration_sensor_sensitivity"
ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE = "acceleration_sensor_trigger_angle"
ATTR_LOW_BATTERY = "low_battery"
ATTR_MOISTURE_DETECTED = "moisture_detected"
ATTR_MOTION_DETECTED = "motion_detected"
Expand All @@ -63,6 +69,13 @@
"waterlevelDetected": ATTR_WATER_LEVEL_DETECTED,
}

SAM_DEVICE_ATTRIBUTES = {
"accelerationSensorNeutralPosition": ATTR_ACCELERATION_SENSOR_NEUTRAL_POSITION,
"accelerationSensorMode": ATTR_ACCELERATION_SENSOR_MODE,
"accelerationSensorSensitivity": ATTR_ACCELERATION_SENSOR_SENSITIVITY,
"accelerationSensorTriggerAngle": ATTR_ACCELERATION_SENSOR_TRIGGER_ANGLE,
}


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the HomematicIP Cloud binary sensor devices."""
Expand All @@ -76,6 +89,8 @@ async def async_setup_entry(
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.devices:
if isinstance(device, AsyncAccelerationSensor):
devices.append(HomematicipAccelerationSensor(home, device))
if isinstance(device, (AsyncContactInterface, AsyncFullFlushContactInterface)):
devices.append(HomematicipContactInterface(home, device))
if isinstance(
Expand Down Expand Up @@ -118,6 +133,32 @@ async def async_setup_entry(
async_add_entities(devices)


class HomematicipAccelerationSensor(HomematicipGenericDevice, BinarySensorDevice):
"""Representation of a HomematicIP Cloud acceleration sensor."""

@property
def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_MOVING

@property
def is_on(self) -> bool:
"""Return true if acceleration is detected."""
return self._device.accelerationSensorTriggered

@property
def device_state_attributes(self):
"""Return the state attributes of the acceleration sensor."""
state_attr = super().device_state_attributes

for attr, attr_key in SAM_DEVICE_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None)
if attr_value:
state_attr[attr_key] = attr_value

return state_attr


class HomematicipContactInterface(HomematicipGenericDevice, BinarySensorDevice):
"""Representation of a HomematicIP Cloud contact interface."""

Expand Down