Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Feb 8, 2024
1 parent dcbc422 commit 7d3378c
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions custom_components/teslemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Final

from tesla_fleet_api import EnergySpecific, Teslemetry, VehicleSpecific
from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope
from tesla_fleet_api.exceptions import InvalidToken, PaymentRequired, TeslaFleetError

from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -63,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
vehicles: list[TeslemetryVehicleData] = []
energysites: list[TeslemetryEnergyData] = []
for product in products:
if "vin" in product and Scopes.VEHICLE_DEVICE_DATA in scopes:
if "vin" in product and Scope.VEHICLE_DEVICE_DATA in scopes:
# Remove the protobuff 'cached_data' that we do not use to save memory
product.pop("cached_data", None)
vin = product["vin"]
Expand All @@ -76,7 +76,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
vin=vin,
)
)
elif "energy_site_id" in product and Scopes.ENERGY_DEVICE_DATA in scopes:
elif "energy_site_id" in product and Scope.ENERGY_DEVICE_DATA in scopes:
site_id = product["energy_site_id"]
api = EnergySpecific(teslemetry.energy, site_id)
energysites.append(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Callable
from dataclasses import dataclass

from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -57,7 +57,7 @@ async def async_setup_entry(
TeslemetryButtonEntity(vehicle, description)
for vehicle in data.vehicles
for description in DESCRIPTIONS
if Scopes.VEHICLE_CMDS in data.scopes
if Scope.VEHICLE_CMDS in data.scopes
)


Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from typing import Any
from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
Expand All @@ -27,7 +27,7 @@ async def async_setup_entry(

async_add_entities(
TeslemetryClimateEntity(
vehicle, TeslemetryClimateSide.DRIVER, Scopes.VEHICLE_CMDS in data.scopes
vehicle, TeslemetryClimateSide.DRIVER, Scope.VEHICLE_CMDS in data.scopes
)
for vehicle in data.vehicles
)
Expand Down
18 changes: 9 additions & 9 deletions custom_components/teslemetry/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any

from tesla_fleet_api import EnergySpecific, VehicleSpecific
from tesla_fleet_api.const import VehicleDataEndpoints
from tesla_fleet_api.const import VehicleDataEndpoint
from tesla_fleet_api.exceptions import TeslaFleetError, VehicleOffline

from homeassistant.core import HomeAssistant
Expand All @@ -16,14 +16,14 @@
ENERGY_INFO_INTERVAL = timedelta(seconds=30)

ENDPOINTS = [
VehicleDataEndpoints.CHARGE_STATE,
VehicleDataEndpoints.CLIMATE_STATE,
# VehicleDataEndpoints.CLOSURES_STATE,
VehicleDataEndpoints.DRIVE_STATE,
# VehicleDataEndpoints.GUI_SETTINGS,
VehicleDataEndpoints.LOCATION_DATA,
# VehicleDataEndpoints.VEHICLE_CONFIG,
VehicleDataEndpoints.VEHICLE_STATE,
VehicleDataEndpoint.CHARGE_STATE,
VehicleDataEndpoint.CLIMATE_STATE,
# VehicleDataEndpoint.CLOSURES_STATE,
VehicleDataEndpoint.DRIVE_STATE,
# VehicleDataEndpoint.GUI_SETTINGS,
VehicleDataEndpoint.LOCATION_DATA,
# VehicleDataEndpoint.VEHICLE_CONFIG,
VehicleDataEndpoint.VEHICLE_STATE,
]


Expand Down
14 changes: 7 additions & 7 deletions custom_components/teslemetry/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any

from tesla_fleet_api.const import WindowCommands, Trunks, Scopes
from tesla_fleet_api.const import WindowCommand, Trunk, Scope

from homeassistant.components.cover import (
CoverDeviceClass,
Expand All @@ -29,13 +29,13 @@ async def async_setup_entry(
async_add_entities(
klass(vehicle, any(scope in data.scopes for scope in scopes))
for (klass, scopes) in (
(TeslemetryWindowEntity, [Scopes.VEHICLE_CMDS]),
(TeslemetryWindowEntity, [Scope.VEHICLE_CMDS]),
(
TeslemetryChargePortEntity,
[Scopes.VEHICLE_CMDS, Scopes.VEHICLE_CHARGING_CMDS],
[Scope.VEHICLE_CMDS, Scope.VEHICLE_CHARGING_CMDS],
),
(TeslemetryFrontTrunkEntity, [Scopes.VEHICLE_CMDS]),
(TeslemetryRearTrunkEntity, [Scopes.VEHICLE_CMDS]),
(TeslemetryFrontTrunkEntity, [Scope.VEHICLE_CMDS]),
(TeslemetryRearTrunkEntity, [Scope.VEHICLE_CMDS]),
)
for vehicle in data.vehicles
)
Expand Down Expand Up @@ -73,7 +73,7 @@ async def async_open_cover(self, **kwargs: Any) -> None:
self.raise_for_scope()
with handle_command():
await self.wake_up_if_asleep()
await self.api.window_control(command=WindowCommands.VENT)
await self.api.window_control(command=WindowCommand.VENT)
self.set(
("vehicle_state_fd_window", TeslemetryCoverStates.OPEN),
("vehicle_state_fp_window", TeslemetryCoverStates.OPEN),
Expand All @@ -86,7 +86,7 @@ async def async_close_cover(self, **kwargs: Any) -> None:
self.raise_for_scope()
with handle_command():
await self.wake_up_if_asleep()
await self.api.window_control(command=WindowCommands.CLOSE)
await self.api.window_control(command=WindowCommand.CLOSE)
self.set(
("vehicle_state_fd_window", TeslemetryCoverStates.CLOSED),
("vehicle_state_fp_window", TeslemetryCoverStates.CLOSED),
Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/lock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Lock platform for Teslemetry integration."""
from __future__ import annotations
from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope
from typing import Any

from homeassistant.components.lock import LockEntity
Expand All @@ -25,7 +25,7 @@ async def async_setup_entry(
data = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
klass(vehicle, Scopes.VEHICLE_CMDS in data.scopes)
klass(vehicle, Scope.VEHICLE_CMDS in data.scopes)
for klass in (
TeslemetryVehicleLockEntity,
TeslemetryCableLockEntity,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/media_player.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Media Player platform for Teslemetry integration."""
from __future__ import annotations
from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from homeassistant.components.media_player import (
MediaPlayerDeviceClass,
Expand Down Expand Up @@ -34,7 +34,7 @@ async def async_setup_entry(
data = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
TeslemetryMediaEntity(vehicle, Scopes.VEHICLE_CMDS in data.scopes)
TeslemetryMediaEntity(vehicle, Scope.VEHICLE_CMDS in data.scopes)
for vehicle in data.vehicles
)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass

from tesla_fleet_api import EnergySpecific, VehicleSpecific
from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from .coordinator import (
TeslemetryEnergySiteLiveCoordinator,
Expand All @@ -20,7 +20,7 @@ class TeslemetryData:

vehicles: list[TeslemetryVehicleData]
energysites: list[TeslemetryEnergyData]
scopes: list[Scopes]
scopes: list[Scope]


@dataclass
Expand Down
14 changes: 7 additions & 7 deletions custom_components/teslemetry/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Callable
from dataclasses import dataclass

from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from homeassistant.components.number import (
NumberDeviceClass,
Expand Down Expand Up @@ -42,7 +42,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
native_max_value: float
min_key: str | None = None
max_key: str | None = None
scopes: list[Scopes] | None = None
scopes: list[Scope] | None = None


VEHICLE_DESCRIPTIONS: tuple[TeslemetryNumberEntityDescription, ...] = (
Expand All @@ -55,7 +55,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
device_class=NumberDeviceClass.CURRENT,
max_key="charge_state_charge_current_request_max",
func=lambda api, value: api.set_charging_amps(int(value)),
scopes=[Scopes.VEHICLE_CHARGING_CMDS],
scopes=[Scope.VEHICLE_CHARGING_CMDS],
),
TeslemetryNumberEntityDescription(
key="charge_state_charge_limit_soc",
Expand All @@ -67,7 +67,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
min_key="charge_state_charge_limit_soc_min",
max_key="charge_state_charge_limit_soc_max",
func=lambda api, value: api.set_charge_limit(int(value)),
scopes=[Scopes.VEHICLE_CHARGING_CMDS, Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CHARGING_CMDS, Scope.VEHICLE_CMDS],
),
TeslemetryNumberEntityDescription(
key="vehicle_state_speed_limit_mode_current_limit_mph",
Expand All @@ -80,7 +80,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
min_key="vehicle_state_speed_limit_mode_min_limit_mph",
max_key="vehicle_state_speed_limit_mode_max_limit_mph",
func=lambda api, value: api.speed_limit_set_limit(value),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
)

Expand All @@ -92,7 +92,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
native_max_value=100,
device_class=NumberDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
scopes=[Scopes.ENERGY_CMDS],
scopes=[Scope.ENERGY_CMDS],
func=lambda api, value: api.backup(int(value)),
),
TeslemetryNumberEntityDescription(
Expand All @@ -103,7 +103,7 @@ class TeslemetryNumberEntityDescription(NumberEntityDescription):
native_max_value=100,
device_class=NumberDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
scopes=[Scopes.ENERGY_CMDS],
scopes=[Scope.ENERGY_CMDS],
func=lambda api, value: api.off_grid_vehicle_charging_reserve(int(value))
),
)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/teslemetry/select.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Select platform for Teslemetry integration."""
from __future__ import annotations

from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope
from dataclasses import dataclass
from collections.abc import Callable

Expand Down Expand Up @@ -61,7 +61,7 @@ async def async_setup_entry(

entities = []
for vehicle in data.vehicles:
scoped = Scopes.VEHICLE_CMDS in data.scopes
scoped = Scope.VEHICLE_CMDS in data.scopes
entities.append(
TeslemetrySeatHeaterSelectEntity(
vehicle, "climate_state_seat_heater_left", scoped
Expand Down Expand Up @@ -105,7 +105,7 @@ async def async_setup_entry(
if description.key in energysite.info_coordinator.data:
entities.append(
TeslemetryEnergySiteSelectEntity(
energysite, description, Scopes.ENERGY_CMDS in data.scopes
energysite, description, Scope.ENERGY_CMDS in data.scopes
)
)

Expand Down
20 changes: 10 additions & 10 deletions custom_components/teslemetry/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from typing import Any

from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from homeassistant.components.switch import (
SwitchDeviceClass,
Expand Down Expand Up @@ -35,39 +35,39 @@ class TeslemetrySwitchEntityDescription(SwitchEntityDescription):

on_func: Callable
off_func: Callable
scopes: list[Scopes] | None = None
scopes: list[Scope] | None = None


VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = (
TeslemetrySwitchEntityDescription(
key="charge_state_charge_enable_request",
on_func=lambda api: api.charge_start(),
off_func=lambda api: api.charge_stop(),
scopes=[Scopes.VEHICLE_CMDS, Scopes.VEHICLE_CHARGING_CMDS],
scopes=[Scope.VEHICLE_CMDS, Scope.VEHICLE_CHARGING_CMDS],
),
TeslemetrySwitchEntityDescription(
key="vehicle_state_sentry_mode",
on_func=lambda api: api.set_sentry_mode(on=True),
off_func=lambda api: api.set_sentry_mode(on=False),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
TeslemetrySwitchEntityDescription(
key="vehicle_state_valet_mode",
on_func=lambda api: api.set_valet_mode(on=True),
off_func=lambda api: api.set_valet_mode(on=False),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
TeslemetrySwitchEntityDescription(
key="climate_state_auto_seat_climate_left",
on_func=lambda api: api.remote_auto_seat_climate_request(0, True),
off_func=lambda api: api.remote_auto_seat_climate_request(0, False),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
TeslemetrySwitchEntityDescription(
key="climate_state_auto_seat_climate_right",
on_func=lambda api: api.remote_auto_seat_climate_request(1, True),
off_func=lambda api: api.remote_auto_seat_climate_request(1, False),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
TeslemetrySwitchEntityDescription(
key="climate_state_auto_steering_wheel_heat",
Expand All @@ -77,7 +77,7 @@ class TeslemetrySwitchEntityDescription(SwitchEntityDescription):
off_func=lambda api: api.remote_auto_steering_wheel_heat_climate_request(
on=False
),
scopes=[Scopes.VEHICLE_CMDS],
scopes=[Scope.VEHICLE_CMDS],
),
)

Expand All @@ -89,15 +89,15 @@ class TeslemetrySwitchEntityDescription(SwitchEntityDescription):
off_func=lambda api: api.grid_import_export(
disallow_charge_from_grid_with_solar_installed=True
),
scopes=[Scopes.ENERGY_CMDS],
scopes=[Scope.ENERGY_CMDS],
)


ENERGY_LIVE_DESCRIPTION = TeslemetrySwitchEntityDescription(
key="storm_mode_enabled",
on_func=lambda api: api.storm_mode(enabled=True),
off_func=lambda api: api.storm_mode(enabled=False),
scopes=[Scopes.ENERGY_CMDS],
scopes=[Scope.ENERGY_CMDS],
)


Expand Down
4 changes: 2 additions & 2 deletions custom_components/teslemetry/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any

from tesla_fleet_api.const import Scopes
from tesla_fleet_api.const import Scope

from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
from homeassistant.config_entries import ConfigEntry
Expand All @@ -23,7 +23,7 @@ async def async_setup_entry(
data = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
TeslemetryUpdateEntity(vehicle, Scopes.VEHICLE_CMDS in data.scopes)
TeslemetryUpdateEntity(vehicle, Scope.VEHICLE_CMDS in data.scopes)
for vehicle in data.vehicles
)

Expand Down

0 comments on commit 7d3378c

Please sign in to comment.