-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add odometer event * add test and missing service event name for odometer * add vehicle_events * adding vehicle events and tests
- Loading branch information
1 parent
63694f4
commit 3b33be6
Showing
9 changed files
with
385 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Models related to vehicle events from the MQTT broker.""" | ||
|
||
from dataclasses import dataclass, field | ||
from datetime import datetime | ||
from enum import StrEnum | ||
from typing import Generic, TypeVar | ||
|
||
from mashumaro import field_options | ||
from mashumaro.mixins.orjson import DataClassORJSONMixin | ||
|
||
from myskoda.models.vehicle_ignition_status import IgnitionStatus, UnexpectedIgnitionStatusError | ||
|
||
|
||
class VehicleEventName(StrEnum): | ||
"""List of known vehicle EventNames.""" | ||
|
||
VEHICLE_AWAKE = "vehicle-awake" | ||
VEHICLE_CONNECTION_ONLINE = "vehicle-connection-online" | ||
VEHICLE_WARNING_BATTEYLEVEL = "vehicle-warning-batterylevel" | ||
VEHICLE_IGNITION_STATUS_CHANGED = "vehicle-ignition-status-changed" | ||
|
||
|
||
@dataclass | ||
class VehicleEventData(DataClassORJSONMixin): | ||
"""Base class for data in vehicle events.""" | ||
|
||
user_id: str = field(metadata=field_options(alias="userId")) | ||
vin: str | ||
|
||
|
||
T = TypeVar("T", bound=VehicleEventData) | ||
|
||
|
||
@dataclass | ||
class VehicleEvent(Generic[T], DataClassORJSONMixin): | ||
"""Main model for Vehicle Events. | ||
Vehicle Events are unsolicited events emitted by the MQTT bus towards the client. | ||
""" | ||
|
||
version: int | ||
producer: str | ||
name: VehicleEventName | ||
data: T | ||
trace_id: str = field(metadata=field_options(alias="traceId")) | ||
timestamp: datetime | None = field(default=None) | ||
|
||
|
||
def _deserialize_ignition_status(value: str) -> IgnitionStatus: | ||
match value: | ||
case "ON": | ||
return IgnitionStatus.ON | ||
case "OFF": | ||
return IgnitionStatus.OFF | ||
case _: | ||
raise UnexpectedIgnitionStatusError | ||
|
||
|
||
@dataclass | ||
class VehicleEventVehicleIgnitionStatusData(VehicleEventData): | ||
"""Ignition data inside vehicle service event vehicle-ignition-status.""" | ||
|
||
ignition_status: IgnitionStatus | None = field( | ||
default=None, | ||
metadata=field_options(alias="ignitionStatus", deserialize=_deserialize_ignition_status), | ||
) | ||
|
||
|
||
@dataclass | ||
class VehicleEventWithVehicleIgnitionStatusData(VehicleEvent): | ||
data: VehicleEventVehicleIgnitionStatusData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import StrEnum | ||
|
||
|
||
class IgnitionStatus(StrEnum): | ||
ON = "ON" | ||
OFF = "OFF" | ||
|
||
|
||
class UnexpectedIgnitionStatusError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.