Skip to content

Commit

Permalink
Support motion detection on all-in-one sensors. (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked committed Jun 3, 2024
1 parent ea0e2db commit 0a1aad0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
aarlo
0.8.1.3
Fix missing motion event for all-in-one sensor
0.8.1.2
Fix alarm mode upgrade issue.
Bump pyaarlo revision
Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from .cfg import BlendedCfg, PyaarloCfg


__version__ = "0.8.1.2"
__version__ = "0.8.1.3"

_LOGGER = logging.getLogger(__name__)

Expand Down
43 changes: 23 additions & 20 deletions custom_components/aarlo/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
# sensor_type: Home Assistant sensor type
# description: What the sensor does.
# class: Home Assistant sensor this represents
# main attribute: Pyaarlo capability that indicates this device provides this sensor
# main attributes: Pyaarlo capability that indicates this device provides this sensor, the
# first one is used for the capability check
# extra_attributes: Another attributes to watch for this sensor
# icon: Default ICON to use.
SENSOR_TYPES_DESCRIPTION = 0
Expand All @@ -63,15 +64,15 @@
SENSOR_TYPES_OTHER_ATTRS = 3
SENSOR_TYPES_ICON = 4
SENSOR_TYPES = {
"sound": ["Sound", BinarySensorDeviceClass.SOUND, AUDIO_DETECTED_KEY, [], None],
"motion": ["Motion", BinarySensorDeviceClass.MOTION, MOTION_DETECTED_KEY, [MOTION_STATE_KEY], None],
"ding": ["Ding", None, BUTTON_PRESSED_KEY, [SILENT_MODE_KEY], "mdi:doorbell"],
"cry": ["Cry", BinarySensorDeviceClass.SOUND, CRY_DETECTION_KEY, [], None],
"connectivity": ["Connected", BinarySensorDeviceClass.CONNECTIVITY, CONNECTION_KEY, [], None],
"contact": ["Open/Close", BinarySensorDeviceClass.OPENING, CONTACT_STATE_KEY, [], None],
"light": ["Light On", BinarySensorDeviceClass.LIGHT, ALS_STATE_KEY, [], None],
"tamper": ["Tamper", BinarySensorDeviceClass.TAMPER, TAMPER_STATE_KEY, [], None],
"leak": ["Moisture", BinarySensorDeviceClass.MOISTURE, WATER_STATE_KEY, [], None],
"sound": ["Sound", BinarySensorDeviceClass.SOUND, [AUDIO_DETECTED_KEY], [], None],
"motion": ["Motion", BinarySensorDeviceClass.MOTION, [MOTION_DETECTED_KEY, MOTION_STATE_KEY], [], None],
"ding": ["Ding", None, [BUTTON_PRESSED_KEY], [SILENT_MODE_KEY], "mdi:doorbell"],
"cry": ["Cry", BinarySensorDeviceClass.SOUND, [CRY_DETECTION_KEY], [], None],
"connectivity": ["Connected", BinarySensorDeviceClass.CONNECTIVITY, [CONNECTION_KEY], [], None],
"contact": ["Open/Close", BinarySensorDeviceClass.OPENING, [CONTACT_STATE_KEY], [], None],
"light": ["Light On", BinarySensorDeviceClass.LIGHT, [ALS_STATE_KEY], [], None],
"tamper": ["Tamper", BinarySensorDeviceClass.TAMPER, [TAMPER_STATE_KEY], [], None],
"leak": ["Moisture", BinarySensorDeviceClass.MOISTURE, [WATER_STATE_KEY], [], None],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -100,19 +101,19 @@ async def async_setup_entry(
sensor_value = SENSOR_TYPES[sensor_type]
if sensor_type == "connectivity":
for base in arlo.base_stations:
if base.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR]):
if base.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR][0]):
sensors.append(ArloBinarySensor(base, aarlo_config, sensor_type, sensor_value))
for camera in arlo.cameras:
if camera.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR]):
if camera.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR][0]):
sensors.append(ArloBinarySensor(camera, aarlo_config, sensor_type, sensor_value))
for doorbell in arlo.doorbells:
if doorbell.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR]):
if doorbell.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR][0]):
sensors.append(ArloBinarySensor(doorbell, aarlo_config, sensor_type, sensor_value))
for light in arlo.lights:
if light.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR]):
if light.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR][0]):
sensors.append(ArloBinarySensor(light, aarlo_config, sensor_type, sensor_value))
for sensor in arlo.sensors:
if sensor.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR]):
if sensor.has_capability(sensor_value[SENSOR_TYPES_MAIN_ATTR][0]):
sensors.append(ArloBinarySensor(sensor, aarlo_config, sensor_type, sensor_value))

async_add_entities(sensors)
Expand All @@ -126,7 +127,7 @@ def __init__(self, device, aarlo_config, sensor_type, sensor_value):

self._device = device
self._sensor_type = sensor_type
self._main_attr = sensor_value[SENSOR_TYPES_MAIN_ATTR]
self._main_attrs = sensor_value[SENSOR_TYPES_MAIN_ATTR]
self._other_attrs = sensor_value[SENSOR_TYPES_OTHER_ATTRS]

self._attr_name = f"{sensor_value[SENSOR_TYPES_DESCRIPTION]} {device.name}"
Expand Down Expand Up @@ -156,13 +157,15 @@ async def async_added_to_hass(self):

def update_state(_device, attr, value):
_LOGGER.debug("callback:" + self._attr_name + ":" + attr + ":" + str(value)[:80])
if self._main_attr == attr:
if attr in self._main_attrs:
self._attr_is_on = self._map_value(attr, value)
self.schedule_update_ha_state()

if self._main_attr is not None:
self._attr_is_on = self._map_value(self._main_attr, self._device.attribute(self._main_attr))
self._device.add_attr_callback(self._main_attr, update_state)
for main_attr in self._main_attrs:
value = self._device.attribute(main_attr)
if value is not None:
self._attr_is_on = self._map_value(main_attr, value)
self._device.add_attr_callback(main_attr, update_state)
for other_attr in self._other_attrs:
self._device.add_attr_callback(other_attr, update_state)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"unidecode",
"pyaarlo>=0.8.0.7"
],
"version": "0.8.1.2"
"version": "0.8.1.3"
}

0 comments on commit 0a1aad0

Please sign in to comment.