Fix ZHA bugs (#21246)

* fix bugs

* add comment

* allow entities to be marked unavailable
This commit is contained in:
David F. Mulcahey 2019-02-21 08:20:58 -05:00 committed by Pascal Vizeli
parent 2435456248
commit 0f8575f939
3 changed files with 19 additions and 8 deletions

View File

@ -126,9 +126,11 @@ class LevelControlChannel(ZigbeeChannel):
class BasicChannel(ZigbeeChannel): class BasicChannel(ZigbeeChannel):
"""Channel to interact with the basic cluster.""" """Channel to interact with the basic cluster."""
UNKNOWN = 0
BATTERY = 3 BATTERY = 3
POWER_SOURCES = { POWER_SOURCES = {
0: 'Unknown', UNKNOWN: 'Unknown',
1: 'Mains (single phase)', 1: 'Mains (single phase)',
2: 'Mains (3 phase)', 2: 'Mains (3 phase)',
BATTERY: 'Battery', BATTERY: 'Battery',

View File

@ -149,7 +149,7 @@ class ZHADevice:
async_dispatcher_send( async_dispatcher_send(
self.hass, self.hass,
"{}_{}".format(self._available_signal, 'entity'), "{}_{}".format(self._available_signal, 'entity'),
True available
) )
self._available = available self._available = available

View File

@ -36,6 +36,7 @@ _LOGGER = logging.getLogger(__name__)
SENSOR_TYPES = {} SENSOR_TYPES = {}
BINARY_SENSOR_TYPES = {} BINARY_SENSOR_TYPES = {}
SMARTTHINGS_HUMIDITY_CLUSTER = 64581
EntityReference = collections.namedtuple( EntityReference = collections.namedtuple(
'EntityReference', 'reference_id zha_device cluster_channels device_info') 'EntityReference', 'reference_id zha_device cluster_channels device_info')
@ -174,7 +175,8 @@ class ZHAGateway:
# available and we already loaded fresh state above # available and we already loaded fresh state above
zha_device.update_available(True) zha_device.update_available(True)
elif not zha_device.available and zha_device.power_source is not None\ elif not zha_device.available and zha_device.power_source is not None\
and zha_device.power_source != BasicChannel.BATTERY: and zha_device.power_source != BasicChannel.BATTERY\
and zha_device.power_source != BasicChannel.UNKNOWN:
# the device is currently marked unavailable and it isn't a battery # the device is currently marked unavailable and it isn't a battery
# powered device so we should be able to update it now # powered device so we should be able to update it now
_LOGGER.debug( _LOGGER.debug(
@ -380,7 +382,10 @@ async def _handle_single_cluster_match(hass, zha_device, cluster, device_key,
"""Dispatch a single cluster match to a HA component.""" """Dispatch a single cluster match to a HA component."""
component = None # sub_component = None component = None # sub_component = None
for cluster_type, candidate_component in device_classes.items(): for cluster_type, candidate_component in device_classes.items():
if isinstance(cluster, cluster_type): if isinstance(cluster_type, int):
if cluster.cluster_id == cluster_type:
component = candidate_component
elif isinstance(cluster, cluster_type):
component = candidate_component component = candidate_component
break break
@ -473,6 +478,9 @@ def establish_device_mappings():
SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update({ SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update({
zcl.clusters.general.OnOff: 'switch', zcl.clusters.general.OnOff: 'switch',
zcl.clusters.measurement.RelativeHumidity: 'sensor', zcl.clusters.measurement.RelativeHumidity: 'sensor',
# this works for now but if we hit conflicts we can break it out to
# a different dict that is keyed by manufacturer
SMARTTHINGS_HUMIDITY_CLUSTER: 'sensor',
zcl.clusters.measurement.TemperatureMeasurement: 'sensor', zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
zcl.clusters.measurement.PressureMeasurement: 'sensor', zcl.clusters.measurement.PressureMeasurement: 'sensor',
zcl.clusters.measurement.IlluminanceMeasurement: 'sensor', zcl.clusters.measurement.IlluminanceMeasurement: 'sensor',
@ -489,6 +497,7 @@ def establish_device_mappings():
SENSOR_TYPES.update({ SENSOR_TYPES.update({
zcl.clusters.measurement.RelativeHumidity.cluster_id: HUMIDITY, zcl.clusters.measurement.RelativeHumidity.cluster_id: HUMIDITY,
SMARTTHINGS_HUMIDITY_CLUSTER: HUMIDITY,
zcl.clusters.measurement.TemperatureMeasurement.cluster_id: zcl.clusters.measurement.TemperatureMeasurement.cluster_id:
TEMPERATURE, TEMPERATURE,
zcl.clusters.measurement.PressureMeasurement.cluster_id: PRESSURE, zcl.clusters.measurement.PressureMeasurement.cluster_id: PRESSURE,