Remove binary sensors for ZHA remotes and controllers (#24370)

* remove remote binary sensor profiles
* fix contact sensors
This commit is contained in:
David F. Mulcahey 2019-06-07 11:13:55 -04:00 committed by Alexei Chetroi
parent a79224aba8
commit 592d30d495
3 changed files with 21 additions and 123 deletions

View file

@ -1,27 +1,31 @@
"""Binary sensors on Zigbee Home Automation networks."""
import logging
from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDevice
from homeassistant.components.binary_sensor import (
DOMAIN, BinarySensorDevice, DEVICE_CLASS_MOVING, DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING, DEVICE_CLASS_MOISTURE, DEVICE_CLASS_SMOKE,
DEVICE_CLASS_GAS, DEVICE_CLASS_VIBRATION, DEVICE_CLASS_OCCUPANCY
)
from homeassistant.const import STATE_ON
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .core.const import (
DATA_ZHA, DATA_ZHA_DISPATCHERS, ZHA_DISCOVERY_NEW, ON_OFF_CHANNEL,
LEVEL_CHANNEL, ZONE_CHANNEL, SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL,
SIGNAL_SET_LEVEL, ATTRIBUTE_CHANNEL, UNKNOWN, OPENING, ZONE, OCCUPANCY,
ATTR_LEVEL, SENSOR_TYPE, ACCELERATION)
ZONE_CHANNEL, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, UNKNOWN, OPENING,
ZONE, OCCUPANCY, SENSOR_TYPE, ACCELERATION
)
from .entity import ZhaEntity
_LOGGER = logging.getLogger(__name__)
# Zigbee Cluster Library Zone Type to Home Assistant device class
CLASS_MAPPING = {
0x000d: 'motion',
0x0015: 'opening',
0x0028: 'smoke',
0x002a: 'moisture',
0x002b: 'gas',
0x002d: 'vibration',
0x000d: DEVICE_CLASS_MOTION,
0x0015: DEVICE_CLASS_OPENING,
0x0028: DEVICE_CLASS_SMOKE,
0x002a: DEVICE_CLASS_MOISTURE,
0x002b: DEVICE_CLASS_GAS,
0x002d: DEVICE_CLASS_VIBRATION,
}
@ -33,10 +37,10 @@ async def get_ias_device_class(channel):
DEVICE_CLASS_REGISTRY = {
UNKNOWN: None,
OPENING: OPENING,
OPENING: DEVICE_CLASS_OPENING,
ZONE: get_ias_device_class,
OCCUPANCY: OCCUPANCY,
ACCELERATION: 'moving',
OCCUPANCY: DEVICE_CLASS_OCCUPANCY,
ACCELERATION: DEVICE_CLASS_MOVING,
}
@ -85,10 +89,8 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
self._device_state_attributes = {}
self._zone_channel = self.cluster_channels.get(ZONE_CHANNEL)
self._on_off_channel = self.cluster_channels.get(ON_OFF_CHANNEL)
self._level_channel = self.cluster_channels.get(LEVEL_CHANNEL)
self._attr_channel = self.cluster_channels.get(ATTRIBUTE_CHANNEL)
self._zha_sensor_type = kwargs[SENSOR_TYPE]
self._level = None
async def _determine_device_class(self):
"""Determine the device class for this binary sensor."""
@ -105,11 +107,6 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
"""Run when about to be added to hass."""
self._device_class = await self._determine_device_class()
await super().async_added_to_hass()
if self._level_channel:
await self.async_accept_signal(
self._level_channel, SIGNAL_SET_LEVEL, self.set_level)
await self.async_accept_signal(
self._level_channel, SIGNAL_MOVE_LEVEL, self.move_level)
if self._on_off_channel:
await self.async_accept_signal(
self._on_off_channel, SIGNAL_ATTR_UPDATED,
@ -126,8 +123,6 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
"""Restore previous state."""
super().async_restore_last_state(last_state)
self._state = last_state.state == STATE_ON
if 'level' in last_state.attributes:
self._level = last_state.attributes['level']
@property
def is_on(self) -> bool:
@ -146,36 +141,9 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
self._state = bool(state)
self.async_schedule_update_ha_state()
def move_level(self, change):
"""Increment the level, setting state if appropriate."""
level = self._level or 0
if not self._state and change > 0:
level = 0
self._level = min(254, max(0, level + change))
self._state = bool(self._level)
self.async_schedule_update_ha_state()
def set_level(self, level):
"""Set the level, setting state if appropriate."""
self._level = level
self._state = bool(level)
self.async_schedule_update_ha_state()
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self._level_channel is not None:
self._device_state_attributes.update({
ATTR_LEVEL: self._state and self._level or 0
})
return self._device_state_attributes
async def async_update(self):
"""Attempt to retrieve on off state from the binary sensor."""
await super().async_update()
if self._level_channel:
self._level = await self._level_channel.get_attribute_value(
'current_level')
if self._on_off_channel:
self._state = await self._on_off_channel.get_attribute_value(
'on_off')