Skip to content

Commit

Permalink
Log out of Sagemcom client after every query (#30)
Browse files Browse the repository at this point in the history
* Log out of Sagemcom client after every query

* Fix black

* Update __init__.py

* Revert change

Co-authored-by: Mick Vleeshouwer <mick@imick.nl>
  • Loading branch information
rhpijnacker and iMicknl committed Feb 6, 2022
1 parent 296cdaf commit 716cc22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion custom_components/sagemcom_fast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
_LOGGER.exception(exception)
return False

try:
gateway = await client.get_device_info()
finally:
await client.logout()

update_interval = entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)

coordinator = SagemcomDataUpdateCoordinator(
Expand All @@ -119,7 +124,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
}

# Create gateway device in Home Assistant
gateway = await client.get_device_info()
device_registry = await hass.helpers.device_registry.async_get_registry()

device_registry.async_get_or_create(
Expand Down
1 change: 1 addition & 0 deletions custom_components/sagemcom_fast/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async def async_validate_input(self, user_input):
)

await client.login()
await client.logout()

return self.async_create_entry(
title=host,
Expand Down
6 changes: 5 additions & 1 deletion custom_components/sagemcom_fast/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ async def _async_update_data(self) -> Dict[str, Device]:
"""Update hosts data."""
try:
async with async_timeout.timeout(10):
hosts = await self._client.get_hosts(only_active=True)
try:
await self._client.login()
hosts = await self._client.get_hosts(only_active=True)
finally:
await self._client.logout()
"""Mark all device as non-active."""
for idx, host in self.hosts.items():
host.active = False
Expand Down

0 comments on commit 716cc22

Please sign in to comment.