Device support for different new sensors of the xiaomi aqara gateway (#8577)

* The gateway configuration accepts a MAC address or a SID value in uppercase already.
The ringtone services accepts the same values now. I hope it will avoid confusion.

* Device support for the new wall switches with neutral lead (ctrl_ln1, ctrl_ln2) added.

* Measurement unit from pressure of weather.v1 fixed.

* Device support for sensor_magnet.aq2 added.

* Device support for sensor_motion.aq2 (motion and lux) added.

* Code reformatted.

* The ringtone service (start/stop) uses the parameter gw_mac instead of gw_sid now.

* Version of the required library updated.
pull/8586/head
Sebastian Muszynski 2017-07-21 10:13:42 +02:00 committed by Daniel Høyer Iversen
parent f6a5e0887d
commit fada6d3f49
4 changed files with 33 additions and 9 deletions

View File

@ -25,8 +25,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
model = device['model']
if model == 'motion':
devices.append(XiaomiMotionSensor(device, hass, gateway))
elif model == 'sensor_motion.aq2':
devices.append(XiaomiMotionSensor(device, hass, gateway))
elif model == 'magnet':
devices.append(XiaomiDoorSensor(device, gateway))
elif model == 'sensor_magnet.aq2':
devices.append(XiaomiDoorSensor(device, gateway))
elif model == 'smoke':
devices.append(XiaomiSmokeSensor(device, gateway))
elif model == 'natgas':

View File

@ -17,13 +17,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
'temperature', gateway))
devices.append(XiaomiSensor(device, 'Humidity',
'humidity', gateway))
if device['model'] == 'weather.v1':
elif device['model'] == 'weather.v1':
devices.append(XiaomiSensor(device, 'Temperature',
'temperature', gateway))
devices.append(XiaomiSensor(device, 'Humidity',
'humidity', gateway))
devices.append(XiaomiSensor(device, 'Pressure',
'pressure', gateway))
elif device['model'] == 'sensor_motion.aq2':
devices.append(XiaomiSensor(device, 'Illumination',
'lux', gateway))
elif device['model'] == 'gateway':
devices.append(XiaomiSensor(device, 'Illumination',
'illumination', gateway))
@ -47,6 +50,8 @@ class XiaomiSensor(XiaomiDevice):
return '%'
elif self._data_key == 'illumination':
return 'lm'
elif self._data_key == 'lux':
return 'lx'
elif self._data_key == 'pressure':
return 'hPa'
@ -69,7 +74,7 @@ class XiaomiSensor(XiaomiDevice):
return False
elif self._data_key == 'pressure' and value == 0:
return False
if self._data_key in ['temperature', 'humidity']:
if self._data_key in ['temperature', 'humidity', 'pressure']:
value /= 100
elif self._data_key in ['illumination']:
value = max(value - 300, 0)

View File

@ -27,6 +27,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
devices.append(XiaomiGenericSwitch(device, 'Wall Switch',
'channel_0',
False, gateway))
elif model == 'ctrl_ln1':
devices.append(XiaomiGenericSwitch(device, 'Wall Switch LN',
'channel_0',
False, gateway))
elif model == 'ctrl_neutral2':
devices.append(XiaomiGenericSwitch(device, 'Wall Switch Left',
'channel_0',
@ -34,6 +38,15 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
devices.append(XiaomiGenericSwitch(device, 'Wall Switch Right',
'channel_1',
False, gateway))
elif model == 'ctrl_ln2':
devices.append(XiaomiGenericSwitch(device,
'Wall Switch LN Left',
'channel_0',
False, gateway))
devices.append(XiaomiGenericSwitch(device,
'Wall Switch LN Right',
'channel_1',
False, gateway))
elif model == '86plug':
devices.append(XiaomiGenericSwitch(device, 'Wall Plug',
'status', True, gateway))

View File

@ -12,7 +12,7 @@ REQUIREMENTS = ['https://github.com/Danielhiversen/PyXiaomiGateway/archive/'
'aa9325fe6fdd62a8ef8c9ca1dce31d3292f484bb.zip#'
'PyXiaomiGateway==0.2.0']
ATTR_GW_SID = 'gw_sid'
ATTR_GW_MAC = 'gw_mac'
ATTR_RINGTONE_ID = 'ringtone_id'
ATTR_RINGTONE_VOL = 'ringtone_vol'
CONF_DISCOVERY_RETRY = 'discovery_retry'
@ -90,12 +90,13 @@ def setup(hass, config):
def play_ringtone_service(call):
"""Service to play ringtone through Gateway."""
if call.data.get(ATTR_RINGTONE_ID) is None \
or call.data.get(ATTR_GW_SID) is None:
ring_id = call.data.get(ATTR_RINGTONE_ID)
gw_sid = call.data.get(ATTR_GW_MAC)
if ring_id is None or gw_sid is None:
_LOGGER.error("Mandatory parameters is not specified.")
return
ring_id = int(call.data.get(ATTR_RINGTONE_ID))
ring_id = int(ring_id)
if ring_id in [9, 14-19]:
_LOGGER.error('Specified mid: %s is not defined in gateway.',
ring_id)
@ -107,7 +108,7 @@ def setup(hass, config):
else:
ringtone = {'mid': ring_id, 'vol': int(ring_vol)}
gw_sid = call.data.get(ATTR_GW_SID)
gw_sid = gw_sid.replace(":", "").lower()
for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items():
if gateway.sid == gw_sid:
@ -118,12 +119,13 @@ def setup(hass, config):
def stop_ringtone_service(call):
"""Service to stop playing ringtone on Gateway."""
gw_sid = call.data.get(ATTR_GW_SID)
gw_sid = call.data.get(ATTR_GW_MAC)
if gw_sid is None:
_LOGGER.error("Mandatory parameter (%s) is not specified.",
ATTR_GW_SID)
ATTR_GW_MAC)
return
gw_sid = gw_sid.replace(":", "").lower()
for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items():
if gateway.sid == gw_sid:
ringtone = {'mid': 10000}