mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Disable polling for modern vehicles in Teslemetry (#143495)
This commit is contained in:
parent
5cd4a0ced6
commit
7016c19b2f
@ -129,12 +129,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||||||
)
|
)
|
||||||
firmware = vehicle_metadata[vin].get("firmware", "Unknown")
|
firmware = vehicle_metadata[vin].get("firmware", "Unknown")
|
||||||
stream_vehicle = stream.get_vehicle(vin)
|
stream_vehicle = stream.get_vehicle(vin)
|
||||||
|
poll = product["command_signing"] == "off"
|
||||||
|
|
||||||
vehicles.append(
|
vehicles.append(
|
||||||
TeslemetryVehicleData(
|
TeslemetryVehicleData(
|
||||||
api=api,
|
api=api,
|
||||||
config_entry=entry,
|
config_entry=entry,
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
|
poll=poll,
|
||||||
stream=stream,
|
stream=stream,
|
||||||
stream_vehicle=stream_vehicle,
|
stream_vehicle=stream_vehicle,
|
||||||
vin=vin,
|
vin=vin,
|
||||||
@ -203,6 +205,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) -
|
|||||||
*(
|
*(
|
||||||
vehicle.coordinator.async_config_entry_first_refresh()
|
vehicle.coordinator.async_config_entry_first_refresh()
|
||||||
for vehicle in vehicles
|
for vehicle in vehicles
|
||||||
|
if vehicle.poll
|
||||||
),
|
),
|
||||||
*(
|
*(
|
||||||
energysite.info_coordinator.async_config_entry_first_refresh()
|
energysite.info_coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -58,8 +58,11 @@ class TeslemetryVehicleDataCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
LOGGER,
|
LOGGER,
|
||||||
config_entry=config_entry,
|
config_entry=config_entry,
|
||||||
name="Teslemetry Vehicle",
|
name="Teslemetry Vehicle",
|
||||||
update_interval=VEHICLE_INTERVAL,
|
|
||||||
)
|
)
|
||||||
|
if product["command_signing"] == "off":
|
||||||
|
# Only allow automatic polling if its included
|
||||||
|
self.update_interval = VEHICLE_INTERVAL
|
||||||
|
|
||||||
self.api = api
|
self.api = api
|
||||||
self.data = flatten(product)
|
self.data = flatten(product)
|
||||||
self.last_active = datetime.now()
|
self.last_active = datetime.now()
|
||||||
|
@ -116,6 +116,12 @@ class TeslemetryVehicleEntity(TeslemetryEntity):
|
|||||||
self.vehicle = data
|
self.vehicle = data
|
||||||
self._attr_unique_id = f"{data.vin}-{key}"
|
self._attr_unique_id = f"{data.vin}-{key}"
|
||||||
self._attr_device_info = data.device
|
self._attr_device_info = data.device
|
||||||
|
|
||||||
|
if not data.poll:
|
||||||
|
# This entities data is not available for free
|
||||||
|
# so disable it by default
|
||||||
|
self._attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
super().__init__(data.coordinator, key)
|
super().__init__(data.coordinator, key)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -37,6 +37,7 @@ class TeslemetryVehicleData:
|
|||||||
api: Vehicle
|
api: Vehicle
|
||||||
config_entry: ConfigEntry
|
config_entry: ConfigEntry
|
||||||
coordinator: TeslemetryVehicleDataCoordinator
|
coordinator: TeslemetryVehicleDataCoordinator
|
||||||
|
poll: bool
|
||||||
stream: TeslemetryStream
|
stream: TeslemetryStream
|
||||||
stream_vehicle: TeslemetryStreamVehicle
|
stream_vehicle: TeslemetryStreamVehicle
|
||||||
vin: str
|
vin: str
|
||||||
|
@ -11,6 +11,8 @@ WAKE_UP_ONLINE = {"response": {"state": TeslemetryState.ONLINE}, "error": None}
|
|||||||
WAKE_UP_ASLEEP = {"response": {"state": TeslemetryState.ASLEEP}, "error": None}
|
WAKE_UP_ASLEEP = {"response": {"state": TeslemetryState.ASLEEP}, "error": None}
|
||||||
|
|
||||||
PRODUCTS = load_json_object_fixture("products.json", DOMAIN)
|
PRODUCTS = load_json_object_fixture("products.json", DOMAIN)
|
||||||
|
PRODUCTS_MODERN = load_json_object_fixture("products.json", DOMAIN)
|
||||||
|
PRODUCTS_MODERN["response"][0]["command_signing"] = "required"
|
||||||
VEHICLE_DATA = load_json_object_fixture("vehicle_data.json", DOMAIN)
|
VEHICLE_DATA = load_json_object_fixture("vehicle_data.json", DOMAIN)
|
||||||
VEHICLE_DATA_ASLEEP = load_json_object_fixture("vehicle_data.json", DOMAIN)
|
VEHICLE_DATA_ASLEEP = load_json_object_fixture("vehicle_data.json", DOMAIN)
|
||||||
VEHICLE_DATA_ASLEEP["response"]["state"] = TeslemetryState.OFFLINE
|
VEHICLE_DATA_ASLEEP["response"]["state"] = TeslemetryState.OFFLINE
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
"webcam_supported": true,
|
"webcam_supported": true,
|
||||||
"wheel_type": "Pinwheel18CapKit"
|
"wheel_type": "Pinwheel18CapKit"
|
||||||
},
|
},
|
||||||
"command_signing": "allowed",
|
"command_signing": "off",
|
||||||
"release_notes_supported": true
|
"release_notes_supported": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
from tesla_fleet_api.exceptions import (
|
from tesla_fleet_api.exceptions import (
|
||||||
@ -10,6 +11,7 @@ from tesla_fleet_api.exceptions import (
|
|||||||
TeslaFleetError,
|
TeslaFleetError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.components.teslemetry.coordinator import VEHICLE_INTERVAL
|
||||||
from homeassistant.components.teslemetry.models import TeslemetryData
|
from homeassistant.components.teslemetry.models import TeslemetryData
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
||||||
@ -17,7 +19,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from . import setup_platform
|
from . import setup_platform
|
||||||
from .const import VEHICLE_DATA_ALT
|
from .const import PRODUCTS_MODERN, VEHICLE_DATA_ALT
|
||||||
|
|
||||||
ERRORS = [
|
ERRORS = [
|
||||||
(InvalidToken, ConfigEntryState.SETUP_ERROR),
|
(InvalidToken, ConfigEntryState.SETUP_ERROR),
|
||||||
@ -169,3 +171,21 @@ async def test_no_live_status(
|
|||||||
await setup_platform(hass)
|
await setup_platform(hass)
|
||||||
|
|
||||||
assert hass.states.get("sensor.energy_site_grid_power") is None
|
assert hass.states.get("sensor.energy_site_grid_power") is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_modern_no_poll(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_vehicle_data: AsyncMock,
|
||||||
|
mock_products: AsyncMock,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
) -> None:
|
||||||
|
"""Test that modern vehicles do not poll vehicle_data."""
|
||||||
|
|
||||||
|
mock_products.return_value = PRODUCTS_MODERN
|
||||||
|
entry = await setup_platform(hass)
|
||||||
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
assert mock_vehicle_data.called is False
|
||||||
|
freezer.tick(VEHICLE_INTERVAL)
|
||||||
|
assert mock_vehicle_data.called is False
|
||||||
|
freezer.tick(VEHICLE_INTERVAL)
|
||||||
|
assert mock_vehicle_data.called is False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user