Skip to content

Commit

Permalink
v0.5.3 vehicles and renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 8, 2024
1 parent 16f1635 commit d13f5d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="teslemetry_stream",
version="0.5.2",
version="0.5.3",
author="Brett Adams",
author_email="hello@teslemetry.com",
description="Teslemetry Streaming API library for Python",
Expand Down
6 changes: 3 additions & 3 deletions teslemetry_stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TeslemetryStreamVehicleNotConfigured,
TeslemetryStreamEnded
)
from .const import TelemetryFields, TelemetryAlerts
from .const import Signal, Alert

__all__ = [
"TeslemetryStream",
Expand All @@ -15,6 +15,6 @@
"TeslemetryStreamConnectionError",
"TeslemetryStreamVehicleNotConfigured",
"TeslemetryStreamEnded",
"TelemetryFields",
"TelemetryAlerts"
"Signal",
"Alert"
]
8 changes: 4 additions & 4 deletions teslemetry_stream/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class StrEnum(str, Enum):
"""String Enum"""


class TelemetryFields(StrEnum):
"""Fields available in telemetry streams"""
class Signal(StrEnum):
"""Signals available in Fleet Telemetry streams"""

AC_CHARGING_ENERGY_IN = "ACChargingEnergyIn"
AC_CHARGING_POWER = "ACChargingPower"
Expand Down Expand Up @@ -213,8 +213,8 @@ class TelemetryFields(StrEnum):
WIPER_HEAT_ENABLED = "WiperHeatEnabled"


class TelemetryAlerts(StrEnum):
"""Alerts available in telemetry streams"""
class Alert(StrEnum):
"""Alerts available in Fleet Telemetry streams"""

CUSTOMER = "Customer"
SERVICE = "Service"
Expand Down
11 changes: 6 additions & 5 deletions teslemetry_stream/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TeslemetryStream:
delay: int
active = None
vehicle: TeslemetryStreamVehicle
vehicles: dict[str, TeslemetryStreamVehicle] = {}

def __init__(
self,
Expand All @@ -39,15 +40,15 @@ def __init__(
self.delay = DELAY

if(self.vin):
self.vehicle = self.create_vehicle(self.vin)
self.vehicle = self.get_vehicle(self.vin)

def create_vehicle(self, vin: str) -> TeslemetryStreamVehicle:
def get_vehicle(self, vin: str) -> TeslemetryStreamVehicle:
"""Create a vehicle stream."""
if self.vin is not None and self.vin != vin:
raise AttributeError("Stream started in single vehicle mode")
if hasattr(self, 'vehicle'):
return self.vehicle
return TeslemetryStreamVehicle(self, vin)
if vin not in self.vehicles:
self.vehicles[vin] = TeslemetryStreamVehicle(self, vin)
return self.vehicles[vin]

@property
def connected(self) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions teslemetry_stream/vehicle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING
import asyncio
import logging
from .const import TelemetryFields
from .const import Signal

if TYPE_CHECKING:
from .stream import TeslemetryStream
Expand All @@ -13,7 +13,7 @@
class TeslemetryStreamVehicle:
"""Handle streaming field updates."""

fields: dict[TelemetryFields, dict[str, int]] = {}
fields: dict[Signal, dict[str, int]] = {}
preferTyped: bool | None = None
_config: dict = {}

Expand Down Expand Up @@ -73,9 +73,9 @@ async def update_config(self, config: dict) -> None:
self.preferTyped = prefer_typed
self._config.clear()

async def add_field(self, field: TelemetryFields | str, interval: int | None = None) -> None:
async def add_field(self, field: Signal | str, interval: int | None = None) -> None:
"""Handle vehicle data from the stream."""
if isinstance(field, TelemetryFields):
if isinstance(field, Signal):
field = field.value

if field in self.fields and (interval is None or self.fields[field].get("interval_seconds") == interval):
Expand Down

0 comments on commit d13f5d2

Please sign in to comment.