Skip to content

Commit

Permalink
Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 16, 2024
1 parent 584c2b8 commit cd979de
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 964 deletions.
23 changes: 0 additions & 23 deletions custom_components/teslemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,6 @@
Platform.UPDATE,
]

class HandleVehicleData:
"""Handle streaming vehicle data."""

def __init__(self, coordinator: TeslemetryVehicleDataCoordinator):
self.coordinator = coordinator

def receive(self, data: dict) -> None:
"""Handle vehicle data from the stream."""
self.coordinator.async_set_updated_data(flatten(data["vehicle_data"]))

class HandleVehicleState:
""" Handle streaming vehicle state"""

def __init__(self, coordinator: TeslemetryVehicleDataCoordinator):
self.coordinator = coordinator

def receive(self, data: dict) -> None:
"""Handle state from the stream."""
self.coordinator.data["state"] = data["state"]
self.coordinator.async_set_updated_data(self.coordinator.data)



async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Telemetry integration."""
async_register_services(hass)
Expand Down
7 changes: 5 additions & 2 deletions custom_components/teslemetry/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers.restore_state import RestoreEntity

from .const import TeslemetryClimateSide
from .const import TeslemetryClimateSide, DOMAIN
from .entity import TeslemetryVehicleComplexStreamEntity, TeslemetryVehicleEntity
from .models import TeslemetryVehicleData

Expand Down Expand Up @@ -162,6 +161,8 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
self.async_write_ha_state()

class TeslemetryPollingClimateEntity(TeslemetryClimateEntity, TeslemetryVehicleEntity):
"""Polling vehicle climate entity."""

def __init__(
self,
data: TeslemetryVehicleData,
Expand Down Expand Up @@ -204,6 +205,8 @@ def _async_update_attrs(self) -> None:


class TeslemetryStreamingClimateEntity(TeslemetryClimateEntity, TeslemetryVehicleComplexStreamEntity):
"""Teslemetry steering wheel climate control."""

def __init__(
self,
data: TeslemetryVehicleData,
Expand Down
3 changes: 1 addition & 2 deletions custom_components/teslemetry/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from tesla_fleet_api.const import VehicleDataEndpoint
from tesla_fleet_api.exceptions import (
TeslaFleetError,
VehicleOffline,
InvalidToken,
SubscriptionRequired,
Forbidden,
Expand All @@ -24,7 +23,7 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from .const import LOGGER, TeslemetryState, DOMAIN, ENERGY_HISTORY_FIELDS
from .const import LOGGER, DOMAIN, ENERGY_HISTORY_FIELDS
from .helpers import flatten

VEHICLE_INTERVAL = timedelta(minutes=15)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/teslemetry/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
TeslemetryVehicleEntity,
TeslemetryVehicleStreamEntity,
)
from .helpers import auto_type
from .models import TeslemetryVehicleData

CLOSED = 0
Expand Down Expand Up @@ -359,7 +358,7 @@ def __init__(self, vehicle: TeslemetryVehicleData, scopes: list[Scope]) -> None:
def _async_update_attrs(self) -> None:
"""Update the entity attributes."""
value = self._value
if value == None or value == "unknown":
if value is None or value == "unknown":
self._attr_is_closed = None
else:
self._attr_is_closed = value == "closed"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def get(self, key: str, default: Any | None = None) -> Any | None:

def get_number(self, key: str, default: float) -> float:
"""Return a specific number from coordinator data."""
if isinstance(value := self.coordinator.data.get(key), (int, float)):
if isinstance(value := self.coordinator.data.get(key), (int | float)):
return value
return default

Expand Down
2 changes: 0 additions & 2 deletions custom_components/teslemetry/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import asyncio
from typing import Any
from teslemetry_stream import TeslemetryStream
from teslemetry_stream import Signal
from tesla_fleet_api.exceptions import TeslaFleetError

from homeassistant.exceptions import HomeAssistantError
Expand Down
3 changes: 1 addition & 2 deletions custom_components/teslemetry/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.const import ATTR_CODE
from homeassistant.helpers.restore_state import RestoreEntity

from .const import DOMAIN, TeslemetryChargeCableLockStates, TeslemetryTimestamp
from .const import DOMAIN, TeslemetryChargeCableLockStates
from .entity import (
TeslemetryVehicleEntity,
TeslemetryVehicleStreamEntity,
Expand Down
1 change: 0 additions & 1 deletion custom_components/teslemetry/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ async def async_media_previous_track(self) -> None:
class TeslemetryPollingMediaEntity(TeslemetryVehicleEntity, MediaPlayerEntity):
"""Polling vehicle media player class."""


def __init__(
self,
data: TeslemetryVehicleData,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tesla_fleet_api import EnergySpecific, VehicleSpecific
from tesla_fleet_api.const import Scope

from teslemetry_stream import TeslemetryStream, TeslemetryStreamVehicle
from teslemetry_stream import TeslemetryStream

from homeassistant.helpers.device_registry import DeviceInfo

Expand Down
1 change: 1 addition & 0 deletions custom_components/teslemetry/repairs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Teslemetry Repairs."""
from __future__ import annotations


Expand Down
2 changes: 1 addition & 1 deletion custom_components/teslemetry/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity

from .const import TeslemetryHeaterOptions, TeslemetryTimestamp
from .const import TeslemetryHeaterOptions
from .entity import (
TeslemetryVehicleEntity,
TeslemetryEnergyInfoEntity,
Expand Down
19 changes: 12 additions & 7 deletions custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
)
from .models import TeslemetryEnergyData, TeslemetryVehicleData

from .helpers import ignore_drop

class TeslemetryOptions:
"""Helper class to handle options for sensor entities."""
Expand All @@ -67,7 +66,6 @@ def get(self, value, default=None):
"""Get the value if it is a valid option."""
if isinstance(value, str):
option = value.replace(self.prefix, "").lower()
print(value,option)
if option in self.options:
return option
return default
Expand All @@ -82,28 +80,23 @@ def get(self, value, default=None):
"nopower",
]
)

ShiftState = TeslemetryOptions("ShiftState",["p", "d", "r", "n"])

ForwardCollisionSensitivity = TeslemetryOptions("ForwardCollisionSensitivity", [
"off",
"late",
"average",
"early"
])

ScheduledChargingMode = TeslemetryOptions("ScheduledChargingMode", [
"off",
"startat",
"departby"
])

LaneAssistLevel = TeslemetryOptions("LaneAssistLevel", [
"off",
"warning",
"assist"
])

SentryModeState = TeslemetryOptions("SentryModeState", ["off", "idle", "armed", "aware", "panic", "quiet"])
SpeedAssistLevel = TeslemetryOptions("SpeedAssistLevel", ["none", "display", "chime"])
DisplayState = TeslemetryOptions("DisplayState", [
Expand All @@ -118,6 +111,17 @@ def get(self, value, default=None):
"dog",
"entertainment"
])
BMSState = TeslemetryOptions("BMSState", ["standby",
"drive",
"support",
"charge",
"feim",
"clearfault",
"fault",
"weld",
"test",
"sna"
])

WALL_CONNECTOR_STATES = {
0: "booting",
Expand Down Expand Up @@ -1172,6 +1176,7 @@ class TeslemetrySensorEntityDescription(SensorEntityDescription):
@dataclass(frozen=True, kw_only=True)
class TeslemetryTimeEntityDescription(SensorEntityDescription):
"""Describes Teslemetry Sensor entity."""

polling: bool = False
variance: int = 60
streaming_key: Signal | None = None
Expand Down
1 change: 0 additions & 1 deletion custom_components/teslemetry/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging

from tesla_fleet_api.exceptions import TeslaFleetError
import voluptuous as vol
from voluptuous import All, Range

Expand Down
Loading

0 comments on commit cd979de

Please sign in to comment.