1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Complete config-entry-unloading quality check in Teslemetry (#161956)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Brett Adams
2026-02-12 05:31:30 +10:00
committed by GitHub
parent 6379014f13
commit 4b5368be8e
3 changed files with 7 additions and 13 deletions

View File

@@ -208,9 +208,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
manual=True,
)
remove_listener = stream.async_add_listener(
create_handle_vehicle_stream(vin, coordinator),
{"vin": vin},
entry.async_on_unload(
stream.async_add_listener(
create_handle_vehicle_stream(vin, coordinator),
{"vin": vin},
)
)
stream_vehicle = stream.get_vehicle(vin)
poll = vehicle_metadata[vin].get("polling", False)
@@ -226,7 +228,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
vin=vin,
firmware=firmware,
device=device,
remove_listener=remove_listener,
)
)
@@ -351,6 +352,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
if stream:
entry.async_on_unload(stream.close)
entry.async_create_background_task(hass, stream.listen(), "Teslemetry Stream")
return True

View File

@@ -3,7 +3,6 @@
from __future__ import annotations
import asyncio
from collections.abc import Callable
from dataclasses import dataclass
from tesla_fleet_api.const import Scope
@@ -44,7 +43,6 @@ class TeslemetryVehicleData:
vin: str
firmware: str
device: DeviceInfo
remove_listener: Callable
wakelock = asyncio.Lock()

View File

@@ -20,13 +20,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