-
Notifications
You must be signed in to change notification settings - Fork 5
Schema for configuration.yaml
David Bonnes edited this page Apr 18, 2019
·
1 revision
For the corresponding configuration.yaml
:
geniushub:
host: 192.168.0.1
username: username
password: password
... use the voluptuous schema:
DOMAIN = 'geniushub'
CONF_TOKEN = 'hub_token'
CONF_HOST = 'host'
CONF_USERNAME = 'username'
CONF_PASSWORD = 'password'
_V1_API_SCHEMA = vol.Schema({
vol.Required(CONF_TOKEN): str,
})
_V3_API_SCHEMA = vol.Schema({
vol.Required(CONF_HOST): str,
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
})
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Any(
_V3_API_SCHEMA,
_V1_API_SCHEMA,
)
}, extra=vol.ALLOW_EXTRA)
... and the following code:
kwargs = dict(hass_config[DOMAIN])
if CONF_HOST in kwargs:
args = (kwargs.pop(CONF_HOST), )
else:
args = (kwargs.pop(CONF_TOKEN), )
try:
client = GeniusHubClient(
*args, **kwargs, session=async_get_clientsession(hass)
)