Configure ZHA entity on new ZHA device join (#19470)

* Address PR#19177 comments.

* Make 'new_join' part of ZhaEntity.

Call async_configure() automatically when new device ZHA device joins.
This commit is contained in:
Alexei Chetroi authored and Martin Hjelmare committed 2018-12-23 20:47:06 +01:00
1 parent 0b84eefa2e
commit 4a1da0b041
6 files changed
+19 -40

No files matched your search

+7 -23
View File
@@ -60,20 +60,19 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async def _async_setup_entities(hass, config_entry, async_add_entities,
discovery_infos):
"""Set up the ZHA binary sensors."""
from zigpy.zcl.clusters.general import OnOff
from zigpy.zcl.clusters.measurement import OccupancySensing
from zigpy.zcl.clusters.security import IasZone
entities = []
for discovery_info in discovery_infos:
from zigpy.zcl.clusters.general import OnOff
from zigpy.zcl.clusters.measurement import OccupancySensing
from zigpy.zcl.clusters.security import IasZone
if IasZone.cluster_id in discovery_info['in_clusters']:
entities.append(await _async_setup_iaszone(discovery_info))
elif OccupancySensing.cluster_id in discovery_info['in_clusters']:
entities.append(await _async_setup_occupancy(
DEVICE_CLASS_OCCUPANCY,
discovery_info
))
entities.append(
BinarySensor(DEVICE_CLASS_OCCUPANCY, **discovery_info))
elif OnOff.cluster_id in discovery_info['out_clusters']:
entities.append(await _async_setup_remote(discovery_info))
entities.append(Remote(**discovery_info))
async_add_entities(entities, update_before_add=True)
@@ -97,21 +96,6 @@ async def _async_setup_iaszone(discovery_info):
return IasZoneSensor(device_class, **discovery_info)
async def _async_setup_remote(discovery_info):
remote = Remote(**discovery_info)
if discovery_info['new_join']:
await remote.async_configure()
return remote
async def _async_setup_occupancy(device_class, discovery_info):
sensor = BinarySensor(device_class, **discovery_info)
if discovery_info['new_join']:
await sensor.async_configure()
return sensor
class IasZoneSensor(RestoreEntity, ZhaEntity, BinarySensorDevice):
"""The IasZoneSensor Binary Sensor."""