Skip to content

Commit

Permalink
Aqara door/window sensor workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jul 15, 2018
1 parent efed851 commit 8916972
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
22 changes: 11 additions & 11 deletions homeassistant/components/binary_sensor/zha.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ async def async_setup_platform(hass, config, async_add_devices,

from zigpy.zcl.clusters.general import OnOff
from zigpy.zcl.clusters.security import IasZone
if IasZone.cluster_id in discovery_info['in_clusters']:
if IasZone.cluster_id in discovery_info['out_clusters']:
await _async_setup_iaszone(hass, config, async_add_devices,
discovery_info)
elif OnOff.cluster_id in discovery_info['out_clusters']:
elif OnOff.cluster_id in discovery_info['in_clusters']:
await _async_setup_remote(hass, config, async_add_devices,
discovery_info)

Expand All @@ -45,7 +45,7 @@ async def _async_setup_iaszone(hass, config, async_add_devices,
discovery_info):
device_class = None
from zigpy.zcl.clusters.security import IasZone
cluster = discovery_info['in_clusters'][IasZone.cluster_id]
cluster = discovery_info['out_clusters'][IasZone.cluster_id]
if discovery_info['new_join']:
await cluster.bind()
ieee = cluster.endpoint.device.application.ieee
Expand Down Expand Up @@ -74,13 +74,13 @@ async def safe(coro):

if discovery_info['new_join']:
from zigpy.zcl.clusters.general import OnOff, LevelControl
out_clusters = discovery_info['out_clusters']
if OnOff.cluster_id in out_clusters:
cluster = out_clusters[OnOff.cluster_id]
in_clusters = discovery_info['in_clusters']
if OnOff.cluster_id in in_clusters:
cluster = in_clusters[OnOff.cluster_id]
await safe(cluster.bind())
await safe(cluster.configure_reporting(0, 0, 600, 1))
if LevelControl.cluster_id in out_clusters:
cluster = out_clusters[LevelControl.cluster_id]
if LevelControl.cluster_id in in_clusters:
cluster = in_clusters[LevelControl.cluster_id]
await safe(cluster.bind())
await safe(cluster.configure_reporting(0, 1, 600, 1))

Expand All @@ -98,7 +98,7 @@ def __init__(self, device_class, **kwargs):
super().__init__(**kwargs)
self._device_class = device_class
from zigpy.zcl.clusters.security import IasZone
self._ias_zone_cluster = self._in_clusters[IasZone.cluster_id]
self._ias_zone_cluster = self._out_clusters[IasZone.cluster_id]

@property
def should_poll(self) -> bool:
Expand Down Expand Up @@ -206,7 +206,7 @@ def __init__(self, **kwargs):
self._state = False
self._level = 0
from zigpy.zcl.clusters import general
self._out_listeners = {
self._in_listeners = {
general.OnOff.cluster_id: self.OnOffListener(self),
general.LevelControl.cluster_id: self.LevelListener(self),
}
Expand Down Expand Up @@ -254,5 +254,5 @@ async def async_update(self):
"""Retrieve latest state."""
from zigpy.zcl.clusters.general import OnOff
result = await zha.safe_read(
self._endpoint.out_clusters[OnOff.cluster_id], ['on_off'])
self._endpoint.in_clusters[OnOff.cluster_id], ['on_off'])
self._state = result.get('on_off', self._state)
16 changes: 14 additions & 2 deletions homeassistant/components/switch/zha.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
at https://home-assistant.io/components/switch.zha/
"""
import logging
import asyncio

from homeassistant.components.switch import DOMAIN, SwitchDevice
from homeassistant.components import zha
Expand All @@ -17,15 +18,26 @@
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the Zigbee Home Automation switches."""
from zigpy.exceptions import DeliveryError
discovery_info = zha.get_discovery_info(hass, discovery_info)
if discovery_info is None:
return

from zigpy.zcl.clusters.general import OnOff
in_clusters = discovery_info['in_clusters']
cluster = in_clusters[OnOff.cluster_id]
await cluster.bind()
await cluster.configure_reporting(0, 0, 600, 1,)

tries = 3
while tries != 0:
tries-=1
try:
await cluster.bind()
await cluster.configure_reporting(0, 0, 600, 1,)
break

except DeliveryError as ex:
_LOGGER.error("cluster.bind() failed: %s", ex)
await asyncio.sleep(1.0)

async_add_devices([Switch(**discovery_info)], update_before_add=True)

Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/zha/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ async def async_device_initialized(self, device, join):
'new_join': join,
'unique_id': device_key,
}
_LOGGER.info("Permitting joins for %ss", discovery_info)
discovery_info.update(discovered_info)
self._hass.data[DISCOVERY_KEY][device_key] = discovery_info

Expand Down Expand Up @@ -285,6 +286,8 @@ async def _attempt_single_cluster_device(self, endpoint, cluster,
discovery_info.update(entity_info)
self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info

_LOGGER.info("Permitting joins for %ss", discovery_info)

await discovery.async_load_platform(
self._hass,
component,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zha/const.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def populate_data():
}

SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update({
zcl.clusters.general.OnOff: 'switch',
zcl.clusters.general.OnOff: 'binary_sensor',
zcl.clusters.measurement.RelativeHumidity: 'sensor',
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
zcl.clusters.measurement.PressureMeasurement: 'sensor',
Expand All @@ -55,7 +55,7 @@ def populate_data():
zcl.clusters.hvac.Fan: 'fan',
})
SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS.update({
zcl.clusters.general.OnOff: 'binary_sensor',
zcl.clusters.general.OnOff: 'switch',
})

# A map of hass components to all Zigbee clusters it could use
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .entity_registry import async_get_registry

SLOW_SETUP_WARNING = 10
SLOW_SETUP_MAX_WAIT = 60
SLOW_SETUP_MAX_WAIT = 240
PLATFORM_NOT_READY_RETRIES = 10


Expand Down

0 comments on commit 8916972

Please sign in to comment.