Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Dec 9, 2024
1 parent 8e5d0bc commit 65c50fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
7 changes: 4 additions & 3 deletions custom_components/teslemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
vin = product["vin"]
api = VehicleSpecific(teslemetry.vehicle, vin)
coordinator = TeslemetryVehicleDataCoordinator(hass, api, product)
firmware = metadata[vin]["access"]
firmware = metadata[vin]["firmware"]

device = DeviceInfo(
identifiers={(DOMAIN, vin)},
Expand Down Expand Up @@ -196,7 +196,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Run all coordinator first refreshes
await asyncio.gather(
*(
async_setup_stream(vehicle.stream_vehicle)
async_setup_stream(vehicle)
for vehicle in vehicles
),
*(
Expand Down Expand Up @@ -265,8 +265,9 @@ def handle_vehicle_stream(data: dict) -> None:

return handle_vehicle_stream

async def async_setup_stream(vehicle_stream: TeslemetryStreamVehicle):
async def async_setup_stream(vehicle: TeslemetryVehicleData):
"""Set up the stream for a vehicle."""

vehicle_stream = vehicle.stream.get_vehicle(vehicle.vin)
await vehicle_stream.get_config()
await vehicle_stream.prefer_typed(True)
2 changes: 1 addition & 1 deletion custom_components/teslemetry/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
"""Initialize the sensor."""
self.entity_description = description
super().__init__(
data, description.key, description.timestamp_key, description.streaming_key
data, description.key
)

def _async_update_attrs(self) -> None:
Expand Down
23 changes: 9 additions & 14 deletions custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ async def async_setup_entry(

entities = []
for vehicle in entry.runtime_data.vehicles:
if vehicle.api.pre2021:
# Vehicle cannot use streaming
for description in VEHICLE_DESCRIPTIONS:
if description.polling_parent:
entities.append(TeslemetryVehicleSensorEntity(vehicle, description))
for description in VEHICLE_TIME_DESCRIPTIONS:
entities.append(TeslemetryVehicleTimeSensorEntity(vehicle, description))
else:
for description in VEHICLE_DESCRIPTIONS:
if description.streaming_key and description.streaming_firmware >= vehicle.firmware:
entities.append(TeslemetryStreamSensorEntity(vehicle, description))
elif description.polling_parent:
entities.append(TeslemetryVehicleSensorEntity(vehicle, description))
for description in VEHICLE_TIME_DESCRIPTIONS:
for description in VEHICLE_DESCRIPTIONS:
if not vehicle.api.pre2021 and description.streaming_key and description.streaming_firmware >= vehicle.firmware:
entities.append(TeslemetryStreamSensorEntity(vehicle, description))
elif description.polling_parent:
entities.append(TeslemetryVehicleSensorEntity(vehicle, description))
for description in VEHICLE_TIME_DESCRIPTIONS:
if not vehicle.api.pre2021 and description.streaming_firmware >= vehicle.firmware:
entities.append(TeslemetryVehicleTimeStreamSensorEntity(vehicle, description))
else:
entities.append(TeslemetryVehicleTimeSensorEntity(vehicle, description))

for energysite in entry.runtime_data.energysites:
for description in ENERGY_LIVE_DESCRIPTIONS:
Expand Down
1 change: 1 addition & 0 deletions custom_components/teslemetry/sensor_descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ class TeslemetryTimeEntityDescription(SensorEntityDescription):
variance: int = 60
polling_parent: TeslemetryPollingKeys | None = None
streaming_key: Signal | None = None
streaming_firmware: str = "2024.26"


VEHICLE_TIME_DESCRIPTIONS: tuple[TeslemetryTimeEntityDescription, ...] = (
Expand Down

0 comments on commit 65c50fd

Please sign in to comment.