mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Dont add location entities without location scope in Teslemetry (#143497)
* Dont add location entities without location scope * Fix tests * simplify logic * Add test
This commit is contained in:
parent
2326c23133
commit
a1ca0a1cb2
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from tesla_fleet_api.const import Scope
|
||||||
from teslemetry_stream import TeslemetryStreamVehicle
|
from teslemetry_stream import TeslemetryStreamVehicle
|
||||||
from teslemetry_stream.const import TeslaLocation
|
from teslemetry_stream.const import TeslaLocation
|
||||||
|
|
||||||
@ -75,6 +76,10 @@ async def async_setup_entry(
|
|||||||
entities: list[
|
entities: list[
|
||||||
TeslemetryPollingDeviceTrackerEntity | TeslemetryStreamingDeviceTrackerEntity
|
TeslemetryPollingDeviceTrackerEntity | TeslemetryStreamingDeviceTrackerEntity
|
||||||
] = []
|
] = []
|
||||||
|
# Only add vehicle location entities if the user has granted vehicle location scope.
|
||||||
|
if Scope.VEHICLE_LOCATION not in entry.runtime_data.scopes:
|
||||||
|
return
|
||||||
|
|
||||||
for vehicle in entry.runtime_data.vehicles:
|
for vehicle in entry.runtime_data.vehicles:
|
||||||
for description in DESCRIPTIONS:
|
for description in DESCRIPTIONS:
|
||||||
if vehicle.api.pre2021 or vehicle.firmware < description.streaming_firmware:
|
if vehicle.api.pre2021 or vehicle.firmware < description.streaming_firmware:
|
||||||
|
@ -45,6 +45,7 @@ METADATA = {
|
|||||||
"vehicle_device_data",
|
"vehicle_device_data",
|
||||||
"vehicle_cmds",
|
"vehicle_cmds",
|
||||||
"vehicle_charging_cmds",
|
"vehicle_charging_cmds",
|
||||||
|
"vehicle_location",
|
||||||
"energy_device_data",
|
"energy_device_data",
|
||||||
"energy_cmds",
|
"energy_cmds",
|
||||||
],
|
],
|
||||||
|
@ -191,6 +191,7 @@
|
|||||||
'vehicle_device_data',
|
'vehicle_device_data',
|
||||||
'vehicle_cmds',
|
'vehicle_cmds',
|
||||||
'vehicle_charging_cmds',
|
'vehicle_charging_cmds',
|
||||||
|
'vehicle_location',
|
||||||
'energy_device_data',
|
'energy_device_data',
|
||||||
'energy_cmds',
|
'energy_cmds',
|
||||||
]),
|
]),
|
||||||
|
@ -11,7 +11,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import assert_entities, assert_entities_alt, setup_platform
|
from . import assert_entities, assert_entities_alt, setup_platform
|
||||||
from .const import VEHICLE_DATA_ALT
|
from .const import METADATA_NOSCOPE, VEHICLE_DATA_ALT
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
@ -42,6 +42,23 @@ async def test_device_tracker_alt(
|
|||||||
assert_entities_alt(hass, entry.entry_id, entity_registry, snapshot)
|
assert_entities_alt(hass, entry.entry_id, entity_registry, snapshot)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_device_tracker_noscope(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_metadata: AsyncMock,
|
||||||
|
mock_vehicle_data: AsyncMock,
|
||||||
|
mock_legacy: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Tests that the device tracker entities are correct."""
|
||||||
|
|
||||||
|
mock_metadata.return_value = METADATA_NOSCOPE
|
||||||
|
entry = await setup_platform(hass, [Platform.DEVICE_TRACKER])
|
||||||
|
entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
|
||||||
|
assert len(entity_entries) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
async def test_device_tracker_streaming(
|
async def test_device_tracker_streaming(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user