From 0a1aad0a7b07f1a5acf521f0abd6b2708958681f Mon Sep 17 00:00:00 2001 From: Steve Herrell <47094394+twrecked@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:21:49 -0400 Subject: [PATCH] Support motion detection on all-in-one sensors. (#961) --- changelog | 2 ++ custom_components/aarlo/__init__.py | 2 +- custom_components/aarlo/binary_sensor.py | 43 +++++++++++++----------- custom_components/aarlo/manifest.json | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/changelog b/changelog index febfc8bf..d3b2fe13 100644 --- a/changelog +++ b/changelog @@ -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 diff --git a/custom_components/aarlo/__init__.py b/custom_components/aarlo/__init__.py index 6b8300b7..8acf3e2e 100644 --- a/custom_components/aarlo/__init__.py +++ b/custom_components/aarlo/__init__.py @@ -53,7 +53,7 @@ from .cfg import BlendedCfg, PyaarloCfg -__version__ = "0.8.1.2" +__version__ = "0.8.1.3" _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/aarlo/binary_sensor.py b/custom_components/aarlo/binary_sensor.py index 2c5287f3..b070ae2e 100644 --- a/custom_components/aarlo/binary_sensor.py +++ b/custom_components/aarlo/binary_sensor.py @@ -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 @@ -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({ @@ -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) @@ -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}" @@ -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) diff --git a/custom_components/aarlo/manifest.json b/custom_components/aarlo/manifest.json index d4078530..adf7cbc0 100644 --- a/custom_components/aarlo/manifest.json +++ b/custom_components/aarlo/manifest.json @@ -15,5 +15,5 @@ "unidecode", "pyaarlo>=0.8.0.7" ], - "version": "0.8.1.2" + "version": "0.8.1.3" }