mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 13:45:55 -04:00
Use typed config entry in teslemetry (#190845)
Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MartinHjelmare <3181692+MartinHjelmare@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude
copilot-swe-agent[bot]
MartinHjelmare
parent
cb1bdfb4c8
commit
99cceda590
@@ -48,7 +48,7 @@ from homeassistant.components.labs import (
|
||||
async_is_preview_feature_enabled,
|
||||
async_subscribe_preview_feature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState, ConfigSubentry
|
||||
from homeassistant.config_entries import ConfigEntryState, ConfigSubentry
|
||||
from homeassistant.const import (
|
||||
CONF_ACCESS_TOKEN,
|
||||
CONF_ADDRESS,
|
||||
@@ -113,6 +113,7 @@ from .helpers import (
|
||||
)
|
||||
from .models import (
|
||||
TeslemetryChargeOnSolarStore,
|
||||
TeslemetryConfigEntry,
|
||||
TeslemetryData,
|
||||
TeslemetryEnergyData,
|
||||
TeslemetryVehicleData,
|
||||
@@ -138,8 +139,6 @@ _VEHICLE_ISSUE_ID_PATTERN = re.compile(
|
||||
f"({'|'.join(map(re.escape, VEHICLE_ISSUE_LEARN_MORE))})_"
|
||||
)
|
||||
|
||||
type TeslemetryConfigEntry = ConfigEntry[TeslemetryData]
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
# Exact SSE topics the integration consumes. An explicit allowlist keeps a
|
||||
|
||||
@@ -20,7 +20,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import TeslemetryState
|
||||
from .entity import (
|
||||
TeslemetryEnergyInfoEntity,
|
||||
@@ -31,7 +30,7 @@ from .entity import (
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import async_remove_stale_vehicle_entities
|
||||
from .models import TeslemetryEnergyData, TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ from homeassistant.components.button import ButtonEntity, ButtonEntityDescriptio
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import TeslemetryVehicleCommandEntity
|
||||
from .helpers import handle_command, handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import TeslemetryEnergyInfoEntity
|
||||
from .models import TeslemetryConfigEntry
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import TeslemetryClimateSide
|
||||
from .entity import (
|
||||
TeslemetryRootEntity,
|
||||
@@ -34,7 +33,7 @@ from .entity import (
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
DEFAULT_MIN_TEMP = 15
|
||||
DEFAULT_MAX_TEMP = 28
|
||||
|
||||
@@ -55,7 +55,6 @@ from homeassistant.components.bluetooth import (
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
SOURCE_RECONFIGURE,
|
||||
ConfigEntry,
|
||||
ConfigEntryState,
|
||||
ConfigFlowResult,
|
||||
ConfigSubentryFlow,
|
||||
@@ -66,7 +65,7 @@ from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from . import _BLE_KEY_ERRORS, TeslemetryConfigEntry
|
||||
from . import _BLE_KEY_ERRORS
|
||||
from .const import (
|
||||
BLE_ADVERTISEMENT_TIMEOUT,
|
||||
CLIENT_ID,
|
||||
@@ -85,7 +84,7 @@ from .helpers import (
|
||||
async_verify_local_gateway,
|
||||
cloud_energy_site,
|
||||
)
|
||||
from .models import TeslemetryEnergyData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData
|
||||
|
||||
|
||||
class PowerwallSetupError(Exception):
|
||||
@@ -120,7 +119,7 @@ class OAuth2FlowHandler(
|
||||
@callback
|
||||
@override
|
||||
def async_get_supported_subentry_types(
|
||||
cls, config_entry: ConfigEntry
|
||||
cls, config_entry: TeslemetryConfigEntry
|
||||
) -> dict[str, type[ConfigSubentryFlow]]:
|
||||
"""Return the subentry types supported by this integration."""
|
||||
return {
|
||||
@@ -168,7 +167,7 @@ class OAuth2FlowHandler(
|
||||
)
|
||||
|
||||
def _async_apply_token(
|
||||
self, entry: ConfigEntry, data: dict[str, Any]
|
||||
self, entry: TeslemetryConfigEntry, data: dict[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Store the refreshed token and reload the entry exactly once."""
|
||||
if entry.state is not ConfigEntryState.LOADED:
|
||||
|
||||
@@ -37,7 +37,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import TeslemetryConfigEntry
|
||||
from .models import TeslemetryConfigEntry
|
||||
|
||||
from .const import DOMAIN, LOGGER
|
||||
from .helpers import async_update_device_sw_version, flatten, gateway_issue_id
|
||||
|
||||
@@ -20,14 +20,13 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import (
|
||||
TeslemetryRootEntity,
|
||||
TeslemetryVehiclePollingEntity,
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
OPEN = 1
|
||||
CLOSED = 0
|
||||
|
||||
@@ -18,9 +18,8 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -10,10 +10,9 @@ from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .entity import TeslemetryVehicleCommandEntity, TeslemetryVehicleStreamEntity
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
VEHICLE_REDACT = [
|
||||
"id",
|
||||
|
||||
@@ -14,7 +14,6 @@ from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import DOMAIN
|
||||
from .entity import (
|
||||
TeslemetryRootEntity,
|
||||
@@ -22,7 +21,7 @@ from .entity import (
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
ENGAGED = "Engaged"
|
||||
|
||||
|
||||
@@ -18,14 +18,13 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import (
|
||||
TeslemetryRootEntity,
|
||||
TeslemetryVehiclePollingEntity,
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
STATES = {
|
||||
"Playing": MediaPlayerState.PLAYING,
|
||||
|
||||
@@ -29,6 +29,8 @@ from .coordinator import (
|
||||
TeslemetryWallConnectorTotalsCoordinator,
|
||||
)
|
||||
|
||||
type TeslemetryConfigEntry = ConfigEntry[TeslemetryData]
|
||||
|
||||
STORAGE_VERSION = 1
|
||||
|
||||
|
||||
@@ -49,7 +51,7 @@ class TeslemetryVehicleData:
|
||||
"""Data for a vehicle in the Teslemetry integration."""
|
||||
|
||||
api: Vehicle | VehicleRouter
|
||||
config_entry: ConfigEntry
|
||||
config_entry: TeslemetryConfigEntry
|
||||
coordinator: TeslemetryVehicleDataCoordinator
|
||||
poll: bool
|
||||
stream: TeslemetryStream
|
||||
|
||||
@@ -29,7 +29,6 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import CHARGE_LIMIT_SOC_KEY, CHARGE_ON_SOLAR_LOWER_LIMIT_KEY
|
||||
from .entity import (
|
||||
TeslemetryChargeOnSolarEntity,
|
||||
@@ -41,6 +40,7 @@ from .entity import (
|
||||
from .helpers import async_set_charge_on_solar, handle_command, handle_vehicle_command
|
||||
from .models import (
|
||||
TeslemetryChargeOnSolarStore,
|
||||
TeslemetryConfigEntry,
|
||||
TeslemetryEnergyData,
|
||||
TeslemetryVehicleData,
|
||||
)
|
||||
|
||||
@@ -16,13 +16,14 @@ from homeassistant.config_entries import ConfigEntryState, ConfigSubentry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from . import TeslemetryConfigEntry, _async_get_rsa_key_pem
|
||||
from . import _async_get_rsa_key_pem
|
||||
from .const import ISSUE_GATEWAY_NOT_FOUND, LOGGER, VEHICLE_ISSUE_LEARN_MORE
|
||||
from .helpers import (
|
||||
PowerwallKeyRejectedError,
|
||||
async_verify_local_gateway,
|
||||
cloud_energy_site,
|
||||
)
|
||||
from .models import TeslemetryConfigEntry
|
||||
|
||||
|
||||
class VehicleMetadataRepairFlow(RepairsFlow):
|
||||
|
||||
@@ -16,7 +16,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import (
|
||||
TeslemetryEnergyInfoEntity,
|
||||
TeslemetryRootEntity,
|
||||
@@ -28,7 +27,7 @@ from .helpers import (
|
||||
handle_command,
|
||||
handle_vehicle_command,
|
||||
)
|
||||
from .models import TeslemetryEnergyData, TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
OFF = "off"
|
||||
LOW = "low"
|
||||
|
||||
@@ -41,7 +41,6 @@ from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import PressureConverter
|
||||
from homeassistant.util.variance import ignore_variance
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import ENERGY_HISTORY_FIELDS
|
||||
from .coordinator import PERIOD_START, WALL_CONNECTOR_TOTALS
|
||||
from .entity import (
|
||||
@@ -56,7 +55,7 @@ from .entity import (
|
||||
TeslemetryWallConnectorTotalsEntity,
|
||||
)
|
||||
from .helpers import async_remove_stale_vehicle_entities
|
||||
from .models import TeslemetryEnergyData, TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Service calls for the Teslemetry integration."""
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import probatio
|
||||
|
||||
@@ -24,10 +23,7 @@ from homeassistant.helpers import (
|
||||
|
||||
from .const import DOMAIN
|
||||
from .helpers import handle_command, handle_energy_site_command, handle_vehicle_command
|
||||
from .models import TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import TeslemetryConfigEntry
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .const import CHARGE_ON_SOLAR_SWITCH_KEY
|
||||
from .entity import (
|
||||
TeslemetryChargeOnSolarEntity,
|
||||
@@ -30,7 +29,7 @@ from .entity import (
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import async_set_charge_on_solar, handle_command, handle_vehicle_command
|
||||
from .models import TeslemetryEnergyData, TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryEnergyData, TeslemetryVehicleData
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
|
||||
@@ -16,14 +16,13 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import TeslemetryConfigEntry
|
||||
from .entity import (
|
||||
TeslemetryRootEntity,
|
||||
TeslemetryVehiclePollingEntity,
|
||||
TeslemetryVehicleStreamEntity,
|
||||
)
|
||||
from .helpers import handle_vehicle_command
|
||||
from .models import TeslemetryVehicleData
|
||||
from .models import TeslemetryConfigEntry, TeslemetryVehicleData
|
||||
|
||||
AVAILABLE = "available"
|
||||
DOWNLOADING = "downloading"
|
||||
|
||||
Reference in New Issue
Block a user