Improve configuration schema for Geniushub integration (#23155)
* configuration for hub tokens are now separate from host addresses/credentials * small change to docstring * use *args **kwargspull/23297/head
parent
dbb49afb3e
commit
df02879c51
|
@ -1,10 +1,10 @@
|
||||||
"""This module connects to the Genius hub and shares the data."""
|
"""This module connects to a Genius hub and shares the data."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME)
|
CONF_HOST, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME)
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.discovery import async_load_platform
|
from homeassistant.helpers.discovery import async_load_platform
|
||||||
|
@ -13,12 +13,19 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DOMAIN = 'geniushub'
|
DOMAIN = 'geniushub'
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
_V1_API_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
vol.Required(CONF_TOKEN): cv.string,
|
||||||
vol.Optional(CONF_USERNAME): cv.string,
|
})
|
||||||
vol.Optional(CONF_PASSWORD): cv.string,
|
_V3_API_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
}),
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
})
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
|
DOMAIN: vol.Any(
|
||||||
|
_V3_API_SCHEMA,
|
||||||
|
_V1_API_SCHEMA,
|
||||||
|
)
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,16 +33,17 @@ async def async_setup(hass, hass_config):
|
||||||
"""Create a Genius Hub system."""
|
"""Create a Genius Hub system."""
|
||||||
from geniushubclient import GeniusHubClient # noqa; pylint: disable=no-name-in-module
|
from geniushubclient import GeniusHubClient # noqa; pylint: disable=no-name-in-module
|
||||||
|
|
||||||
host = hass_config[DOMAIN].get(CONF_HOST)
|
|
||||||
username = hass_config[DOMAIN].get(CONF_USERNAME)
|
|
||||||
password = hass_config[DOMAIN].get(CONF_PASSWORD)
|
|
||||||
|
|
||||||
geniushub_data = hass.data[DOMAIN] = {}
|
geniushub_data = hass.data[DOMAIN] = {}
|
||||||
|
|
||||||
|
kwargs = dict(hass_config[DOMAIN])
|
||||||
|
if CONF_HOST in kwargs:
|
||||||
|
args = (kwargs.pop(CONF_HOST), )
|
||||||
|
else:
|
||||||
|
args = (kwargs.pop(CONF_TOKEN), )
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client = geniushub_data['client'] = GeniusHubClient(
|
client = geniushub_data['client'] = GeniusHubClient(
|
||||||
host, username, password,
|
*args, **kwargs, session=async_get_clientsession(hass)
|
||||||
session=async_get_clientsession(hass)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await client.hub.update()
|
await client.hub.update()
|
||||||
|
|
Loading…
Reference in New Issue