Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion homeassistant/components/teslemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -

async def async_unload_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -> bool:
"""Unload Teslemetry Config."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
# Remove stream listeners for each vehicle
for vehicle in entry.runtime_data.vehicles:
vehicle.remove_listener()

# Close the stream connection
if entry.runtime_data.stream:
entry.runtime_data.stream.close()

return unload_ok


async def async_migrate_entry(
Expand Down
8 changes: 1 addition & 7 deletions homeassistant/components/teslemetry/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ rules:
unique-config-entry: done
# Silver
action-exceptions: done
config-entry-unloading:
status: todo
comment: |
async_unload_entry must clean up: (1) close TeslemetryStream websocket via
stream.close(), (2) call remove_listener() for each vehicle to unsubscribe
from stream events, (3) consider using entry.async_on_unload() during setup
to register cleanup callbacks automatically.
config-entry-unloading: done
docs-configuration-parameters: done
docs-installation-parameters: done
entity-unavailable: done
Expand Down
Loading