Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log out of Sagemcom client after every query #30

Merged
merged 6 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
iMicknl marked this conversation as resolved.
Show resolved Hide resolved
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