Add support for HomeKit motion sensor devices (#20555)

This commit is contained in:
Jc2k authored and Paulus Schoutsen committed 2019-01-28 20:30:56 -08:00
1 parent cc74035c3b
commit e22802a4d4
3 files changed
+86 -1

No files matched your search

@@ -28,7 +28,8 @@ HOMEKIT_ACCESSORY_DISPATCH = {
'garage-door-opener': 'cover',
'window': 'cover',
'window-covering': 'cover',
'lock-mechanism': 'lock'
'lock-mechanism': 'lock',
'motion': 'binary_sensor',
}
HOMEKIT_IGNORE = [
@@ -0,0 +1,55 @@
"""
Support for Homekit motion sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.homekit_controller/
"""
import logging
from homeassistant.components.homekit_controller import (HomeKitEntity,
KNOWN_ACCESSORIES)
from homeassistant.components.binary_sensor import BinarySensorDevice
DEPENDENCIES = ['homekit_controller']
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up Homekit motion sensor support."""
if discovery_info is not None:
accessory = hass.data[KNOWN_ACCESSORIES][discovery_info['serial']]
add_entities([HomeKitMotionSensor(accessory, discovery_info)], True)
class HomeKitMotionSensor(HomeKitEntity, BinarySensorDevice):
"""Representation of a Homekit sensor."""
def __init__(self, *args):
"""Initialise the entity."""
super().__init__(*args)
self._on = False
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
# pylint: disable=import-error
from homekit.model.characteristics import CharacteristicsTypes
return [
CharacteristicsTypes.MOTION_DETECTED,
]
def _update_motion_detected(self, value):
self._on = value
@property
def device_class(self):
"""Define this binary_sensor as a motion sensor."""
return 'motion'
@property
def is_on(self):
"""Has motion been detected."""
if not self.available:
return False
return self._on