mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Xiaomi config validation (#9941)
* validate xiaomi config * Update xiaomi_aqara.py * check for valid config * use consts
This commit is contained in:
parent
f641a6aad3
commit
587948ec06
@ -6,9 +6,9 @@ from homeassistant.helpers import discovery
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.discovery import SERVICE_XIAOMI_GW
|
||||
from homeassistant.const import (ATTR_BATTERY_LEVEL, EVENT_HOMEASSISTANT_STOP,
|
||||
CONF_MAC)
|
||||
CONF_MAC, CONF_HOST, CONF_PORT)
|
||||
|
||||
REQUIREMENTS = ['PyXiaomiGateway==0.5.1']
|
||||
REQUIREMENTS = ['PyXiaomiGateway==0.5.2']
|
||||
|
||||
ATTR_GW_MAC = 'gw_mac'
|
||||
ATTR_RINGTONE_ID = 'ringtone_id'
|
||||
@ -24,30 +24,36 @@ def _validate_conf(config):
|
||||
"""Validate a list of devices definitions."""
|
||||
res_config = []
|
||||
for gw_conf in config:
|
||||
for _conf in gw_conf.keys():
|
||||
if _conf not in [CONF_MAC, CONF_HOST, CONF_PORT, 'key']:
|
||||
raise vol.Invalid('{} is not a valid config parameter'.
|
||||
format(_conf))
|
||||
|
||||
res_gw_conf = {'sid': gw_conf.get(CONF_MAC)}
|
||||
if res_gw_conf['sid'] is not None:
|
||||
res_gw_conf['sid'] = res_gw_conf['sid'].replace(":", "").lower()
|
||||
if len(res_gw_conf['sid']) != 12:
|
||||
raise vol.Invalid('Invalid mac address', gw_conf.get(CONF_MAC))
|
||||
key = gw_conf.get('key')
|
||||
|
||||
if key is None:
|
||||
_LOGGER.warning(
|
||||
'Gateway Key is not provided.'
|
||||
' Controlling gateway device will not be possible.')
|
||||
elif len(key) != 16:
|
||||
raise vol.Invalid('Invalid key %s.'
|
||||
' Key must be 16 characters', key)
|
||||
raise vol.Invalid('Invalid key {}.'
|
||||
' Key must be 16 characters'.format(key))
|
||||
res_gw_conf['key'] = key
|
||||
|
||||
host = gw_conf.get('host')
|
||||
host = gw_conf.get(CONF_HOST)
|
||||
if host is not None:
|
||||
res_gw_conf['host'] = host
|
||||
res_gw_conf['port'] = gw_conf.get('port', 9898)
|
||||
res_gw_conf[CONF_HOST] = host
|
||||
res_gw_conf['port'] = gw_conf.get(CONF_PORT, 9898)
|
||||
|
||||
_LOGGER.warning(
|
||||
'Static address (%s:%s) of the gateway provided. '
|
||||
'Discovery of this host will be skipped.',
|
||||
res_gw_conf['host'], res_gw_conf['port'])
|
||||
res_gw_conf[CONF_HOST], res_gw_conf[CONF_PORT])
|
||||
|
||||
res_config.append(res_gw_conf)
|
||||
return res_config
|
||||
|
@ -33,7 +33,7 @@ PyMVGLive==1.1.4
|
||||
PyMata==2.14
|
||||
|
||||
# homeassistant.components.xiaomi_aqara
|
||||
PyXiaomiGateway==0.5.1
|
||||
PyXiaomiGateway==0.5.2
|
||||
|
||||
# homeassistant.components.rpi_gpio
|
||||
# RPi.GPIO==0.6.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user