Support new Xiaomi Aqara device model names and LAN protocol 2.0 (#13540)

This commit is contained in:
Kerwin Bryant 2018-04-25 13:05:00 +08:00 committed by Sebastian Muszynski
parent 75fffb6a86
commit 0a0d34d394
4 changed files with 28 additions and 15 deletions

View File

@ -25,30 +25,35 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items(): for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items():
for device in gateway.devices['binary_sensor']: for device in gateway.devices['binary_sensor']:
model = device['model'] model = device['model']
if model in ['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.aq2']: elif model in ['magnet', 'sensor_magnet', 'sensor_magnet.aq2']:
devices.append(XiaomiDoorSensor(device, gateway)) devices.append(XiaomiDoorSensor(device, gateway))
elif model == 'sensor_wleak.aq1': elif model == 'sensor_wleak.aq1':
devices.append(XiaomiWaterLeakSensor(device, gateway)) devices.append(XiaomiWaterLeakSensor(device, gateway))
elif model == 'smoke': elif model in ['smoke', 'sensor_smoke']:
devices.append(XiaomiSmokeSensor(device, gateway)) devices.append(XiaomiSmokeSensor(device, gateway))
elif model == 'natgas': elif model in ['natgas', 'sensor_natgas']:
devices.append(XiaomiNatgasSensor(device, gateway)) devices.append(XiaomiNatgasSensor(device, gateway))
elif model in ['switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: elif model in ['switch', 'sensor_switch',
devices.append(XiaomiButton(device, 'Switch', 'status', 'sensor_switch.aq2', 'sensor_switch.aq3']:
if 'proto' not in device or int(device['proto'][0:1]) == 1:
data_key = 'status'
else:
data_key = 'channel_0'
devices.append(XiaomiButton(device, 'Switch', data_key,
hass, gateway)) hass, gateway))
elif model == '86sw1': elif model in ['86sw1', 'sensor_86sw1.aq1']:
devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0',
hass, gateway)) hass, gateway))
elif model == '86sw2': elif model in ['86sw2', 'sensor_86sw2.aq1']:
devices.append(XiaomiButton(device, 'Wall Switch (Left)', devices.append(XiaomiButton(device, 'Wall Switch (Left)',
'channel_0', hass, gateway)) 'channel_0', hass, gateway))
devices.append(XiaomiButton(device, 'Wall Switch (Right)', devices.append(XiaomiButton(device, 'Wall Switch (Right)',
'channel_1', hass, gateway)) 'channel_1', 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 == 'cube': elif model in ['cube', 'sensor_cube']:
devices.append(XiaomiCube(device, hass, gateway)) devices.append(XiaomiCube(device, hass, gateway))
add_devices(devices) add_devices(devices)
@ -129,8 +134,12 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
"""Initialize the XiaomiMotionSensor.""" """Initialize the XiaomiMotionSensor."""
self._hass = hass self._hass = hass
self._no_motion_since = 0 self._no_motion_since = 0
if 'proto' not in device or int(device['proto'][0:1]) == 1:
data_key = 'status'
else:
data_key = 'motion_status'
XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub, XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub,
'status', 'motion') data_key, 'motion')
@property @property
def device_state_attributes(self): def device_state_attributes(self):

View File

@ -18,7 +18,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items(): for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items():
for device in gateway.devices['light']: for device in gateway.devices['light']:
model = device['model'] model = device['model']
if model == 'gateway': if model in ['gateway', 'gateway.v3']:
devices.append(XiaomiGatewayLight(device, 'Gateway Light', devices.append(XiaomiGatewayLight(device, 'Gateway Light',
gateway)) gateway))
add_devices(devices) add_devices(devices)

View File

@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
'temperature', gateway)) 'temperature', gateway))
devices.append(XiaomiSensor(device, 'Humidity', devices.append(XiaomiSensor(device, 'Humidity',
'humidity', gateway)) 'humidity', gateway))
elif device['model'] == 'weather.v1': elif device['model'] in ['weather', 'weather.v1']:
devices.append(XiaomiSensor(device, 'Temperature', devices.append(XiaomiSensor(device, 'Temperature',
'temperature', gateway)) 'temperature', gateway))
devices.append(XiaomiSensor(device, 'Humidity', devices.append(XiaomiSensor(device, 'Humidity',
@ -36,7 +36,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
elif device['model'] == 'sensor_motion.aq2': elif device['model'] == 'sensor_motion.aq2':
devices.append(XiaomiSensor(device, 'Illumination', devices.append(XiaomiSensor(device, 'Illumination',
'lux', gateway)) 'lux', gateway))
elif device['model'] == 'gateway': elif device['model'] in ['gateway', 'gateway.v3', 'acpartner.v3']:
devices.append(XiaomiSensor(device, 'Illumination', devices.append(XiaomiSensor(device, 'Illumination',
'illumination', gateway)) 'illumination', gateway))
add_devices(devices) add_devices(devices)

View File

@ -26,7 +26,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
for device in gateway.devices['switch']: for device in gateway.devices['switch']:
model = device['model'] model = device['model']
if model == 'plug': if model == 'plug':
devices.append(XiaomiGenericSwitch(device, "Plug", 'status', if 'proto' not in device or int(device['proto'][0:1]) == 1:
data_key = 'status'
else:
data_key = 'channel_0'
devices.append(XiaomiGenericSwitch(device, "Plug", data_key,
True, gateway)) True, gateway))
elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']:
devices.append(XiaomiGenericSwitch(device, 'Wall Switch', devices.append(XiaomiGenericSwitch(device, 'Wall Switch',
@ -52,7 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
'Wall Switch LN Right', 'Wall Switch LN Right',
'channel_1', 'channel_1',
False, gateway)) False, gateway))
elif model in ['86plug', 'ctrl_86plug.aq1']: elif model in ['86plug', 'ctrl_86plug', 'ctrl_86plug.aq1']:
devices.append(XiaomiGenericSwitch(device, 'Wall Plug', devices.append(XiaomiGenericSwitch(device, 'Wall Plug',
'status', True, gateway)) 'status', True, gateway))
add_devices(devices) add_devices(devices)