Black format code
This commit is contained in:
parent
34deaf8849
commit
d732a7e670
1368 changed files with 69529 additions and 53340 deletions
|
@ -6,38 +6,47 @@ https://home-assistant.io/components/binary_sensor.deconz/
|
|||
"""
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.deconz.const import (
|
||||
ATTR_DARK, ATTR_ON, CONF_ALLOW_CLIP_SENSOR, DOMAIN as DATA_DECONZ,
|
||||
DATA_DECONZ_ID, DATA_DECONZ_UNSUB, DECONZ_DOMAIN)
|
||||
ATTR_DARK,
|
||||
ATTR_ON,
|
||||
CONF_ALLOW_CLIP_SENSOR,
|
||||
DOMAIN as DATA_DECONZ,
|
||||
DATA_DECONZ_ID,
|
||||
DATA_DECONZ_UNSUB,
|
||||
DECONZ_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
DEPENDENCIES = ['deconz']
|
||||
DEPENDENCIES = ["deconz"]
|
||||
|
||||
|
||||
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 deCONZ binary sensors."""
|
||||
pass
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the deCONZ binary sensor."""
|
||||
|
||||
@callback
|
||||
def async_add_sensor(sensors):
|
||||
"""Add binary sensor from deCONZ."""
|
||||
from pydeconz.sensor import DECONZ_BINARY_SENSOR
|
||||
|
||||
entities = []
|
||||
allow_clip_sensor = config_entry.data.get(CONF_ALLOW_CLIP_SENSOR, True)
|
||||
for sensor in sensors:
|
||||
if sensor.type in DECONZ_BINARY_SENSOR and \
|
||||
not (not allow_clip_sensor and sensor.type.startswith('CLIP')):
|
||||
if sensor.type in DECONZ_BINARY_SENSOR and not (
|
||||
not allow_clip_sensor and sensor.type.startswith("CLIP")
|
||||
):
|
||||
entities.append(DeconzBinarySensor(sensor))
|
||||
async_add_entities(entities, True)
|
||||
|
||||
hass.data[DATA_DECONZ_UNSUB].append(
|
||||
async_dispatcher_connect(hass, 'deconz_new_sensor', async_add_sensor))
|
||||
async_dispatcher_connect(hass, "deconz_new_sensor", async_add_sensor)
|
||||
)
|
||||
|
||||
async_add_sensor(hass.data[DATA_DECONZ].sensors.values())
|
||||
|
||||
|
@ -66,10 +75,12 @@ class DeconzBinarySensor(BinarySensorDevice):
|
|||
If reason is that state is updated,
|
||||
or reachable has changed or battery has changed.
|
||||
"""
|
||||
if reason['state'] or \
|
||||
'reachable' in reason['attr'] or \
|
||||
'battery' in reason['attr'] or \
|
||||
'on' in reason['attr']:
|
||||
if (
|
||||
reason["state"]
|
||||
or "reachable" in reason["attr"]
|
||||
or "battery" in reason["attr"]
|
||||
or "on" in reason["attr"]
|
||||
):
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
|
@ -111,6 +122,7 @@ class DeconzBinarySensor(BinarySensorDevice):
|
|||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
from pydeconz.sensor import PRESENCE
|
||||
|
||||
attr = {}
|
||||
if self._sensor.battery:
|
||||
attr[ATTR_BATTERY_LEVEL] = self._sensor.battery
|
||||
|
@ -123,15 +135,14 @@ class DeconzBinarySensor(BinarySensorDevice):
|
|||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
if (self._sensor.uniqueid is None or
|
||||
self._sensor.uniqueid.count(':') != 7):
|
||||
if self._sensor.uniqueid is None or self._sensor.uniqueid.count(":") != 7:
|
||||
return None
|
||||
serial = self._sensor.uniqueid.split('-', 1)[0]
|
||||
serial = self._sensor.uniqueid.split("-", 1)[0]
|
||||
return {
|
||||
'connections': {(CONNECTION_ZIGBEE, serial)},
|
||||
'identifiers': {(DECONZ_DOMAIN, serial)},
|
||||
'manufacturer': self._sensor.manufacturer,
|
||||
'model': self._sensor.modelid,
|
||||
'name': self._sensor.name,
|
||||
'sw_version': self._sensor.swversion,
|
||||
"connections": {(CONNECTION_ZIGBEE, serial)},
|
||||
"identifiers": {(DECONZ_DOMAIN, serial)},
|
||||
"manufacturer": self._sensor.manufacturer,
|
||||
"model": self._sensor.modelid,
|
||||
"name": self._sensor.name,
|
||||
"sw_version": self._sensor.swversion,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue