|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import logging |
| 5 | +from datetime import datetime, timezone |
5 | 6 | from typing import TYPE_CHECKING, Callable |
6 | 7 |
|
7 | 8 | from .const import ( |
|
28 | 29 | HvacPowerState, |
29 | 30 | HvilStatus, |
30 | 31 | LaneAssistLevel, |
| 32 | + MediaStatus, |
31 | 33 | PowershareState, |
32 | 34 | PowershareStopReasonStatus, |
33 | 35 | PowershareTypeStatus, |
|
39 | 41 | SunroofInstalledState, |
40 | 42 | TemperatureUnit, |
41 | 43 | TeslaLocation, |
| 44 | + TurnSignalState, |
42 | 45 | WindowState, |
43 | | - MediaStatus |
44 | 46 | ) |
45 | 47 |
|
46 | 48 | if TYPE_CHECKING: |
@@ -1521,11 +1523,11 @@ def listen_ScheduledChargingPending(self, callback: Callable[[bool | None], None |
1521 | 1523 | {"vin":self.vin, "data": {Signal.SCHEDULED_CHARGING_PENDING: None}} |
1522 | 1524 | ) |
1523 | 1525 |
|
1524 | | - def listen_ScheduledChargingStartTime(self, callback: Callable[[str | None], None]) -> Callable[[],None]: |
| 1526 | + def listen_ScheduledChargingStartTime(self, callback: Callable[[datetime | None], None]) -> Callable[[],None]: |
1525 | 1527 | """Listen for Scheduled Charging Start Time.""" |
1526 | 1528 | self._enable_field(Signal.SCHEDULED_CHARGING_START_TIME) |
1527 | 1529 | return self.stream.async_add_listener( |
1528 | | - lambda x: callback(x['data'][Signal.SCHEDULED_CHARGING_START_TIME]), |
| 1530 | + make_datetime(Signal.SCHEDULED_CHARGING_START_TIME, callback), |
1529 | 1531 | {"vin":self.vin, "data": {Signal.SCHEDULED_CHARGING_START_TIME: None}} |
1530 | 1532 | ) |
1531 | 1533 |
|
@@ -1745,35 +1747,35 @@ def listen_TpmsHardWarnings(self, callback: Callable[[int | None], None]) -> Cal |
1745 | 1747 | {"vin":self.vin, "data": {Signal.TPMS_HARD_WARNINGS: None}} |
1746 | 1748 | ) |
1747 | 1749 |
|
1748 | | - def listen_TpmsLastSeenPressureTimeFl(self, callback: Callable[[str | None], None]) -> Callable[[],None]: |
| 1750 | + def listen_TpmsLastSeenPressureTimeFl(self, callback: Callable[[datetime | None], None]) -> Callable[[],None]: |
1749 | 1751 | """Listen for TPMS Last Seen Pressure Time Front Left.""" |
1750 | 1752 | self._enable_field(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FL) |
1751 | 1753 | return self.stream.async_add_listener( |
1752 | | - lambda x: callback(x['data'][Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FL]), |
| 1754 | + make_datetime(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FL, callback), |
1753 | 1755 | {"vin":self.vin, "data": {Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FL: None}} |
1754 | 1756 | ) |
1755 | 1757 |
|
1756 | | - def listen_TpmsLastSeenPressureTimeFr(self, callback: Callable[[str | None], None]) -> Callable[[],None]: |
| 1758 | + def listen_TpmsLastSeenPressureTimeFr(self, callback: Callable[[datetime | None], None]) -> Callable[[],None]: |
1757 | 1759 | """Listen for TPMS Last Seen Pressure Time Front Right.""" |
1758 | 1760 | self._enable_field(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FR) |
1759 | 1761 | return self.stream.async_add_listener( |
1760 | | - lambda x: callback(x['data'][Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FR]), |
| 1762 | + make_datetime(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FR, callback), |
1761 | 1763 | {"vin":self.vin, "data": {Signal.TPMS_LAST_SEEN_PRESSURE_TIME_FR: None}} |
1762 | 1764 | ) |
1763 | 1765 |
|
1764 | | - def listen_TpmsLastSeenPressureTimeRl(self, callback: Callable[[str | None], None]) -> Callable[[],None]: |
| 1766 | + def listen_TpmsLastSeenPressureTimeRl(self, callback: Callable[[datetime | None], None]) -> Callable[[],None]: |
1765 | 1767 | """Listen for TPMS Last Seen Pressure Time Rear Left.""" |
1766 | 1768 | self._enable_field(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RL) |
1767 | 1769 | return self.stream.async_add_listener( |
1768 | | - lambda x: callback(x['data'][Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RL]), |
| 1770 | + make_datetime(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RL, callback), |
1769 | 1771 | {"vin":self.vin, "data": {Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RL: None}} |
1770 | 1772 | ) |
1771 | 1773 |
|
1772 | | - def listen_TpmsLastSeenPressureTimeRr(self, callback: Callable[[str | None], None]) -> Callable[[],None]: |
| 1774 | + def listen_TpmsLastSeenPressureTimeRr(self, callback: Callable[[datetime | None], None]) -> Callable[[],None]: |
1773 | 1775 | """Listen for TPMS Last Seen Pressure Time Rear Right.""" |
1774 | 1776 | self._enable_field(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RR) |
1775 | 1777 | return self.stream.async_add_listener( |
1776 | | - lambda x: callback(x['data'][Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RR]), |
| 1778 | + make_datetime(Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RR, callback), |
1777 | 1779 | {"vin":self.vin, "data": {Signal.TPMS_LAST_SEEN_PRESSURE_TIME_RR: None}} |
1778 | 1780 | ) |
1779 | 1781 |
|
@@ -2067,6 +2069,18 @@ def typer(event: dict): |
2067 | 2069 | callback(None) |
2068 | 2070 | return typer |
2069 | 2071 |
|
| 2072 | +def make_datetime(signal: Signal, callback: Callable[[datetime | None], None]) -> Callable[[dict], None]: |
| 2073 | + """Listener factory""" |
| 2074 | + def typer(event: dict): |
| 2075 | + data = event["data"][signal] |
| 2076 | + if isinstance(data, int): |
| 2077 | + try: |
| 2078 | + data = datetime.fromtimestamp(data, tz=timezone.utc) |
| 2079 | + except ValueError: |
| 2080 | + data = None |
| 2081 | + callback(data) |
| 2082 | + return typer |
| 2083 | + |
2070 | 2084 | def merge(source, destination): |
2071 | 2085 | for key, value in source.items(): |
2072 | 2086 | if isinstance(value, dict): |
|
0 commit comments