parent
a2a9150a9b
commit
6e4285f824
6 changed files with 24 additions and 21 deletions
|
@ -23,6 +23,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up SmartThings Find from a config entry."""
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = {}
|
||||
|
||||
# Load the jsessionid from the config and create a session from it
|
||||
jsessionid = entry.data[CONF_JSESSIONID]
|
||||
session = async_get_clientsession(hass)
|
||||
|
@ -30,10 +33,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
# This raises ConfigEntryAuthFailed-exception if failed. So if we
|
||||
# can continue after fetch_csrf, we know that authentication was ok
|
||||
await fetch_csrf(hass, session)
|
||||
await fetch_csrf(hass, session, entry.entry_id)
|
||||
|
||||
# Load all SmartThings-Find devices from the users account
|
||||
devices = await get_devices(hass, session)
|
||||
devices = await get_devices(hass, session, entry.entry_id)
|
||||
|
||||
# Create an update coordinator. This is responsible to regularly
|
||||
# fetch data from STF and update the device_tracker and sensor
|
||||
|
@ -44,9 +47,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
# seconds for my 15 devices) but it is the right way to do it. Only if
|
||||
# it succeeds, the integration will be marked as successfully loaded.
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
||||
hass.data[DOMAIN].update({
|
||||
hass.data[DOMAIN][entry.entry_id].update({
|
||||
CONF_JSESSIONID: jsessionid,
|
||||
"session": session,
|
||||
"coordinator": coordinator,
|
||||
|
@ -62,7 +64,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
"""Unload a config entry."""
|
||||
unload_success = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_success:
|
||||
del hass.data[DOMAIN]
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
else:
|
||||
_LOGGER.error(f"Unload failed: {unload_success}")
|
||||
return unload_success
|
||||
|
@ -90,7 +92,7 @@ class SmartThingsFindCoordinator(DataUpdateCoordinator):
|
|||
_LOGGER.debug(f"Updating locations...")
|
||||
for device in self.devices:
|
||||
dev_data = device['data']
|
||||
tag_data = await get_device_location(self.hass, self.session, dev_data)
|
||||
tag_data = await get_device_location(self.hass, self.session, dev_data, self.config_entry.entry_id)
|
||||
tags[dev_data['dvceID']] = tag_data
|
||||
_LOGGER.debug(f"Fetched {len(tags)} locations")
|
||||
return tags
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue