Support setup exception
This commit is contained in:
@@ -47,13 +47,11 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Setup Georide component."""
|
"""Setup Georide component."""
|
||||||
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
||||||
hass.async_create_task(
|
result = await hass.config_entries.flow.async_init(
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER.info("Georide-setup ")
|
_LOGGER.info("Georide-setup success: %s", result)
|
||||||
|
|
||||||
# Return boolean to indicate that initialization was successful.
|
# Return boolean to indicate that initialization was successful.
|
||||||
return True
|
return True
|
||||||
@@ -74,15 +72,13 @@ def connect_socket(hass, component):
|
|||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up Georide entry."""
|
"""Set up Georide entry."""
|
||||||
|
|
||||||
|
|
||||||
config = hass.data[DOMAIN]["config"]
|
config = hass.data[DOMAIN]["config"]
|
||||||
email = config.get(CONF_EMAIL) or entry.data[CONF_EMAIL]
|
email = config.get(CONF_EMAIL) or entry.data[CONF_EMAIL]
|
||||||
password = config.get(CONF_PASSWORD) or entry.data[CONF_PASSWORD]
|
password = config.get(CONF_PASSWORD) or entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
if email is None or password is None:
|
if email is None or password is None:
|
||||||
return False
|
return False
|
||||||
|
try:
|
||||||
account = GeorideApi.get_authorisation_token(email, password)
|
account = GeorideApi.get_authorisation_token(email, password)
|
||||||
context = GeorideContext(
|
context = GeorideContext(
|
||||||
hass,
|
hass,
|
||||||
@@ -98,13 +94,15 @@ async def async_setup_entry(hass, entry):
|
|||||||
trackers = GeorideApi.get_trackers(account.auth_token)
|
trackers = GeorideApi.get_trackers(account.auth_token)
|
||||||
context.georide_trackers = trackers
|
context.georide_trackers = trackers
|
||||||
|
|
||||||
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
|
hass.async_create_task(
|
||||||
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "switch"))
|
hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
|
||||||
|
hass.async_create_task(
|
||||||
|
hass.config_entries.async_forward_entry_setup(entry, "switch"))
|
||||||
|
|
||||||
thread = Thread(target=connect_socket, args=(hass, entry))
|
thread = Thread(target=connect_socket, args=(hass, entry))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_unload_entry(hass, entry):
|
async def async_unload_entry(hass, entry):
|
||||||
|
|||||||
Reference in New Issue
Block a user