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 authored and Alexei Chetroi committed 2019-06-07 11:13:55 -04:00
1 parent a79224aba8
commit 592d30d495
3 files changed
+21 -123

No files matched your search

+17 -49
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')
@@ -110,17 +110,11 @@ def establish_device_mappings():
BINDABLE_CLUSTERS.append(zcl.clusters.lighting.Color.cluster_id)
DEVICE_CLASS[zha.PROFILE_ID].update({
zha.DeviceType.ON_OFF_SWITCH: BINARY_SENSOR,
zha.DeviceType.LEVEL_CONTROL_SWITCH: BINARY_SENSOR,
zha.DeviceType.REMOTE_CONTROL: BINARY_SENSOR,
zha.DeviceType.SMART_PLUG: SWITCH,
zha.DeviceType.LEVEL_CONTROLLABLE_OUTPUT: LIGHT,
zha.DeviceType.ON_OFF_LIGHT: LIGHT,
zha.DeviceType.DIMMABLE_LIGHT: LIGHT,
zha.DeviceType.COLOR_DIMMABLE_LIGHT: LIGHT,
zha.DeviceType.ON_OFF_LIGHT_SWITCH: BINARY_SENSOR,
zha.DeviceType.DIMMER_SWITCH: BINARY_SENSOR,
zha.DeviceType.COLOR_DIMMER_SWITCH: BINARY_SENSOR,
zha.DeviceType.COLOR_DIMMABLE_LIGHT: LIGHT
})
DEVICE_CLASS[zll.PROFILE_ID].update({
@@ -130,12 +124,7 @@ def establish_device_mappings():
zll.DeviceType.DIMMABLE_PLUGIN_UNIT: LIGHT,
zll.DeviceType.COLOR_LIGHT: LIGHT,
zll.DeviceType.EXTENDED_COLOR_LIGHT: LIGHT,
zll.DeviceType.COLOR_TEMPERATURE_LIGHT: LIGHT,
zll.DeviceType.COLOR_CONTROLLER: BINARY_SENSOR,
zll.DeviceType.COLOR_SCENE_CONTROLLER: BINARY_SENSOR,
zll.DeviceType.CONTROLLER: BINARY_SENSOR,
zll.DeviceType.SCENE_CONTROLLER: BINARY_SENSOR,
zll.DeviceType.ON_OFF_SENSOR: BINARY_SENSOR,
zll.DeviceType.COLOR_TEMPERATURE_LIGHT: LIGHT
})
SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update({
@@ -285,7 +274,6 @@ def establish_device_mappings():
})
BINARY_SENSOR_CLUSTERS.add(zcl.clusters.general.OnOff.cluster_id)
BINARY_SENSOR_CLUSTERS.add(zcl.clusters.general.LevelControl.cluster_id)
BINARY_SENSOR_CLUSTERS.add(zcl.clusters.security.IasZone.cluster_id)
BINARY_SENSOR_CLUSTERS.add(
zcl.clusters.measurement.OccupancySensing.cluster_id)