Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -2,17 +2,34 @@
|
|||
import logging
|
||||
|
||||
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
|
||||
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,
|
||||
ZONE_CHANNEL, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, UNKNOWN, OPENING,
|
||||
ZONE, OCCUPANCY, SENSOR_TYPE, ACCELERATION
|
||||
DATA_ZHA,
|
||||
DATA_ZHA_DISPATCHERS,
|
||||
ZHA_DISCOVERY_NEW,
|
||||
ON_OFF_CHANNEL,
|
||||
ZONE_CHANNEL,
|
||||
SIGNAL_ATTR_UPDATED,
|
||||
ATTRIBUTE_CHANNEL,
|
||||
UNKNOWN,
|
||||
OPENING,
|
||||
ZONE,
|
||||
OCCUPANCY,
|
||||
SENSOR_TYPE,
|
||||
ACCELERATION,
|
||||
)
|
||||
from .entity import ZhaEntity
|
||||
|
||||
|
@ -20,18 +37,18 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
# Zigbee Cluster Library Zone Type to Home Assistant device class
|
||||
CLASS_MAPPING = {
|
||||
0x000d: DEVICE_CLASS_MOTION,
|
||||
0x000D: DEVICE_CLASS_MOTION,
|
||||
0x0015: DEVICE_CLASS_OPENING,
|
||||
0x0028: DEVICE_CLASS_SMOKE,
|
||||
0x002a: DEVICE_CLASS_MOISTURE,
|
||||
0x002b: DEVICE_CLASS_GAS,
|
||||
0x002d: DEVICE_CLASS_VIBRATION,
|
||||
0x002A: DEVICE_CLASS_MOISTURE,
|
||||
0x002B: DEVICE_CLASS_GAS,
|
||||
0x002D: DEVICE_CLASS_VIBRATION,
|
||||
}
|
||||
|
||||
|
||||
async def get_ias_device_class(channel):
|
||||
"""Get the HA device class from the channel."""
|
||||
zone_type = await channel.get_attribute_value('zone_type')
|
||||
zone_type = await channel.get_attribute_value("zone_type")
|
||||
return CLASS_MAPPING.get(zone_type)
|
||||
|
||||
|
||||
|
@ -44,31 +61,35 @@ DEVICE_CLASS_REGISTRY = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Old way of setting up Zigbee Home Automation binary sensors."""
|
||||
pass
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Zigbee Home Automation binary sensor from config entry."""
|
||||
|
||||
async def async_discover(discovery_info):
|
||||
await _async_setup_entities(hass, config_entry, async_add_entities,
|
||||
[discovery_info])
|
||||
await _async_setup_entities(
|
||||
hass, config_entry, async_add_entities, [discovery_info]
|
||||
)
|
||||
|
||||
unsub = async_dispatcher_connect(
|
||||
hass, ZHA_DISCOVERY_NEW.format(DOMAIN), async_discover)
|
||||
hass, ZHA_DISCOVERY_NEW.format(DOMAIN), async_discover
|
||||
)
|
||||
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
|
||||
|
||||
binary_sensors = hass.data.get(DATA_ZHA, {}).get(DOMAIN)
|
||||
if binary_sensors is not None:
|
||||
await _async_setup_entities(hass, config_entry, async_add_entities,
|
||||
binary_sensors.values())
|
||||
await _async_setup_entities(
|
||||
hass, config_entry, async_add_entities, binary_sensors.values()
|
||||
)
|
||||
del hass.data[DATA_ZHA][DOMAIN]
|
||||
|
||||
|
||||
async def _async_setup_entities(hass, config_entry, async_add_entities,
|
||||
discovery_infos):
|
||||
async def _async_setup_entities(
|
||||
hass, config_entry, async_add_entities, discovery_infos
|
||||
):
|
||||
"""Set up the ZHA binary sensors."""
|
||||
entities = []
|
||||
for discovery_info in discovery_infos:
|
||||
|
@ -94,8 +115,7 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
|
|||
|
||||
async def _determine_device_class(self):
|
||||
"""Determine the device class for this binary sensor."""
|
||||
device_class_supplier = DEVICE_CLASS_REGISTRY.get(
|
||||
self._zha_sensor_type)
|
||||
device_class_supplier = DEVICE_CLASS_REGISTRY.get(self._zha_sensor_type)
|
||||
if callable(device_class_supplier):
|
||||
channel = self.cluster_channels.get(self._zha_sensor_type)
|
||||
if channel is None:
|
||||
|
@ -109,14 +129,16 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
|
|||
await super().async_added_to_hass()
|
||||
if self._on_off_channel:
|
||||
await self.async_accept_signal(
|
||||
self._on_off_channel, SIGNAL_ATTR_UPDATED,
|
||||
self.async_set_state)
|
||||
self._on_off_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||
)
|
||||
if self._zone_channel:
|
||||
await self.async_accept_signal(
|
||||
self._zone_channel, SIGNAL_ATTR_UPDATED, self.async_set_state)
|
||||
self._zone_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||
)
|
||||
if self._attr_channel:
|
||||
await self.async_accept_signal(
|
||||
self._attr_channel, SIGNAL_ATTR_UPDATED, self.async_set_state)
|
||||
self._attr_channel, SIGNAL_ATTR_UPDATED, self.async_set_state
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_restore_last_state(self, last_state):
|
||||
|
@ -145,13 +167,12 @@ class BinarySensor(ZhaEntity, BinarySensorDevice):
|
|||
"""Attempt to retrieve on off state from the binary sensor."""
|
||||
await super().async_update()
|
||||
if self._on_off_channel:
|
||||
self._state = await self._on_off_channel.get_attribute_value(
|
||||
'on_off')
|
||||
self._state = await self._on_off_channel.get_attribute_value("on_off")
|
||||
if self._zone_channel:
|
||||
value = await self._zone_channel.get_attribute_value(
|
||||
'zone_status')
|
||||
value = await self._zone_channel.get_attribute_value("zone_status")
|
||||
if value is not None:
|
||||
self._state = value & 3
|
||||
if self._attr_channel:
|
||||
self._state = await self._attr_channel.get_attribute_value(
|
||||
self._attr_channel.value_attribute)
|
||||
self._attr_channel.value_attribute
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue