- implemented us/eu authorization fixes

This commit is contained in:
Jack Simbach 2022-02-19 15:03:14 -05:00
parent 37cf69b99d
commit 9b901f82f7
3 changed files with 35 additions and 6 deletions

View File

@ -1,19 +1,38 @@
"""The ge_home integration."""
import logging
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_REGION
from .const import DOMAIN
from .update_coordinator import GeHomeUpdateCoordinator
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
async def async_setup(hass: HomeAssistant, config: dict):
return True
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Migrate old entry."""
_LOGGER.debug("Migrating from version %s", config_entry.version)
if config_entry.version == 1:
new = {**config_entry.data}
new[CONF_REGION] = "US"
config_entry.version = 2
hass.config_entries.async_update_entry(config_entry, data=new)
_LOGGER.info("Migration to version %s successful", config_entry.version)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up the ge_home component."""

View File

@ -7,11 +7,17 @@ import aiohttp
import asyncio
import async_timeout
from gehomesdk import GeAuthFailedError, GeNotAuthenticatedError, GeGeneralServerError, async_get_oauth2_token
from gehomesdk import (
GeAuthFailedError,
GeNotAuthenticatedError,
GeGeneralServerError,
async_get_oauth2_token,
LOGIN_REGIONS
)
import voluptuous as vol
from homeassistant import config_entries, core
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONF_REGION
from .const import DOMAIN # pylint:disable=unused-import
from .exceptions import HaAuthError, HaCannotConnect, HaAlreadyConfigured
@ -19,7 +25,11 @@ from .exceptions import HaAuthError, HaCannotConnect, HaAlreadyConfigured
_LOGGER = logging.getLogger(__name__)
GEHOME_SCHEMA = vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
{
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_REGION): vol.In(LOGIN_REGIONS.keys())
}
)
async def validate_input(hass: core.HomeAssistant, data):
@ -30,7 +40,7 @@ async def validate_input(hass: core.HomeAssistant, data):
# noinspection PyBroadException
try:
with async_timeout.timeout(10):
_ = await async_get_oauth2_token(session, data[CONF_USERNAME], data[CONF_PASSWORD])
_ = await async_get_oauth2_token(session, data[CONF_USERNAME], data[CONF_PASSWORD], data[CONF_REGION])
except (asyncio.TimeoutError, aiohttp.ClientError):
raise HaCannotConnect('Connection failure')
except (GeAuthFailedError, GeNotAuthenticatedError):
@ -47,7 +57,7 @@ async def validate_input(hass: core.HomeAssistant, data):
class GeHomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for GE Home."""
VERSION = 1
VERSION = 2
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_PUSH
async def _async_validate_input(self, user_input):

View File

@ -3,7 +3,7 @@
"name": "GE Home (SmartHQ)",
"config_flow": true,
"documentation": "https://github.com/simbaja/ha_gehome",
"requirements": ["gehomesdk==0.4.22","magicattr==0.1.5","slixmpp==1.7.1"],
"requirements": ["gehomesdk==0.4.24","magicattr==0.1.5","slixmpp==1.7.1"],
"codeowners": ["@simbaja"],
"version": "0.6.0"
}