mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Fix the protocol v2 data_key of several aqara devices (#16112)
* Fix the protocol v2 data_key of several aqara devices * Incorporate review
This commit is contained in:
parent
d8ae079757
commit
478eb48e93
@ -28,11 +28,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if model in ['motion', 'sensor_motion', 'sensor_motion.aq2']:
|
if model in ['motion', 'sensor_motion', 'sensor_motion.aq2']:
|
||||||
devices.append(XiaomiMotionSensor(device, hass, gateway))
|
devices.append(XiaomiMotionSensor(device, hass, gateway))
|
||||||
elif model in ['magnet', 'sensor_magnet', 'sensor_magnet.aq2']:
|
elif model in ['magnet', 'sensor_magnet', 'sensor_magnet.aq2']:
|
||||||
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
devices.append(XiaomiDoorSensor(device, gateway))
|
||||||
data_key = 'status'
|
|
||||||
else:
|
|
||||||
data_key = 'window_status'
|
|
||||||
devices.append(XiaomiDoorSensor(device, data_key, gateway))
|
|
||||||
elif model == 'sensor_wleak.aq1':
|
elif model == 'sensor_wleak.aq1':
|
||||||
devices.append(XiaomiWaterLeakSensor(device, gateway))
|
devices.append(XiaomiWaterLeakSensor(device, gateway))
|
||||||
elif model in ['smoke', 'sensor_smoke']:
|
elif model in ['smoke', 'sensor_smoke']:
|
||||||
@ -44,17 +40,27 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
data_key = 'status'
|
data_key = 'status'
|
||||||
else:
|
else:
|
||||||
data_key = 'channel_0'
|
data_key = 'button_0'
|
||||||
devices.append(XiaomiButton(device, 'Switch', data_key,
|
devices.append(XiaomiButton(device, 'Switch', data_key,
|
||||||
hass, gateway))
|
hass, gateway))
|
||||||
elif model in ['86sw1', 'sensor_86sw1', 'sensor_86sw1.aq1']:
|
elif model in ['86sw1', 'sensor_86sw1', 'sensor_86sw1.aq1']:
|
||||||
devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0',
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
|
data_key = 'channel_0'
|
||||||
|
else:
|
||||||
|
data_key = 'button_0'
|
||||||
|
devices.append(XiaomiButton(device, 'Wall Switch', data_key,
|
||||||
hass, gateway))
|
hass, gateway))
|
||||||
elif model in ['86sw2', 'sensor_86sw2', 'sensor_86sw2.aq1']:
|
elif model in ['86sw2', 'sensor_86sw2', 'sensor_86sw2.aq1']:
|
||||||
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
|
data_key_left = 'channel_0'
|
||||||
|
data_key_right = 'channel_1'
|
||||||
|
else:
|
||||||
|
data_key_left = 'button_0'
|
||||||
|
data_key_right = 'button_1'
|
||||||
devices.append(XiaomiButton(device, 'Wall Switch (Left)',
|
devices.append(XiaomiButton(device, 'Wall Switch (Left)',
|
||||||
'channel_0', hass, gateway))
|
data_key_left, hass, gateway))
|
||||||
devices.append(XiaomiButton(device, 'Wall Switch (Right)',
|
devices.append(XiaomiButton(device, 'Wall Switch (Right)',
|
||||||
'channel_1', hass, gateway))
|
data_key_right, hass, gateway))
|
||||||
devices.append(XiaomiButton(device, 'Wall Switch (Both)',
|
devices.append(XiaomiButton(device, 'Wall Switch (Both)',
|
||||||
'dual_channel', hass, gateway))
|
'dual_channel', hass, gateway))
|
||||||
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
|
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
|
||||||
@ -119,7 +125,7 @@ class XiaomiNatgasSensor(XiaomiBinarySensor):
|
|||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if value == '1':
|
if value in ('1', '2'):
|
||||||
if self._state:
|
if self._state:
|
||||||
return False
|
return False
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -194,9 +200,13 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
|
|||||||
class XiaomiDoorSensor(XiaomiBinarySensor):
|
class XiaomiDoorSensor(XiaomiBinarySensor):
|
||||||
"""Representation of a XiaomiDoorSensor."""
|
"""Representation of a XiaomiDoorSensor."""
|
||||||
|
|
||||||
def __init__(self, device, data_key, xiaomi_hub):
|
def __init__(self, device, xiaomi_hub):
|
||||||
"""Initialize the XiaomiDoorSensor."""
|
"""Initialize the XiaomiDoorSensor."""
|
||||||
self._open_since = 0
|
self._open_since = 0
|
||||||
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
|
data_key = 'status'
|
||||||
|
else:
|
||||||
|
data_key = 'window_status'
|
||||||
XiaomiBinarySensor.__init__(self, device, 'Door Window Sensor',
|
XiaomiBinarySensor.__init__(self, device, 'Door Window Sensor',
|
||||||
xiaomi_hub, data_key, 'opening')
|
xiaomi_hub, data_key, 'opening')
|
||||||
|
|
||||||
@ -237,8 +247,12 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor):
|
|||||||
|
|
||||||
def __init__(self, device, xiaomi_hub):
|
def __init__(self, device, xiaomi_hub):
|
||||||
"""Initialize the XiaomiWaterLeakSensor."""
|
"""Initialize the XiaomiWaterLeakSensor."""
|
||||||
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
|
data_key = 'status'
|
||||||
|
else:
|
||||||
|
data_key = 'wleak_status'
|
||||||
XiaomiBinarySensor.__init__(self, device, 'Water Leak Sensor',
|
XiaomiBinarySensor.__init__(self, device, 'Water Leak Sensor',
|
||||||
xiaomi_hub, 'status', 'moisture')
|
xiaomi_hub, data_key, 'moisture')
|
||||||
|
|
||||||
def parse_data(self, data, raw_data):
|
def parse_data(self, data, raw_data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
@ -285,7 +299,7 @@ class XiaomiSmokeSensor(XiaomiBinarySensor):
|
|||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if value == '1':
|
if value in ('1', '2'):
|
||||||
if self._state:
|
if self._state:
|
||||||
return False
|
return False
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -359,6 +373,10 @@ class XiaomiCube(XiaomiBinarySensor):
|
|||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._last_action = None
|
self._last_action = None
|
||||||
self._state = False
|
self._state = False
|
||||||
|
if 'proto' not in device or int(device['proto'][0:1]) == 1:
|
||||||
|
self._data_key = 'status'
|
||||||
|
else:
|
||||||
|
self._data_key = 'cube_status'
|
||||||
XiaomiBinarySensor.__init__(self, device, 'Cube', xiaomi_hub,
|
XiaomiBinarySensor.__init__(self, device, 'Cube', xiaomi_hub,
|
||||||
None, None)
|
None, None)
|
||||||
|
|
||||||
@ -371,19 +389,12 @@ class XiaomiCube(XiaomiBinarySensor):
|
|||||||
|
|
||||||
def parse_data(self, data, raw_data):
|
def parse_data(self, data, raw_data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
if 'status' in data:
|
if self._data_key in data:
|
||||||
self._hass.bus.fire('cube_action', {
|
self._hass.bus.fire('cube_action', {
|
||||||
'entity_id': self.entity_id,
|
'entity_id': self.entity_id,
|
||||||
'action_type': data['status']
|
'action_type': data[self._data_key]
|
||||||
})
|
})
|
||||||
self._last_action = data['status']
|
self._last_action = data[self._data_key]
|
||||||
|
|
||||||
if 'cube_status' in data:
|
|
||||||
self._hass.bus.fire('cube_action', {
|
|
||||||
'entity_id': self.entity_id,
|
|
||||||
'action_type': data['cube_status']
|
|
||||||
})
|
|
||||||
self._last_action = data['cube_status']
|
|
||||||
|
|
||||||
if 'rotate' in data:
|
if 'rotate' in data:
|
||||||
self._hass.bus.fire('cube_action', {
|
self._hass.bus.fire('cube_action', {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user