From 0192bdf2dd8b505f3df04f6d3a8f11f13b9f6ceb Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Tue, 10 Nov 2026 04:41:31 +0000 Subject: [PATCH 1/6] Pass subscription errors to an on_error callback The server ends a subscription with an `error` message when it fails, for example when the vehicle refuses a command the subscription waits on. The web socket only logged those at debug, so a caller waiting on the subscription could only time out. Subscriptions can now take an `on_error` callback that gets the error message; existing callers are unchanged. --- src/rivian/rivian.py | 5 ++++- src/rivian/ws_monitor.py | 29 ++++++++++++++++++++++++----- tests/test_ws_monitor.py | 22 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/rivian/rivian.py b/src/rivian/rivian.py index c9cd86d..c4854de 100644 --- a/src/rivian/rivian.py +++ b/src/rivian/rivian.py @@ -1136,6 +1136,7 @@ async def _start_subscription( payload: dict[str, Any], callback: Callable[[dict[str, Any]], None], description: str, + on_error: Callable[[dict[str, Any]], None] | None = None, ) -> Callable[[], Awaitable[None]] | None: """Connect the web socket if needed and start a subscription. @@ -1146,7 +1147,9 @@ async def _start_subscription( ws_monitor = await self._ws_connect() # Ends early if the connection closes, e.g. when rate limited if await ws_monitor.wait_for_ack() and ( - unsubscribe := await ws_monitor.start_subscription(payload, callback) + unsubscribe := await ws_monitor.start_subscription( + payload, callback, on_error=on_error + ) ): _LOGGER.debug("Subscribed to %s", description) return unsubscribe diff --git a/src/rivian/ws_monitor.py b/src/rivian/ws_monitor.py index 6e6e77e..bf0a339 100644 --- a/src/rivian/ws_monitor.py +++ b/src/rivian/ws_monitor.py @@ -98,8 +98,14 @@ def __init__( self._monitor_task: asyncio.Task | None = None self._receiver_task: asyncio.Task | None = None self._last_received: datetime | None = None + # id -> (callback, payload, error callback) self._subscriptions: dict[ - str, tuple[Callable[[dict[str, Any]], None], dict[str, Any]] + str, + tuple[ + Callable[[dict[str, Any]], None], + dict[str, Any], + Callable[[dict[str, Any]], None] | None, + ], ] = {} @property @@ -211,13 +217,20 @@ async def wait_for_ack(self) -> bool: return self._connection_ack.is_set() async def start_subscription( - self, payload: dict[str, Any], callback: Callable[[dict[str, Any]], None] + self, + payload: dict[str, Any], + callback: Callable[[dict[str, Any]], None], + on_error: Callable[[dict[str, Any]], None] | None = None, ) -> Callable[[], Awaitable[None]] | None: - """Start a subscription.""" + """Start a subscription. + + `on_error` gets the subscription's error messages, which are otherwise + only logged. + """ if not self.connected: return None _id = str(uuid4()) - self._subscriptions[_id] = (callback, payload) + self._subscriptions[_id] = (callback, payload, on_error) await self._subscribe(_id, payload) async def unsubscribe() -> None: @@ -247,7 +260,7 @@ async def _resubscribe_all(self) -> None: except TimeoutError: _LOGGER.error("A timeout occurred while attempting to resubscribe") return - for _id, (_, payload) in self._subscriptions.items(): + for _id, (_, payload, _) in self._subscriptions.items(): await self._subscribe(_id, payload) async def _receiver(self) -> None: @@ -305,6 +318,12 @@ async def _receive(self, websocket: ClientWebSocketResponse[bool]) -> None: _fn(data) except Exception: # pylint: disable=broad-except _LOGGER.exception("Error in a subscription callback") + elif ( + data_type == "error" + and (subscription := self._subscriptions.get(data.get("id"))) + and subscription[2] + ): + subscription[2](data) else: self._log_message(msg) elif msg.type == WSMsgType.ERROR: diff --git a/tests/test_ws_monitor.py b/tests/test_ws_monitor.py index 7f5a4bd..88d7a52 100644 --- a/tests/test_ws_monitor.py +++ b/tests/test_ws_monitor.py @@ -31,6 +31,7 @@ def __init__(self) -> None: self.ping_once_connections = 0 self.connections = 0 self.next_on_subscribe = False + self.error_on_subscribe = False self.url = "" async def handler(self, request: web.Request) -> web.WebSocketResponse: @@ -72,6 +73,10 @@ async def handler(self, request: web.Request) -> web.WebSocketResponse: data = msg.json() if self.next_on_subscribe and data.get("type") == "subscribe": await ws.send_json({"id": data["id"], "type": "next"}) + if self.error_on_subscribe and data.get("type") == "subscribe": + await ws.send_json( + {"id": data["id"], "type": "error", "payload": [{}]} + ) return ws @@ -159,7 +164,7 @@ async def fake_sleep(delay: float) -> None: def add_subscription(monitor: WebSocketMonitor) -> None: """Give the monitor a subscription to resume, so it keeps reconnecting.""" - monitor._subscriptions["sub"] = (lambda _: None, {"query": "subscription"}) + monitor._subscriptions["sub"] = (lambda _: None, {"query": "subscription"}, None) async def wait_for(condition: Any, timeout: float = 5) -> None: @@ -594,3 +599,18 @@ async def test_monitor_stops_when_the_session_closes( await wait_for(monitor.monitor.done) assert server.connections == 1 assert not [r for r in caplog.records if r.levelname == "ERROR"] + + +async def test_subscription_errors_reach_on_error( + server: FakeServer, monitor: WebSocketMonitor +) -> None: + """A subscription's error message goes to its on_error, if it has one.""" + server.error_on_subscribe = True + await monitor.new_connection(start_monitor=True) + await wait_for(lambda: monitor.connection_ack.is_set()) + errors: list[dict[str, Any]] = [] + await monitor.start_subscription({"query": "a"}, lambda _: None, errors.append) + await monitor.start_subscription({"query": "b"}, lambda _: None) + await wait_for(lambda: errors) + assert errors[0]["type"] == "error" + assert monitor.connected From e8fe7d97e8eb1c4e59ba5e81f4f0da88a2a4c3f7 Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Sun, 15 Nov 2026 18:17:39 +0000 Subject: [PATCH 2/6] Guard the on_error callback like the next callback An `on_error` that raised escaped the receive loop and ended the receiver task. Both callbacks now run through `_run_callback`, which logs a failure instead of raising and awaits coroutine callbacks. --- src/rivian/ws_monitor.py | 28 ++++++++++++++++++---------- tests/test_ws_monitor.py | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/rivian/ws_monitor.py b/src/rivian/ws_monitor.py index bf0a339..dd2578d 100644 --- a/src/rivian/ws_monitor.py +++ b/src/rivian/ws_monitor.py @@ -55,6 +55,22 @@ class _Backoff: rate_limited: bool = False # whether the backoff until retry_at is a rate limit +async def _run_callback( + callback: Callable[[dict[str, Any]], None], data: dict[str, Any] +) -> None: + """Run a subscription callback, logging instead of raising if it fails. + + A failing callback shouldn't take the connection down. + """ + try: + if inspect.iscoroutinefunction(callback): + await callback(data) + else: + callback(data) + except Exception: # pylint: disable=broad-except + _LOGGER.exception("Error in a subscription callback") + + class WebSocketMonitor: """Web socket monitor for a vehicle.""" @@ -309,21 +325,13 @@ async def _receive(self, websocket: ClientWebSocketResponse[bool]) -> None: elif data_type == "next": self._reset_backoff() if (_id := data.get("id")) in self._subscriptions: - _fn = self._subscriptions[_id][0] - # A failing callback shouldn't take the connection down - try: - if inspect.iscoroutinefunction(_fn): - await _fn(data) - else: - _fn(data) - except Exception: # pylint: disable=broad-except - _LOGGER.exception("Error in a subscription callback") + await _run_callback(self._subscriptions[_id][0], data) elif ( data_type == "error" and (subscription := self._subscriptions.get(data.get("id"))) and subscription[2] ): - subscription[2](data) + await _run_callback(subscription[2], data) else: self._log_message(msg) elif msg.type == WSMsgType.ERROR: diff --git a/tests/test_ws_monitor.py b/tests/test_ws_monitor.py index 88d7a52..3ea5bbe 100644 --- a/tests/test_ws_monitor.py +++ b/tests/test_ws_monitor.py @@ -614,3 +614,26 @@ async def test_subscription_errors_reach_on_error( await wait_for(lambda: errors) assert errors[0]["type"] == "error" assert monitor.connected + + +async def test_failing_on_error_keeps_connection( + server: FakeServer, + monitor: WebSocketMonitor, + caplog: pytest.LogCaptureFixture, +) -> None: + """An on_error that raises is logged, and later messages still arrive.""" + server.error_on_subscribe = True + await monitor.new_connection(start_monitor=True) + await wait_for(lambda: monitor.connection_ack.is_set()) + + def failing(_: dict[str, Any]) -> None: + raise ValueError("on_error failed") + + errors: list[dict[str, Any]] = [] + await monitor.start_subscription({"query": "a"}, lambda _: None, failing) + await monitor.start_subscription({"query": "b"}, lambda _: None, errors.append) + await wait_for(lambda: errors) + + assert "Error in a subscription callback" in caplog.text + assert monitor.connected + assert server.connections == 1 From 206cf0901d73c64c82716fc40650a24aa860532b Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Tue, 10 Nov 2026 04:41:31 +0000 Subject: [PATCH 3/6] Add starting a Gear Guard live stream `start_gear_guard_live_stream` starts a live camera stream the way the Rivian app does and returns its Kinesis Video WebRTC config (signaling endpoint, ICE servers and role), for a viewer to join: - It subscribes to `gearGuardLiveConfig` with a fresh command id, then sends the signed `security.video_monitoring.start_live_streaming` command with that same id; the cloud routes the config by it. - `parallax.encode_live_streaming` builds the command's payload from a new `LiveStreamingRequest` schema; `GEAR_GUARD_CAMERAS` names the cameras. - A refused start (e.g. a camera the vehicle doesn't have) raises RivianApiException straight away, through the subscription's `on_error`. It needs Gear Guard video monitoring on and a paired phone. The vehicle serves one session at a time, about 3 minutes each and an hour a day. Builds on #249. Verified against a 2026 R1S (Gen 2) running 2026.36.01: the config arrived within seconds of the start when the vehicle was awake, and the front and right cameras streamed in a WebRTC viewer. A sleeping vehicle can take longer to wake than the default 40 second timeout. Not tested: the rear, left and bed cameras, the R2's cabin camera. --- src/rivian/parallax/__init__.py | 10 +++ src/rivian/parallax/proto/security.proto | 16 +++++ src/rivian/parallax/proto/security_pb2.py | 46 +++++++------ src/rivian/parallax/proto/security_pb2.pyi | 25 +++++++ src/rivian/parallax/security.py | 18 +++++ src/rivian/rivian.py | 78 ++++++++++++++++++++++ tests/parallax/test_security.py | 10 +++ tests/test_rivian.py | 59 ++++++++++++++++ 8 files changed, 241 insertions(+), 21 deletions(-) diff --git a/src/rivian/parallax/__init__.py b/src/rivian/parallax/__init__.py index 530e1a5..b1cdeb4 100644 --- a/src/rivian/parallax/__init__.py +++ b/src/rivian/parallax/__init__.py @@ -19,6 +19,8 @@ Reads a raw `subscribe_for_parallax_command_state` message. encode_end_trip(user_id) -> str Builds the unsigned `end_trip` request. + encode_live_streaming(camera, device_id) -> bytes + A Gear Guard live stream start, for `start_gear_guard_live_stream`. Layout: core.py - registry, payload parsing and shared helpers @@ -68,6 +70,11 @@ ) from .navigation import UPDATED_TRIP_MODEL, encode_end_trip from .operation import encode_vehicle_operation +from .security import ( + GEAR_GUARD_CAMERAS, + START_LIVE_STREAMING_RVM, + encode_live_streaming, +) PARALLAX_RVMS: list[str] = list(RVMDecoder.decoders) @@ -88,8 +95,10 @@ "CHARGING_RVMS", "CLIMATE_HOLD_SETTING_RVM", "CLIMATE_HOLD_STATUS_RVM", + "GEAR_GUARD_CAMERAS", "LOCK_RVM", "PARALLAX_RVMS", + "START_LIVE_STREAMING_RVM", "UNLOCK_RVM", "UPDATED_TRIP_MODEL", "decode_command_state_message", @@ -98,6 +107,7 @@ "encode_climate_hold_setting", "encode_command", "encode_end_trip", + "encode_live_streaming", "encode_lock", "encode_unlock", "encode_vehicle_operation", diff --git a/src/rivian/parallax/proto/security.proto b/src/rivian/parallax/proto/security.proto index cebfd21..0457397 100644 --- a/src/rivian/parallax/proto/security.proto +++ b/src/rivian/parallax/proto/security.proto @@ -129,3 +129,19 @@ enum TosAcceptance { TOS_NOT_ACCEPTED = 1; TOS_ACCEPTED = 2; } + +// security.video_monitoring.start_live_streaming +message LiveStreamingRequest { + GearGuardCamera camera = 1; + string device_id = 2; // a label for the viewer; any stable string works +} + +enum GearGuardCamera { // the app's camera selector + GEAR_GUARD_CAMERA_UNSPECIFIED = 0; + GEAR_GUARD_CAMERA_FRONT = 1; + GEAR_GUARD_CAMERA_BED = 2; + GEAR_GUARD_CAMERA_LEFT = 3; + GEAR_GUARD_CAMERA_RIGHT = 4; + GEAR_GUARD_CAMERA_REAR = 5; + GEAR_GUARD_CAMERA_INTERIOR = 6; +} diff --git a/src/rivian/parallax/proto/security_pb2.py b/src/rivian/parallax/proto/security_pb2.py index 617a4b9..408b1e3 100644 --- a/src/rivian/parallax/proto/security_pb2.py +++ b/src/rivian/parallax/proto/security_pb2.py @@ -24,33 +24,35 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$rivian/parallax/proto/security.proto\x12\x18rivian.parallax.security\"\x0e\n\x0cPassiveEntry\"\xe7\x03\n\x03\x42tm\x12:\n\x02\x66\x66\x18\x01 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x00\x88\x01\x01\x12:\n\x02ic\x18\x02 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x01\x88\x01\x01\x12;\n\x03lfd\x18\x03 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x02\x88\x01\x01\x12:\n\x02rf\x18\x04 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x03\x88\x01\x01\x12;\n\x03rfd\x18\x05 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x04\x88\x01\x01\x12:\n\x02oc\x18\x06 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x05\x88\x01\x01\x12\x11\n\tffr_error\x18\x07 \x01(\x05\x12\x11\n\trfr_error\x18\x08 \x01(\x05\x12\x11\n\tffl_error\x18\t \x01(\x05\x12\x11\n\trfl_error\x18\n \x01(\x05\x42\x05\n\x03_ffB\x05\n\x03_icB\x06\n\x04_lfdB\x05\n\x03_rfB\x06\n\x04_rfdB\x05\n\x03_oc\"_\n\x10ImmobilizerState\x12@\n\x06status\x18\x01 \x01(\x0e\x32+.rivian.parallax.security.ImmobilizerStatusH\x00\x88\x01\x01\x42\t\n\x07_status\"\xba\x01\n\x11PassiveEntryDebug\x12\x45\n\x06reason\x18\x01 \x01(\x0e\x32\x30.rivian.parallax.security.PassiveEntryFailReasonH\x00\x88\x01\x01\x12S\n\x1bsend_lock_fail_notification\x18\x02 \x01(\x0e\x32..rivian.parallax.security.LockFailNotificationB\t\n\x07_reason\"\xbe\x01\n\x08VasFault\x12K\n\x0esecure_element\x18\x01 \x01(\x0e\x32..rivian.parallax.security.SecureElementFaultedH\x00\x88\x01\x01\x12\x43\n\naccess_can\x18\x02 \x01(\x0e\x32*.rivian.parallax.security.AccessCanFaultedH\x01\x88\x01\x01\x42\x11\n\x0f_secure_elementB\r\n\x0b_access_can\"\x8d\x01\n\nAlarmState\x12>\n\x0bsound_alarm\x18\x01 \x01(\x0e\x32$.rivian.parallax.security.AlarmSoundH\x00\x88\x01\x01\x12/\n\'consecutive_alarm_disabled_notification\x18\x02 \x01(\x08\x42\x0e\n\x0c_sound_alarm\"\x81\x02\n\x14VideoMonitoringState\x12\x44\n\x06status\x18\x01 \x01(\x0e\x32/.rivian.parallax.security.VideoMonitoringStatusH\x00\x88\x01\x01\x12\x36\n\x04mode\x18\x02 \x01(\x0e\x32#.rivian.parallax.security.VideoModeH\x01\x88\x01\x01\x12\x44\n\x0eterms_accepted\x18\x03 \x01(\x0e\x32\'.rivian.parallax.security.TosAcceptanceH\x02\x88\x01\x01\x42\t\n\x07_statusB\x07\n\x05_modeB\x11\n\x0f_terms_accepted*M\n\x0fHardwareFailure\x12 \n\x1cHARDWARE_FAILURE_UNSPECIFIED\x10\x00\x12\x18\n\x14HARDWARE_FAILURE_SET\x10\x01*v\n\x11ImmobilizerStatus\x12\x1c\n\x18IMMOBILIZER_NOT_ASSIGNED\x10\x00\x12\x1e\n\x1aIMMOBILIZER_NOT_AUTHORIZED\x10\x01\x12#\n\x1fIMMOBILIZER_AUTHORIZED_TO_DRIVE\x10\x02*y\n\x14LockFailNotification\x12\x1e\n\x1aLOCK_FAIL_NOTIFICATION_SNA\x10\x00\x12\x1f\n\x1bLOCK_FAIL_NOTIFICATION_TRUE\x10\x01\x12 \n\x1cLOCK_FAIL_NOTIFICATION_FALSE\x10\x02*\xfe\x03\n\x16PassiveEntryFailReason\x12\"\n\x1ePASSIVE_ENTRY_FAIL_UNSPECIFIED\x10\x00\x12\x1d\n\x19PASSIVE_ENTRY_NOT_IN_PARK\x10\x01\x12!\n\x1dPASSIVE_ENTRY_AT_HOME_DISABLE\x10\x02\x12#\n\x1fPASSIVE_ENTRY_PASSENGER_IN_SEAT\x10\x03\x12$\n PASSIVE_ENTRY_DEVICE_NOT_ENABLED\x10\x04\x12 \n\x1cPASSIVE_ENTRY_TRANSPORT_MODE\x10\x05\x12\x1f\n\x1bPASSIVE_ENTRY_CAR_WASH_MODE\x10\x06\x12\x1b\n\x17PASSIVE_ENTRY_CAMP_MODE\x10\x07\x12\x1c\n\x18PASSIVE_ENTRY_ACTIVE_OTA\x10\x08\x12$\n PASSIVE_ENTRY_SHOW_AND_TELL_MODE\x10\t\x12#\n\x1fPASSIVE_ENTRY_RCVD_RSSI_PENDING\x10\n\x12#\n\x1fPASSIVE_ENTRY_LOCK_ONLY_AT_HOME\x10\x0b\x12\"\n\x1ePASSIVE_ENTRY_CAR_COSTUME_MODE\x10\x0c\x12!\n\x1dPASSIVE_ENTRY_SLEPT_IMMEDIATE\x10\r*\x9b\x02\n\x14SecureElementFaulted\x12$\n SECURE_ELEMENT_FAULT_UNSPECIFIED\x10\x00\x12\x1d\n\x19SECURE_ELEMENT_NO_FAILURE\x10\x01\x12%\n!SECURE_ELEMENT_LOST_COMMUNICATION\x10\x02\x12(\n$SECURE_ELEMENT_APPLET_NOT_PROGRAMMED\x10\x03\x12!\n\x1dSECURE_ELEMENT_NOT_CONFIGURED\x10\x04\x12!\n\x1dSECURE_ELEMENT_ATTACK_COUNTER\x10\x05\x12\'\n#SECURE_ELEMENT_URSK_DECRYPT_FAILURE\x10\x06*g\n\x10\x41\x63\x63\x65ssCanFaulted\x12 \n\x1c\x41\x43\x43\x45SS_CAN_FAULT_UNSPECIFIED\x10\x00\x12\x19\n\x15\x41\x43\x43\x45SS_CAN_NO_FAILURE\x10\x01\x12\x16\n\x12\x41\x43\x43\x45SS_CAN_FAILURE\x10\x02*|\n\nAlarmSound\x12\x1b\n\x17\x41LARM_SOUND_UNSPECIFIED\x10\x00\x12\x15\n\x11\x41LARM_SOUND_FALSE\x10\x01\x12\x14\n\x10\x41LARM_SOUND_TRUE\x10\x02\x12$\n ALARM_SOUND_SIGNAL_NOT_AVAILABLE\x10\x03*\xb8\x01\n\x15VideoMonitoringStatus\x12\'\n#VIDEO_MONITORING_STATUS_UNSPECIFIED\x10\x00\x12\x1d\n\x19VIDEO_MONITORING_DISABLED\x10\x01\x12\x1c\n\x18VIDEO_MONITORING_ENABLED\x10\x02\x12\x1b\n\x17VIDEO_MONITORING_ACTIVE\x10\x03\x12\x1c\n\x18VIDEO_MONITORING_FAULTED\x10\x04*Z\n\tVideoMode\x12\x13\n\x0fVIDEO_MODE_NONE\x10\x00\x12\x19\n\x15VIDEO_MODE_EVERYWHERE\x10\x01\x12\x1d\n\x19VIDEO_MODE_AWAY_FROM_HOME\x10\x02*W\n\rTosAcceptance\x12\x1e\n\x1aTOS_ACCEPTANCE_UNSPECIFIED\x10\x00\x12\x14\n\x10TOS_NOT_ACCEPTED\x10\x01\x12\x10\n\x0cTOS_ACCEPTED\x10\x02\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$rivian/parallax/proto/security.proto\x12\x18rivian.parallax.security\"\x0e\n\x0cPassiveEntry\"\xe7\x03\n\x03\x42tm\x12:\n\x02\x66\x66\x18\x01 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x00\x88\x01\x01\x12:\n\x02ic\x18\x02 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x01\x88\x01\x01\x12;\n\x03lfd\x18\x03 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x02\x88\x01\x01\x12:\n\x02rf\x18\x04 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x03\x88\x01\x01\x12;\n\x03rfd\x18\x05 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x04\x88\x01\x01\x12:\n\x02oc\x18\x06 \x01(\x0e\x32).rivian.parallax.security.HardwareFailureH\x05\x88\x01\x01\x12\x11\n\tffr_error\x18\x07 \x01(\x05\x12\x11\n\trfr_error\x18\x08 \x01(\x05\x12\x11\n\tffl_error\x18\t \x01(\x05\x12\x11\n\trfl_error\x18\n \x01(\x05\x42\x05\n\x03_ffB\x05\n\x03_icB\x06\n\x04_lfdB\x05\n\x03_rfB\x06\n\x04_rfdB\x05\n\x03_oc\"_\n\x10ImmobilizerState\x12@\n\x06status\x18\x01 \x01(\x0e\x32+.rivian.parallax.security.ImmobilizerStatusH\x00\x88\x01\x01\x42\t\n\x07_status\"\xba\x01\n\x11PassiveEntryDebug\x12\x45\n\x06reason\x18\x01 \x01(\x0e\x32\x30.rivian.parallax.security.PassiveEntryFailReasonH\x00\x88\x01\x01\x12S\n\x1bsend_lock_fail_notification\x18\x02 \x01(\x0e\x32..rivian.parallax.security.LockFailNotificationB\t\n\x07_reason\"\xbe\x01\n\x08VasFault\x12K\n\x0esecure_element\x18\x01 \x01(\x0e\x32..rivian.parallax.security.SecureElementFaultedH\x00\x88\x01\x01\x12\x43\n\naccess_can\x18\x02 \x01(\x0e\x32*.rivian.parallax.security.AccessCanFaultedH\x01\x88\x01\x01\x42\x11\n\x0f_secure_elementB\r\n\x0b_access_can\"\x8d\x01\n\nAlarmState\x12>\n\x0bsound_alarm\x18\x01 \x01(\x0e\x32$.rivian.parallax.security.AlarmSoundH\x00\x88\x01\x01\x12/\n\'consecutive_alarm_disabled_notification\x18\x02 \x01(\x08\x42\x0e\n\x0c_sound_alarm\"\x81\x02\n\x14VideoMonitoringState\x12\x44\n\x06status\x18\x01 \x01(\x0e\x32/.rivian.parallax.security.VideoMonitoringStatusH\x00\x88\x01\x01\x12\x36\n\x04mode\x18\x02 \x01(\x0e\x32#.rivian.parallax.security.VideoModeH\x01\x88\x01\x01\x12\x44\n\x0eterms_accepted\x18\x03 \x01(\x0e\x32\'.rivian.parallax.security.TosAcceptanceH\x02\x88\x01\x01\x42\t\n\x07_statusB\x07\n\x05_modeB\x11\n\x0f_terms_accepted\"d\n\x14LiveStreamingRequest\x12\x39\n\x06\x63\x61mera\x18\x01 \x01(\x0e\x32).rivian.parallax.security.GearGuardCamera\x12\x11\n\tdevice_id\x18\x02 \x01(\t*M\n\x0fHardwareFailure\x12 \n\x1cHARDWARE_FAILURE_UNSPECIFIED\x10\x00\x12\x18\n\x14HARDWARE_FAILURE_SET\x10\x01*v\n\x11ImmobilizerStatus\x12\x1c\n\x18IMMOBILIZER_NOT_ASSIGNED\x10\x00\x12\x1e\n\x1aIMMOBILIZER_NOT_AUTHORIZED\x10\x01\x12#\n\x1fIMMOBILIZER_AUTHORIZED_TO_DRIVE\x10\x02*y\n\x14LockFailNotification\x12\x1e\n\x1aLOCK_FAIL_NOTIFICATION_SNA\x10\x00\x12\x1f\n\x1bLOCK_FAIL_NOTIFICATION_TRUE\x10\x01\x12 \n\x1cLOCK_FAIL_NOTIFICATION_FALSE\x10\x02*\xfe\x03\n\x16PassiveEntryFailReason\x12\"\n\x1ePASSIVE_ENTRY_FAIL_UNSPECIFIED\x10\x00\x12\x1d\n\x19PASSIVE_ENTRY_NOT_IN_PARK\x10\x01\x12!\n\x1dPASSIVE_ENTRY_AT_HOME_DISABLE\x10\x02\x12#\n\x1fPASSIVE_ENTRY_PASSENGER_IN_SEAT\x10\x03\x12$\n PASSIVE_ENTRY_DEVICE_NOT_ENABLED\x10\x04\x12 \n\x1cPASSIVE_ENTRY_TRANSPORT_MODE\x10\x05\x12\x1f\n\x1bPASSIVE_ENTRY_CAR_WASH_MODE\x10\x06\x12\x1b\n\x17PASSIVE_ENTRY_CAMP_MODE\x10\x07\x12\x1c\n\x18PASSIVE_ENTRY_ACTIVE_OTA\x10\x08\x12$\n PASSIVE_ENTRY_SHOW_AND_TELL_MODE\x10\t\x12#\n\x1fPASSIVE_ENTRY_RCVD_RSSI_PENDING\x10\n\x12#\n\x1fPASSIVE_ENTRY_LOCK_ONLY_AT_HOME\x10\x0b\x12\"\n\x1ePASSIVE_ENTRY_CAR_COSTUME_MODE\x10\x0c\x12!\n\x1dPASSIVE_ENTRY_SLEPT_IMMEDIATE\x10\r*\x9b\x02\n\x14SecureElementFaulted\x12$\n SECURE_ELEMENT_FAULT_UNSPECIFIED\x10\x00\x12\x1d\n\x19SECURE_ELEMENT_NO_FAILURE\x10\x01\x12%\n!SECURE_ELEMENT_LOST_COMMUNICATION\x10\x02\x12(\n$SECURE_ELEMENT_APPLET_NOT_PROGRAMMED\x10\x03\x12!\n\x1dSECURE_ELEMENT_NOT_CONFIGURED\x10\x04\x12!\n\x1dSECURE_ELEMENT_ATTACK_COUNTER\x10\x05\x12\'\n#SECURE_ELEMENT_URSK_DECRYPT_FAILURE\x10\x06*g\n\x10\x41\x63\x63\x65ssCanFaulted\x12 \n\x1c\x41\x43\x43\x45SS_CAN_FAULT_UNSPECIFIED\x10\x00\x12\x19\n\x15\x41\x43\x43\x45SS_CAN_NO_FAILURE\x10\x01\x12\x16\n\x12\x41\x43\x43\x45SS_CAN_FAILURE\x10\x02*|\n\nAlarmSound\x12\x1b\n\x17\x41LARM_SOUND_UNSPECIFIED\x10\x00\x12\x15\n\x11\x41LARM_SOUND_FALSE\x10\x01\x12\x14\n\x10\x41LARM_SOUND_TRUE\x10\x02\x12$\n ALARM_SOUND_SIGNAL_NOT_AVAILABLE\x10\x03*\xb8\x01\n\x15VideoMonitoringStatus\x12\'\n#VIDEO_MONITORING_STATUS_UNSPECIFIED\x10\x00\x12\x1d\n\x19VIDEO_MONITORING_DISABLED\x10\x01\x12\x1c\n\x18VIDEO_MONITORING_ENABLED\x10\x02\x12\x1b\n\x17VIDEO_MONITORING_ACTIVE\x10\x03\x12\x1c\n\x18VIDEO_MONITORING_FAULTED\x10\x04*Z\n\tVideoMode\x12\x13\n\x0fVIDEO_MODE_NONE\x10\x00\x12\x19\n\x15VIDEO_MODE_EVERYWHERE\x10\x01\x12\x1d\n\x19VIDEO_MODE_AWAY_FROM_HOME\x10\x02*W\n\rTosAcceptance\x12\x1e\n\x1aTOS_ACCEPTANCE_UNSPECIFIED\x10\x00\x12\x14\n\x10TOS_NOT_ACCEPTED\x10\x01\x12\x10\n\x0cTOS_ACCEPTED\x10\x02*\xe1\x01\n\x0fGearGuardCamera\x12!\n\x1dGEAR_GUARD_CAMERA_UNSPECIFIED\x10\x00\x12\x1b\n\x17GEAR_GUARD_CAMERA_FRONT\x10\x01\x12\x19\n\x15GEAR_GUARD_CAMERA_BED\x10\x02\x12\x1a\n\x16GEAR_GUARD_CAMERA_LEFT\x10\x03\x12\x1b\n\x17GEAR_GUARD_CAMERA_RIGHT\x10\x04\x12\x1a\n\x16GEAR_GUARD_CAMERA_REAR\x10\x05\x12\x1e\n\x1aGEAR_GUARD_CAMERA_INTERIOR\x10\x06\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'rivian.parallax.proto.security_pb2', _globals) if not _descriptor._USE_C_DESCRIPTORS: DESCRIPTOR._loaded_options = None - _globals['_HARDWAREFAILURE']._serialized_start=1455 - _globals['_HARDWAREFAILURE']._serialized_end=1532 - _globals['_IMMOBILIZERSTATUS']._serialized_start=1534 - _globals['_IMMOBILIZERSTATUS']._serialized_end=1652 - _globals['_LOCKFAILNOTIFICATION']._serialized_start=1654 - _globals['_LOCKFAILNOTIFICATION']._serialized_end=1775 - _globals['_PASSIVEENTRYFAILREASON']._serialized_start=1778 - _globals['_PASSIVEENTRYFAILREASON']._serialized_end=2288 - _globals['_SECUREELEMENTFAULTED']._serialized_start=2291 - _globals['_SECUREELEMENTFAULTED']._serialized_end=2574 - _globals['_ACCESSCANFAULTED']._serialized_start=2576 - _globals['_ACCESSCANFAULTED']._serialized_end=2679 - _globals['_ALARMSOUND']._serialized_start=2681 - _globals['_ALARMSOUND']._serialized_end=2805 - _globals['_VIDEOMONITORINGSTATUS']._serialized_start=2808 - _globals['_VIDEOMONITORINGSTATUS']._serialized_end=2992 - _globals['_VIDEOMODE']._serialized_start=2994 - _globals['_VIDEOMODE']._serialized_end=3084 - _globals['_TOSACCEPTANCE']._serialized_start=3086 - _globals['_TOSACCEPTANCE']._serialized_end=3173 + _globals['_HARDWAREFAILURE']._serialized_start=1557 + _globals['_HARDWAREFAILURE']._serialized_end=1634 + _globals['_IMMOBILIZERSTATUS']._serialized_start=1636 + _globals['_IMMOBILIZERSTATUS']._serialized_end=1754 + _globals['_LOCKFAILNOTIFICATION']._serialized_start=1756 + _globals['_LOCKFAILNOTIFICATION']._serialized_end=1877 + _globals['_PASSIVEENTRYFAILREASON']._serialized_start=1880 + _globals['_PASSIVEENTRYFAILREASON']._serialized_end=2390 + _globals['_SECUREELEMENTFAULTED']._serialized_start=2393 + _globals['_SECUREELEMENTFAULTED']._serialized_end=2676 + _globals['_ACCESSCANFAULTED']._serialized_start=2678 + _globals['_ACCESSCANFAULTED']._serialized_end=2781 + _globals['_ALARMSOUND']._serialized_start=2783 + _globals['_ALARMSOUND']._serialized_end=2907 + _globals['_VIDEOMONITORINGSTATUS']._serialized_start=2910 + _globals['_VIDEOMONITORINGSTATUS']._serialized_end=3094 + _globals['_VIDEOMODE']._serialized_start=3096 + _globals['_VIDEOMODE']._serialized_end=3186 + _globals['_TOSACCEPTANCE']._serialized_start=3188 + _globals['_TOSACCEPTANCE']._serialized_end=3275 + _globals['_GEARGUARDCAMERA']._serialized_start=3278 + _globals['_GEARGUARDCAMERA']._serialized_end=3503 _globals['_PASSIVEENTRY']._serialized_start=66 _globals['_PASSIVEENTRY']._serialized_end=80 _globals['_BTM']._serialized_start=83 @@ -65,4 +67,6 @@ _globals['_ALARMSTATE']._serialized_end=1193 _globals['_VIDEOMONITORINGSTATE']._serialized_start=1196 _globals['_VIDEOMONITORINGSTATE']._serialized_end=1453 + _globals['_LIVESTREAMINGREQUEST']._serialized_start=1455 + _globals['_LIVESTREAMINGREQUEST']._serialized_end=1555 # @@protoc_insertion_point(module_scope) diff --git a/src/rivian/parallax/proto/security_pb2.pyi b/src/rivian/parallax/proto/security_pb2.pyi index 58cc421..e04e8c7 100644 --- a/src/rivian/parallax/proto/security_pb2.pyi +++ b/src/rivian/parallax/proto/security_pb2.pyi @@ -81,6 +81,16 @@ class TosAcceptance(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): TOS_ACCEPTANCE_UNSPECIFIED: _ClassVar[TosAcceptance] TOS_NOT_ACCEPTED: _ClassVar[TosAcceptance] TOS_ACCEPTED: _ClassVar[TosAcceptance] + +class GearGuardCamera(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + GEAR_GUARD_CAMERA_UNSPECIFIED: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_FRONT: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_BED: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_LEFT: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_RIGHT: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_REAR: _ClassVar[GearGuardCamera] + GEAR_GUARD_CAMERA_INTERIOR: _ClassVar[GearGuardCamera] HARDWARE_FAILURE_UNSPECIFIED: HardwareFailure HARDWARE_FAILURE_SET: HardwareFailure IMMOBILIZER_NOT_ASSIGNED: ImmobilizerStatus @@ -128,6 +138,13 @@ VIDEO_MODE_AWAY_FROM_HOME: VideoMode TOS_ACCEPTANCE_UNSPECIFIED: TosAcceptance TOS_NOT_ACCEPTED: TosAcceptance TOS_ACCEPTED: TosAcceptance +GEAR_GUARD_CAMERA_UNSPECIFIED: GearGuardCamera +GEAR_GUARD_CAMERA_FRONT: GearGuardCamera +GEAR_GUARD_CAMERA_BED: GearGuardCamera +GEAR_GUARD_CAMERA_LEFT: GearGuardCamera +GEAR_GUARD_CAMERA_RIGHT: GearGuardCamera +GEAR_GUARD_CAMERA_REAR: GearGuardCamera +GEAR_GUARD_CAMERA_INTERIOR: GearGuardCamera class PassiveEntry(_message.Message): __slots__ = () @@ -196,3 +213,11 @@ class VideoMonitoringState(_message.Message): mode: VideoMode terms_accepted: TosAcceptance def __init__(self, status: _Optional[_Union[VideoMonitoringStatus, str]] = ..., mode: _Optional[_Union[VideoMode, str]] = ..., terms_accepted: _Optional[_Union[TosAcceptance, str]] = ...) -> None: ... + +class LiveStreamingRequest(_message.Message): + __slots__ = ("camera", "device_id") + CAMERA_FIELD_NUMBER: _ClassVar[int] + DEVICE_ID_FIELD_NUMBER: _ClassVar[int] + camera: GearGuardCamera + device_id: str + def __init__(self, camera: _Optional[_Union[GearGuardCamera, str]] = ..., device_id: _Optional[str] = ...) -> None: ... diff --git a/src/rivian/parallax/security.py b/src/rivian/parallax/security.py index bce9291..c0f40fb 100644 --- a/src/rivian/parallax/security.py +++ b/src/rivian/parallax/security.py @@ -7,6 +7,24 @@ from .core import RVMDecoder, _enum, _present from .proto import security_pb2 +START_LIVE_STREAMING_RVM: Final = "security.video_monitoring.start_live_streaming" + +GEAR_GUARD_CAMERAS: Final[dict[str, security_pb2.GearGuardCamera]] = { + "front": security_pb2.GEAR_GUARD_CAMERA_FRONT, + "bed": security_pb2.GEAR_GUARD_CAMERA_BED, + "left": security_pb2.GEAR_GUARD_CAMERA_LEFT, + "right": security_pb2.GEAR_GUARD_CAMERA_RIGHT, + "rear": security_pb2.GEAR_GUARD_CAMERA_REAR, + "interior": security_pb2.GEAR_GUARD_CAMERA_INTERIOR, +} + + +def encode_live_streaming(camera: str, device_id: str) -> bytes: + """Encode a security.video_monitoring.start_live_streaming payload.""" + return security_pb2.LiveStreamingRequest( + camera=GEAR_GUARD_CAMERAS[camera], device_id=device_id + ).SerializeToString() + @RVMDecoder.register("security.access.passive_entry", security_pb2.PassiveEntry) def decode_passive_entry(_m: security_pb2.PassiveEntry) -> dict[str, Any]: diff --git a/src/rivian/rivian.py b/src/rivian/rivian.py index c4854de..a2166f4 100644 --- a/src/rivian/rivian.py +++ b/src/rivian/rivian.py @@ -34,10 +34,13 @@ from .parallax import ( CLIMATE_HOLD_SETTING_RVM, CLIMATE_HOLD_STATUS_RVM, + GEAR_GUARD_CAMERAS, + START_LIVE_STREAMING_RVM, UPDATED_TRIP_MODEL, encode_climate_hold_setting, encode_command, encode_end_trip, + encode_live_streaming, encode_vehicle_operation, ) from .utils import generate_vehicle_command_hmac, send_deprecation_warning @@ -789,6 +792,81 @@ async def end_trip(self, vehicle_id: str, user_id: str) -> bool: ) return False + async def start_gear_guard_live_stream( + self, + vehicle_id: str, + camera: str = "front", + *, + identity_id: str, + vehicle_key: str, + private_key: str, + device_id: str = "rivian-python-client", + timeout: float = 40, + ) -> dict[str, Any] | None: + """Start a Gear Guard live stream and return its Kinesis WebRTC config. + + `camera` is a `parallax.GEAR_GUARD_CAMERAS` key. Needs Gear Guard video + monitoring on and a paired phone; the vehicle serves one viewer at a time, + about 3 minutes each and an hour a day. None if the start fails or no config + arrives within `timeout` seconds (a sleeping vehicle may need longer). + Raises RivianApiException if the vehicle refuses the stream, e.g. for a + camera it doesn't have. + """ + if camera not in GEAR_GUARD_CAMERAS: + raise RivianBadRequestError(f"Unknown camera: {camera}") + command_id = str(uuid.uuid4()) + config: asyncio.Future[dict[str, Any]] = ( + asyncio.get_running_loop().create_future() + ) + + def on_message(message: dict[str, Any]) -> None: + data = (message.get("payload") or {}).get("data") or {} + live = data.get("gearGuardLiveConfig") or {} + if live.get("endpoint") and not config.done(): + config.set_result(live) + + def on_error(message: dict[str, Any]) -> None: + errors = message.get("payload") or [{}] + reason = (errors[0].get("extensions") or {}).get("reason") + if not config.done(): + config.set_exception( + RivianApiException(f"The vehicle refused the stream: {reason}") + ) + + # The cloud sends the config to the subscription whose commandId is the + # start command's id, as hex + unsubscribe = await self._start_subscription( + { + "operationName": "GearGuardLiveConfigSubscription", + "query": "subscription GearGuardLiveConfigSubscription($vehicleId: String!, $commandId: String!) { gearGuardLiveConfig(vehicleId: $vehicleId, commandId: $commandId) { __typename endpoint channelArn role iceServers { __typename url username credential ttl } } }", + "variables": { + "vehicleId": vehicle_id, + "commandId": uuid.UUID(command_id).hex, + }, + }, + on_message, + f"{vehicle_id} Gear Guard live config", + on_error, + ) + if not unsubscribe: + return None + try: + if not await self.send_parallax_command( + vehicle_id, + START_LIVE_STREAMING_RVM, + encode_live_streaming(camera, device_id), + identity_id=identity_id, + vehicle_key=vehicle_key, + private_key=private_key, + command_id=command_id, + ): + return None + return await asyncio.wait_for(config, timeout) + except TimeoutError: + return None + finally: + await unsubscribe() + async def get_vehicle_ota_update_details(self, vehicle_id: str) -> ClientResponse: """Get vehicle OTA update details.""" url = GRAPHQL_GATEWAY diff --git a/tests/parallax/test_security.py b/tests/parallax/test_security.py index 1864196..7c5189d 100644 --- a/tests/parallax/test_security.py +++ b/tests/parallax/test_security.py @@ -2,6 +2,7 @@ from __future__ import annotations +from rivian.parallax import encode_live_streaming from rivian.parallax.proto import security_pb2 as security from .helpers import decode @@ -35,3 +36,12 @@ def test_alarm_state() -> None: "alarmSoundStatus": "false", "consecutiveAlarmDisabledNotification": True, } + + +def test_encode_live_streaming() -> None: + """A live stream start names the camera and the viewer's device id.""" + request = security.LiveStreamingRequest.FromString( + encode_live_streaming("rear", "viewer") + ) + assert request.camera == security.GEAR_GUARD_CAMERA_REAR + assert request.device_id == "viewer" diff --git a/tests/test_rivian.py b/tests/test_rivian.py index d72c83f..0bdccbb 100644 --- a/tests/test_rivian.py +++ b/tests/test_rivian.py @@ -495,6 +495,65 @@ async def test_trips(aresponses: ResponsesMockServer) -> None: assert not await rivian.end_trip("vehicle_id", "user") +async def test_start_gear_guard_live_stream(aresponses: ResponsesMockServer) -> None: + """Test starting a Gear Guard live stream.""" + requests = capture_requests( + aresponses, + SEND_PARALLAX_COMMAND_RESPONSE, + {"data": {"sendParallaxPayload": None}}, + SEND_PARALLAX_COMMAND_RESPONSE, + ) + vehicle_key, private_key = generate_key_pair() + keys = { + "identity_id": "identity_id", + "vehicle_key": vehicle_key, + "private_key": private_key, + } + live = {"endpoint": "wss://kinesis", "role": "VIEWER", "iceServers": []} + async with aiohttp.ClientSession(): + rivian = Rivian( + csrf_token="csrf", + app_session_token="token", + user_session_token="token", + ) + subscriptions: list[dict[str, Any]] = [] + unsubscribe = AsyncMock() + + async def subscribe( + payload: dict[str, Any], callback: Any, _: str, on_error: Any + ) -> Any: + subscriptions.append(payload) + callback({"payload": {"data": {"gearGuardLiveConfig": live}}}) + return unsubscribe + + rivian._start_subscription = subscribe # type: ignore[method-assign] + config = await rivian.start_gear_guard_live_stream("vehicle_id", "rear", **keys) + assert config == live + _, operation = decode_parallax_command(requests[0]) + assert operation.rvm == "security.video_monitoring.start_live_streaming" + # The config is routed by the start command's id + assert subscriptions[0]["variables"]["commandId"] == operation.command_id.hex() + + # A rejected start returns None and still ends the subscription + assert not await rivian.start_gear_guard_live_stream("vehicle_id", **keys) + assert unsubscribe.await_count == 2 + with pytest.raises(RivianBadRequestError): + await rivian.start_gear_guard_live_stream("vehicle_id", "roof", **keys) + + # A refused start fails straight away instead of timing out + async def refuse( + payload: dict[str, Any], callback: Any, _: str, on_error: Any + ) -> Any: + on_error( + {"payload": [{"extensions": {"reason": "VEHICLE_COMMAND_FORBIDDEN"}}]} + ) + return unsubscribe + + rivian._start_subscription = refuse # type: ignore[method-assign] + with pytest.raises(RivianApiException, match="VEHICLE_COMMAND_FORBIDDEN"): + await rivian.start_gear_guard_live_stream("vehicle_id", timeout=30, **keys) + + async def test_subscribe_for_departure_schedules() -> None: """Test subscribing to departure schedules.""" rivian = Rivian(user_session_token="token") From 9124f99840e6a7e4394d28443727e3de8694224e Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Sun, 15 Nov 2026 18:33:00 +0000 Subject: [PATCH 4/6] Read a Gear Guard refusal on early returns and take any error shape A refusal that reached the future before the start command was rejected was never read, so asyncio logged "Future exception was never retrieved"; it is now read before returning. The error handler also takes a `payload` sent as an object, not only as a list, so it still fails the start instead of raising in the callback. --- src/rivian/rivian.py | 8 ++++++-- tests/test_rivian.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/rivian/rivian.py b/src/rivian/rivian.py index a2166f4..dc1b05e 100644 --- a/src/rivian/rivian.py +++ b/src/rivian/rivian.py @@ -826,8 +826,9 @@ def on_message(message: dict[str, Any]) -> None: config.set_result(live) def on_error(message: dict[str, Any]) -> None: - errors = message.get("payload") or [{}] - reason = (errors[0].get("extensions") or {}).get("reason") + payload = message.get("payload") or [{}] + error = (payload if isinstance(payload, list) else [payload])[0] + reason = (error.get("extensions") or {}).get("reason") if not config.done(): config.set_exception( RivianApiException(f"The vehicle refused the stream: {reason}") @@ -866,6 +867,9 @@ def on_error(message: dict[str, Any]) -> None: return None finally: await unsubscribe() + # Read a refusal left on the future by an early return, or asyncio logs it + if config.done() and not config.cancelled(): + config.exception() async def get_vehicle_ota_update_details(self, vehicle_id: str) -> ClientResponse: """Get vehicle OTA update details.""" diff --git a/tests/test_rivian.py b/tests/test_rivian.py index 0bdccbb..83e512b 100644 --- a/tests/test_rivian.py +++ b/tests/test_rivian.py @@ -3,7 +3,9 @@ # pylint: disable=protected-access from __future__ import annotations +import asyncio import base64 +import gc import json import uuid from datetime import UTC, date, datetime @@ -502,6 +504,8 @@ async def test_start_gear_guard_live_stream(aresponses: ResponsesMockServer) -> SEND_PARALLAX_COMMAND_RESPONSE, {"data": {"sendParallaxPayload": None}}, SEND_PARALLAX_COMMAND_RESPONSE, + SEND_PARALLAX_COMMAND_RESPONSE, + {"data": {"sendParallaxPayload": None}}, ) vehicle_key, private_key = generate_key_pair() keys = { @@ -553,6 +557,29 @@ async def refuse( with pytest.raises(RivianApiException, match="VEHICLE_COMMAND_FORBIDDEN"): await rivian.start_gear_guard_live_stream("vehicle_id", timeout=30, **keys) + # An error payload sent as an object instead of a list still fails the start + async def refuse_object( + payload: dict[str, Any], callback: Any, _: str, on_error: Any + ) -> Any: + on_error({"payload": {"extensions": {"reason": "VEHICLE_ASLEEP"}}}) + return unsubscribe + + rivian._start_subscription = refuse_object # type: ignore[method-assign] + with pytest.raises(RivianApiException, match="VEHICLE_ASLEEP"): + await rivian.start_gear_guard_live_stream("vehicle_id", timeout=30, **keys) + + # A refusal before a rejected start is read, so asyncio doesn't log it + loop = asyncio.get_running_loop() + unread: list[dict[str, Any]] = [] + loop.set_exception_handler(lambda _, context: unread.append(context)) + try: + rivian._start_subscription = refuse # type: ignore[method-assign] + assert not await rivian.start_gear_guard_live_stream("vehicle_id", **keys) + gc.collect() + finally: + loop.set_exception_handler(None) + assert not unread + async def test_subscribe_for_departure_schedules() -> None: """Test subscribing to departure schedules.""" From 05a5b2ebbe2bc81377849875b4a4383acb154ecc Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Tue, 10 Nov 2026 04:55:09 +0000 Subject: [PATCH 5/6] Add searching for places - `search_places` searches like the Rivian app's map search (its `places` query): results with a Google place id, name, address, coordinates and the driving distance and time from where you search. - `suggest_places` returns the app's suggested search texts for partial text (the same query with autocomplete), such as "restaurants" and "Red Lobster" for "RE", for type-ahead in front of `search_places`. - `utils.place_url` builds the Rivian app's link for a result, which `send_location_to_vehicle` sends so the vehicle shows the place's name. None of them needs a paired phone key. Tested against the API: a search returned Google's results in under a second, in their own order rather than nearest first, and suggestions came back in about a tenth of a second. `maxResults` was ignored, so it is left out. --- src/rivian/rivian.py | 61 ++++++++++++++++++++++++++++++++++++++++++++ src/rivian/utils.py | 28 ++++++++++++++++++++ tests/responses.py | 19 ++++++++++++++ tests/test_rivian.py | 44 ++++++++++++++++++++++++++++++++ tests/test_utils.py | 9 +++++++ 5 files changed, 161 insertions(+) diff --git a/src/rivian/rivian.py b/src/rivian/rivian.py index dc1b05e..1501f04 100644 --- a/src/rivian/rivian.py +++ b/src/rivian/rivian.py @@ -666,6 +666,67 @@ async def depart_now( } return await self.__graphql_query(headers, url, graphql_json) + async def search_places( + self, query: str, latitude: float, longitude: float + ) -> list[dict[str, Any]]: + """Search for places like the Rivian app's map search. + + Results come in the search's own order, each with a Google place `id`, + `name`, `location` and the `driveDetails` from `latitude`, `longitude`. + """ + url = GRAPHQL_GATEWAY + headers = BASE_HEADERS | { + "Csrf-Token": self._csrf_token, + "A-Sess": self._app_session_token, + "U-Sess": self._user_session_token, + } + graphql_json = { + "operationName": "places", + "query": "query places($params: PlacesQueryParams!) { places(params: $params) { results { id name location { formattedAddress coordinate { latitude longitude } navCoordinate { latitude longitude } } driveDetails { driveDistance driveDuration } } } }", + "variables": { + "params": { + "query": query, + "userLocation": {"latitude": latitude, "longitude": longitude}, + "autocomplete": "None", + } + }, + } + + response = await self.__graphql_query(headers, url, graphql_json) + if response.status == 200: + data = await response.json() + return (data.get("data", {}).get("places") or {}).get("results") or [] + return [] + + async def suggest_places( + self, query: str, latitude: float, longitude: float + ) -> list[str]: + """Suggest search texts for partial text, for type-ahead in a place search.""" + url = GRAPHQL_GATEWAY + headers = BASE_HEADERS | { + "Csrf-Token": self._csrf_token, + "A-Sess": self._app_session_token, + "U-Sess": self._user_session_token, + } + graphql_json = { + "operationName": "places", + "query": "query places($params: PlacesQueryParams!) { places(params: $params) { queryPredictions { query } } }", + "variables": { + "params": { + "query": query, + "userLocation": {"latitude": latitude, "longitude": longitude}, + "autocomplete": "Place", + } + }, + } + + response = await self.__graphql_query(headers, url, graphql_json) + if response.status == 200: + data = await response.json() + places = data.get("data", {}).get("places") or {} + return [p["query"] for p in places.get("queryPredictions") or []] + return [] + async def send_location_to_vehicle( self, vehicle_id: str, location: str ) -> ClientResponse: diff --git a/src/rivian/utils.py b/src/rivian/utils.py index 1bfff46..d94ac55 100644 --- a/src/rivian/utils.py +++ b/src/rivian/utils.py @@ -8,6 +8,7 @@ from base64 import b64decode, b64encode from datetime import UTC, datetime from typing import cast +from urllib.parse import urlencode from warnings import warn from cryptography.hazmat.primitives import hashes, serialization @@ -143,3 +144,30 @@ def from_epoch(epoch: float) -> datetime: if abs(epoch) >= _MS_THRESHOLD: epoch /= 1000 return datetime.fromtimestamp(epoch, UTC) + + +def place_url( + place_id: str, + name: str, + latitude: float, + longitude: float, + address: str | None = None, +) -> str: + """Return the Rivian app's link for a place, for `send_location_to_vehicle`. + + The vehicle shows the place's name. `place_id` is a Google place id, such as a + `search_places` result's `id`; Rivian refuses these links without one. Use the + result's `navCoordinate`, where the drive ends. + """ + coordinates = f"{latitude},{longitude}" + query = { + "geo_coordinates": coordinates, + "entity_id": place_id, + "name": name, + "nav_coordinates": coordinates, + "address": address, + "source_type": "telenav", + } + return "https://telenav.id/entity?" + urlencode( + {k: v for k, v in query.items() if v is not None} + ) diff --git a/tests/responses.py b/tests/responses.py index 53e98e9..c885a93 100644 --- a/tests/responses.py +++ b/tests/responses.py @@ -654,6 +654,25 @@ "data": {"sendParallaxPayload": {"success": True, "sequenceNumber": 0}} } +PLACES_RESPONSE = { + "data": { + "places": { + "results": [ + { + "id": "place_id", + "name": "REI", + "location": { + "formattedAddress": "5901 Mills Civic Pkwy, West Des Moines, IA", + "coordinate": {"latitude": 41.56028, "longitude": -93.78724}, + "navCoordinate": {"latitude": 41.56001, "longitude": -93.7873}, + }, + "driveDetails": {"driveDistance": 239062, "driveDuration": 9960}, + } + ] + } + } +} + SEND_VEHICLE_OPERATION_RESPONSE = { "data": { "sendVehicleOperation": { diff --git a/tests/test_rivian.py b/tests/test_rivian.py index 83e512b..003e255 100644 --- a/tests/test_rivian.py +++ b/tests/test_rivian.py @@ -45,6 +45,7 @@ DELETE_DEPARTURE_SCHEDULE_RESPONSE, DEPART_NOW_RESPONSE, OTP_TOKEN_RESPONSE, + PLACES_RESPONSE, SEND_LOCATION_TO_VEHICLE_RESPONSE, SEND_PARALLAX_COMMAND_RESPONSE, SEND_VEHICLE_OPERATION_RESPONSE, @@ -581,6 +582,49 @@ async def refuse_object( assert not unread +async def test_search_places(aresponses: ResponsesMockServer) -> None: + """Test searching for places.""" + requests = capture_requests(aresponses, PLACES_RESPONSE, {"data": {"places": None}}) + async with aiohttp.ClientSession(): + rivian = Rivian( + csrf_token="csrf", + app_session_token="token", + user_session_token="token", + ) + + results = await rivian.search_places("REI", 40.175, -92.591) + assert results == PLACES_RESPONSE["data"]["places"]["results"] + assert requests[0]["variables"]["params"] == { + "query": "REI", + "userLocation": {"latitude": 40.175, "longitude": -92.591}, + "autocomplete": "None", + } + assert await rivian.search_places("REI", 40.175, -92.591) == [] + + +async def test_suggest_places(aresponses: ResponsesMockServer) -> None: + """Test suggesting search texts for partial text.""" + predictions = [{"query": "restaurants"}, {"query": "Red Lobster"}] + requests = capture_requests( + aresponses, + {"data": {"places": {"queryPredictions": predictions}}}, + {"data": {"places": None}}, + ) + async with aiohttp.ClientSession(): + rivian = Rivian( + csrf_token="csrf", + app_session_token="token", + user_session_token="token", + ) + + assert await rivian.suggest_places("RE", 40.175, -92.591) == [ + "restaurants", + "Red Lobster", + ] + assert requests[0]["variables"]["params"]["autocomplete"] == "Place" + assert await rivian.suggest_places("RE", 40.175, -92.591) == [] + + async def test_subscribe_for_departure_schedules() -> None: """Test subscribing to departure schedules.""" rivian = Rivian(user_session_token="token") diff --git a/tests/test_utils.py b/tests/test_utils.py index 06fdf4b..0f32d75 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -48,3 +48,12 @@ def test_generate_vehicle_command_hmac() -> None: command, timestamp, VEHICLE_KEY, PRIVATE_KEY ) assert hmac == "2a68bdda69ff8643e37bac595905f6a481435e00bb63bdd415ecbb425a5bb598" + + +def test_place_url() -> None: + """A place link carries the place's name, id, address and coordinates.""" + assert utils.place_url("place_id", "REI", 41.5, -93.7, "1 Main St") == ( + "https://telenav.id/entity?geo_coordinates=41.5%2C-93.7&entity_id=place_id" + "&name=REI&nav_coordinates=41.5%2C-93.7&address=1+Main+St&source_type=telenav" + ) + assert "address" not in utils.place_url("place_id", "REI", 41.5, -93.7) From 5a924ddb600fd9376925a4752576db7d85ce13d7 Mon Sep 17 00:00:00 2001 From: Walt Howd Date: Sun, 8 Nov 2026 02:21:35 +0000 Subject: [PATCH 6/6] Add climate hold and pet mode commands Encoders for the payloads of the signed `comfort.cabin.set_climate_hold` and `comfort.cabin.set_pet_mode` commands, both a single on/off action as in the Rivian app: await rivian.send_parallax_command( vehicle_id, SET_PET_MODE_RVM, encode_pet_mode(True), ... ) Verified against a 2026 R1S (Gen 2) running 2026.36.01: pet mode on/off and climate hold on/off each reported the new state within seconds. The pet mode payloads match the app's (captured with mitmproxy); the app's climate hold control only sets the duration (`set_climate_hold_duration`), so that payload comes from the app's code. Not tested: Gen 1 vehicles, the R1T and R2. --- src/rivian/parallax/__init__.py | 11 ++++ src/rivian/parallax/comfort.py | 14 ++++ src/rivian/parallax/proto/comfort.proto | 12 ++++ src/rivian/parallax/proto/comfort_pb2.py | 78 ++++++++++++----------- src/rivian/parallax/proto/comfort_pb2.pyi | 15 +++++ tests/parallax/test_comfort.py | 13 +++- 6 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/rivian/parallax/__init__.py b/src/rivian/parallax/__init__.py index b1cdeb4..1d28390 100644 --- a/src/rivian/parallax/__init__.py +++ b/src/rivian/parallax/__init__.py @@ -21,6 +21,9 @@ Builds the unsigned `end_trip` request. encode_live_streaming(camera, device_id) -> bytes A Gear Guard live stream start, for `start_gear_guard_live_stream`. + encode_climate_hold(on), encode_pet_mode(on) -> bytes + Payloads for the signed SET_CLIMATE_HOLD_RVM and SET_PET_MODE_RVM + commands. Layout: core.py - registry, payload parsing and shared helpers @@ -60,7 +63,11 @@ from .comfort import ( CLIMATE_HOLD_SETTING_RVM, CLIMATE_HOLD_STATUS_RVM, + SET_CLIMATE_HOLD_RVM, + SET_PET_MODE_RVM, + encode_climate_hold, encode_climate_hold_setting, + encode_pet_mode, ) from .command import decode_command_state_message, encode_command from .core import ( @@ -98,17 +105,21 @@ "GEAR_GUARD_CAMERAS", "LOCK_RVM", "PARALLAX_RVMS", + "SET_CLIMATE_HOLD_RVM", + "SET_PET_MODE_RVM", "START_LIVE_STREAMING_RVM", "UNLOCK_RVM", "UPDATED_TRIP_MODEL", "decode_command_state_message", "decode_parallax_message", "decode_parallax_subscription_message", + "encode_climate_hold", "encode_climate_hold_setting", "encode_command", "encode_end_trip", "encode_live_streaming", "encode_lock", + "encode_pet_mode", "encode_unlock", "encode_vehicle_operation", ] diff --git a/src/rivian/parallax/comfort.py b/src/rivian/parallax/comfort.py index 279613d..da6f64f 100644 --- a/src/rivian/parallax/comfort.py +++ b/src/rivian/parallax/comfort.py @@ -9,6 +9,8 @@ CLIMATE_HOLD_SETTING_RVM: Final = "comfort.cabin.climate_hold_setting" CLIMATE_HOLD_STATUS_RVM: Final = "comfort.cabin.climate_hold_status" +SET_CLIMATE_HOLD_RVM: Final = "comfort.cabin.set_climate_hold" +SET_PET_MODE_RVM: Final = "comfort.cabin.set_pet_mode" @RVMDecoder.register( @@ -208,6 +210,18 @@ def encode_climate_hold_setting(duration_seconds: int) -> bytes: return comfort_pb2.ClimateHoldSetting(duration=duration_seconds).SerializeToString() +def encode_climate_hold(on: bool) -> bytes: + """Encode a comfort.cabin.set_climate_hold payload.""" + action = comfort_pb2.ACTION_ON if on else comfort_pb2.ACTION_OFF + return comfort_pb2.ActionRequest(action=action).SerializeToString() + + +def encode_pet_mode(on: bool) -> bytes: + """Encode a comfort.cabin.set_pet_mode payload.""" + action = comfort_pb2.ACTION_ON if on else comfort_pb2.ACTION_OFF + return comfort_pb2.ActionRequest(action=action).SerializeToString() + + @RVMDecoder.register(CLIMATE_HOLD_SETTING_RVM, comfort_pb2.ClimateHoldSetting) def decode_climate_hold_setting(m: comfort_pb2.ClimateHoldSetting) -> dict[str, Any]: """comfort.cabin.climate_hold_setting — configured climate-hold duration. diff --git a/src/rivian/parallax/proto/comfort.proto b/src/rivian/parallax/proto/comfort.proto index 3f022f2..385ce24 100644 --- a/src/rivian/parallax/proto/comfort.proto +++ b/src/rivian/parallax/proto/comfort.proto @@ -74,6 +74,18 @@ message ClimateHoldSetting { int32 duration = 1; // seconds; empty payload when no hold is set } +// comfort.cabin.set_climate_hold and comfort.cabin.set_pet_mode; the names +// are the app's +message ActionRequest { + Action action = 1; +} + +enum Action { + ACTION_UNSPECIFIED = 0; + ACTION_ON = 1; + ACTION_OFF = 2; +} + // comfort.cabin.climate_hold_status message ClimateHoldStatus { ClimateHoldStatusValue status = 1; diff --git a/src/rivian/parallax/proto/comfort_pb2.py b/src/rivian/parallax/proto/comfort_pb2.py index d46df2b..423b48d 100644 --- a/src/rivian/parallax/proto/comfort_pb2.py +++ b/src/rivian/parallax/proto/comfort_pb2.py @@ -24,37 +24,39 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n#rivian/parallax/proto/comfort.proto\x12\x17rivian.parallax.comfort\"0\n\x12HvacSettingsStatus\x12\x1a\n\x12target_temperature\x18\x01 \x01(\x02\"\xa4\x01\n\x0eUserModesState\x12\x12\n\nin_service\x18\x01 \x01(\x08\x12\x15\n\rcar_wash_mode\x18\x02 \x01(\x08\x12\x10\n\x08pet_mode\x18\x03 \x01(\x05\x12\x11\n\tcamp_mode\x18\x04 \x01(\x05\x12\x16\n\x0etransport_mode\x18\x05 \x01(\x05\x12\x14\n\x0c\x63limate_keep\x18\x06 \x01(\x05\x12\x14\n\x0c\x66\x61\x63tory_mode\x18\x07 \x01(\x05\"\x98\x01\n\x1a\x43\x61\x62inPreconditioningStatus\x12>\n\x06status\x18\x01 \x01(\x0e\x32..rivian.parallax.comfort.PreconditioningStatus\x12:\n\x04type\x18\x02 \x01(\x0e\x32,.rivian.parallax.comfort.PreconditioningType\"\xa9\x02\n\x11\x43\x61\x62inTemperatures\x12P\n\x0ctemperatures\x18\x01 \x03(\x0b\x32:.rivian.parallax.comfort.CabinTemperatures.ZoneTemperature\x12!\n\x14\x65xterior_temperature\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12\x1c\n\x14interior_temperature\x18\x03 \x01(\x02\x12\x1d\n\x10\x64river_set_point\x18\x04 \x01(\x02H\x01\x88\x01\x01\x1a\x34\n\x0fZoneTemperature\x12\x0c\n\x04seat\x18\x01 \x01(\x05\x12\x13\n\x0btemperature\x18\x02 \x01(\x02\x42\x17\n\x15_exterior_temperatureB\x13\n\x11_driver_set_point\"A\n\x17\x43\x61\x62inVentilationSetting\x12&\n\x1e\x61uto_cabin_ventilation_enabled\x18\x01 \x01(\x08\"&\n\x12\x43limateHoldSetting\x12\x10\n\x08\x64uration\x18\x01 \x01(\x05\"\xd7\x02\n\x11\x43limateHoldStatus\x12?\n\x06status\x18\x01 \x01(\x0e\x32/.rivian.parallax.comfort.ClimateHoldStatusValue\x12\x46\n\x0c\x61vailability\x18\x02 \x01(\x0e\x32\x30.rivian.parallax.comfort.ClimateHoldAvailability\x12W\n\x15unavailability_reason\x18\x03 \x01(\x0e\x32\x38.rivian.parallax.comfort.ClimateHoldUnavailabilityReason\x12\x44\n\x08\x65nd_time\x18\x04 \x01(\x0b\x32\x32.rivian.parallax.comfort.ClimateHoldStatus.EndTime\x1a\x1a\n\x07\x45ndTime\x12\x0f\n\x07seconds\x18\x01 \x01(\x03\"L\n\x12\x44\x65\x66rostDefogStatus\x12\x36\n\x06status\x18\x01 \x01(\x0e\x32&.rivian.parallax.comfort.DefrostStatus\"\xda\x01\n\rPetModeStatus\x12\x35\n\x06status\x18\x01 \x01(\x0e\x32%.rivian.parallax.comfort.PetModeState\x12M\n\x12temperature_status\x18\x02 \x01(\x0e\x32\x31.rivian.parallax.comfort.PetModeTemperatureStatus\x12\x43\n\rcabin_climate\x18\x03 \x01(\x0e\x32,.rivian.parallax.comfort.PetModeCabinClimate\"\xa4\x02\n\x16SeatConditioningStatus\x12H\n\x07surface\x18\x01 \x03(\x0b\x32\x37.rivian.parallax.comfort.SeatConditioningStatus.Surface\x1a\xbf\x01\n\x07Surface\x12\x31\n\x02id\x18\x01 \x01(\x0e\x32%.rivian.parallax.comfort.CabinSurface\x12\x37\n\x04type\x18\x02 \x01(\x0e\x32).rivian.parallax.comfort.ConditioningType\x12>\n\x05state\x18\x03 \x01(\x0e\x32*.rivian.parallax.comfort.ConditioningLevelH\x00\x88\x01\x01\x42\x08\n\x06_state*\x85\x03\n\x15PreconditioningStatus\x12&\n\"PRECONDITIONING_STATUS_UNSPECIFIED\x10\x00\x12\x1c\n\x18PRECONDITIONING_INITIATE\x10\x01\x12\x1a\n\x16PRECONDITIONING_ACTIVE\x10\x02\x12\"\n\x1ePRECONDITIONING_ACTIVE_WARNING\x10\x03\x12%\n!PRECONDITIONING_COMPLETE_MAINTAIN\x10\x04\x12-\n)PRECONDITIONING_TIMEOUT_TEMP_NOT_ACHIEVED\x10\x05\x12!\n\x1dPRECONDITIONING_ERROR_SOC_LOW\x10\x06\x12&\n\"PRECONDITIONING_ERROR_SYSTEM_FAULT\x10\x07\x12\x1f\n\x1bPRECONDITIONING_UNAVAILABLE\x10\x08\x12$\n PRECONDITIONING_TIMEOUT_COMPLETE\x10\t*\xe4\x01\n\x13PreconditioningType\x12$\n PRECONDITIONING_TYPE_UNSPECIFIED\x10\x00\x12&\n\"PRECONDITIONING_TYPE_USER_SELECTED\x10\x01\x12*\n&PRECONDITIONING_TYPE_SCREEN_PROTECTION\x10\x02\x12\"\n\x1ePRECONDITIONING_TYPE_SCHEDULED\x10\x03\x12/\n+PRECONDITIONING_TYPE_AUTO_CABIN_VENTILATION\x10\x04*\xba\x01\n\x16\x43limateHoldStatusValue\x12#\n\x1f\x43LIMATE_HOLD_STATUS_UNSPECIFIED\x10\x00\x12#\n\x1f\x43LIMATE_HOLD_STATUS_UNAVAILABLE\x10\x01\x12\x1b\n\x17\x43LIMATE_HOLD_STATUS_OFF\x10\x02\x12\x1a\n\x16\x43LIMATE_HOLD_STATUS_ON\x10\x03\x12\x1d\n\x19\x43LIMATE_HOLD_STATUS_FAULT\x10\x04*\x9d\x01\n\x17\x43limateHoldAvailability\x12)\n%CLIMATE_HOLD_AVAILABILITY_UNSPECIFIED\x10\x00\x12\x1a\n\x16\x43LIMATE_HOLD_AVAILABLE\x10\x01\x12\x1d\n\x19\x43LIMATE_HOLD_CONTROLLABLE\x10\x02\x12\x1c\n\x18\x43LIMATE_HOLD_UNAVAILABLE\x10\x03*\xc7\x01\n\x1f\x43limateHoldUnavailabilityReason\x12+\n\'CLIMATE_HOLD_UNAVAILABILITY_UNSPECIFIED\x10\x00\x12\'\n#CLIMATE_HOLD_UNAVAILABILITY_UNKNOWN\x10\x01\x12\'\n#CLIMATE_HOLD_UNAVAILABILITY_LOW_SOC\x10\x02\x12%\n!CLIMATE_HOLD_UNAVAILABILITY_FAULT\x10\x03*\x82\x01\n\rDefrostStatus\x12\x1e\n\x1a\x44\x45\x46ROST_STATUS_UNSPECIFIED\x10\x00\x12\x11\n\rDEFROST_DEFOG\x10\x01\x12\x12\n\x0e\x44\x45\x46ROST_ACTIVE\x10\x02\x12\x19\n\x15\x44\x45\x46ROST_DEFOG_DEFROST\x10\x03\x12\x0f\n\x0b\x44\x45\x46ROST_OFF\x10\x04*~\n\x13PetModeCabinClimate\x12&\n\"PET_MODE_CABIN_CLIMATE_COMFORTABLE\x10\x00\x12\x1f\n\x1bPET_MODE_CABIN_CLIMATE_COLD\x10\x01\x12\x1e\n\x1aPET_MODE_CABIN_CLIMATE_HOT\x10\x02*]\n\x0cPetModeState\x12\x10\n\x0cPET_MODE_OFF\x10\x00\x12\x0f\n\x0bPET_MODE_ON\x10\x01\x12\x15\n\x11PET_MODE_DISABLED\x10\x02\x12\x13\n\x0fPET_MODE_FAULTY\x10\x03*\x9a\x01\n\x18PetModeTemperatureStatus\x12 \n\x1cPET_MODE_TEMPERATURE_DEFAULT\x10\x00\x12\x1d\n\x19PET_MODE_TEMPERATURE_COLD\x10\x01\x12\x1c\n\x18PET_MODE_TEMPERATURE_HOT\x10\x02\x12\x1f\n\x1bPET_MODE_TEMPERATURE_FAULTY\x10\x03*\xce\x02\n\x0c\x43\x61\x62inSurface\x12\x1d\n\x19\x43\x41\x42IN_SURFACE_UNSPECIFIED\x10\x00\x12\x12\n\x0eSTEERING_WHEEL\x10\x01\x12\x0e\n\nREAR_GLASS\x10\x02\x12\x0f\n\x0b\x46RONT_GLASS\x10\x03\x12\x14\n\x10SIDEVIEW_MIRRORS\x10\x04\x12\x13\n\x0fSEAT_ROW_1_LEFT\x10\x05\x12\x15\n\x11SEAT_ROW_1_MIDDLE\x10\x06\x12\x14\n\x10SEAT_ROW_1_RIGHT\x10\x07\x12\x13\n\x0fSEAT_ROW_2_LEFT\x10\x08\x12\x15\n\x11SEAT_ROW_2_MIDDLE\x10\t\x12\x14\n\x10SEAT_ROW_2_RIGHT\x10\n\x12\x13\n\x0fSEAT_ROW_3_LEFT\x10\x0b\x12\x15\n\x11SEAT_ROW_3_MIDDLE\x10\x0c\x12\x14\n\x10SEAT_ROW_3_RIGHT\x10\r\x12\x0e\n\nWIPER_AREA\x10\x0e*c\n\x10\x43onditioningType\x12!\n\x1d\x43ONDITIONING_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x43ONDITIONING_HEAT\x10\x01\x12\x15\n\x11\x43ONDITIONING_VENT\x10\x02*\x85\x01\n\x11\x43onditioningLevel\x12\"\n\x1e\x43ONDITIONING_LEVEL_UNSPECIFIED\x10\x00\x12\x18\n\x14\x43ONDITIONING_LEVEL_1\x10\x01\x12\x18\n\x14\x43ONDITIONING_LEVEL_2\x10\x02\x12\x18\n\x14\x43ONDITIONING_LEVEL_3\x10\x03\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n#rivian/parallax/proto/comfort.proto\x12\x17rivian.parallax.comfort\"0\n\x12HvacSettingsStatus\x12\x1a\n\x12target_temperature\x18\x01 \x01(\x02\"\xa4\x01\n\x0eUserModesState\x12\x12\n\nin_service\x18\x01 \x01(\x08\x12\x15\n\rcar_wash_mode\x18\x02 \x01(\x08\x12\x10\n\x08pet_mode\x18\x03 \x01(\x05\x12\x11\n\tcamp_mode\x18\x04 \x01(\x05\x12\x16\n\x0etransport_mode\x18\x05 \x01(\x05\x12\x14\n\x0c\x63limate_keep\x18\x06 \x01(\x05\x12\x14\n\x0c\x66\x61\x63tory_mode\x18\x07 \x01(\x05\"\x98\x01\n\x1a\x43\x61\x62inPreconditioningStatus\x12>\n\x06status\x18\x01 \x01(\x0e\x32..rivian.parallax.comfort.PreconditioningStatus\x12:\n\x04type\x18\x02 \x01(\x0e\x32,.rivian.parallax.comfort.PreconditioningType\"\xa9\x02\n\x11\x43\x61\x62inTemperatures\x12P\n\x0ctemperatures\x18\x01 \x03(\x0b\x32:.rivian.parallax.comfort.CabinTemperatures.ZoneTemperature\x12!\n\x14\x65xterior_temperature\x18\x02 \x01(\x02H\x00\x88\x01\x01\x12\x1c\n\x14interior_temperature\x18\x03 \x01(\x02\x12\x1d\n\x10\x64river_set_point\x18\x04 \x01(\x02H\x01\x88\x01\x01\x1a\x34\n\x0fZoneTemperature\x12\x0c\n\x04seat\x18\x01 \x01(\x05\x12\x13\n\x0btemperature\x18\x02 \x01(\x02\x42\x17\n\x15_exterior_temperatureB\x13\n\x11_driver_set_point\"A\n\x17\x43\x61\x62inVentilationSetting\x12&\n\x1e\x61uto_cabin_ventilation_enabled\x18\x01 \x01(\x08\"&\n\x12\x43limateHoldSetting\x12\x10\n\x08\x64uration\x18\x01 \x01(\x05\"@\n\rActionRequest\x12/\n\x06\x61\x63tion\x18\x01 \x01(\x0e\x32\x1f.rivian.parallax.comfort.Action\"\xd7\x02\n\x11\x43limateHoldStatus\x12?\n\x06status\x18\x01 \x01(\x0e\x32/.rivian.parallax.comfort.ClimateHoldStatusValue\x12\x46\n\x0c\x61vailability\x18\x02 \x01(\x0e\x32\x30.rivian.parallax.comfort.ClimateHoldAvailability\x12W\n\x15unavailability_reason\x18\x03 \x01(\x0e\x32\x38.rivian.parallax.comfort.ClimateHoldUnavailabilityReason\x12\x44\n\x08\x65nd_time\x18\x04 \x01(\x0b\x32\x32.rivian.parallax.comfort.ClimateHoldStatus.EndTime\x1a\x1a\n\x07\x45ndTime\x12\x0f\n\x07seconds\x18\x01 \x01(\x03\"L\n\x12\x44\x65\x66rostDefogStatus\x12\x36\n\x06status\x18\x01 \x01(\x0e\x32&.rivian.parallax.comfort.DefrostStatus\"\xda\x01\n\rPetModeStatus\x12\x35\n\x06status\x18\x01 \x01(\x0e\x32%.rivian.parallax.comfort.PetModeState\x12M\n\x12temperature_status\x18\x02 \x01(\x0e\x32\x31.rivian.parallax.comfort.PetModeTemperatureStatus\x12\x43\n\rcabin_climate\x18\x03 \x01(\x0e\x32,.rivian.parallax.comfort.PetModeCabinClimate\"\xa4\x02\n\x16SeatConditioningStatus\x12H\n\x07surface\x18\x01 \x03(\x0b\x32\x37.rivian.parallax.comfort.SeatConditioningStatus.Surface\x1a\xbf\x01\n\x07Surface\x12\x31\n\x02id\x18\x01 \x01(\x0e\x32%.rivian.parallax.comfort.CabinSurface\x12\x37\n\x04type\x18\x02 \x01(\x0e\x32).rivian.parallax.comfort.ConditioningType\x12>\n\x05state\x18\x03 \x01(\x0e\x32*.rivian.parallax.comfort.ConditioningLevelH\x00\x88\x01\x01\x42\x08\n\x06_state*\x85\x03\n\x15PreconditioningStatus\x12&\n\"PRECONDITIONING_STATUS_UNSPECIFIED\x10\x00\x12\x1c\n\x18PRECONDITIONING_INITIATE\x10\x01\x12\x1a\n\x16PRECONDITIONING_ACTIVE\x10\x02\x12\"\n\x1ePRECONDITIONING_ACTIVE_WARNING\x10\x03\x12%\n!PRECONDITIONING_COMPLETE_MAINTAIN\x10\x04\x12-\n)PRECONDITIONING_TIMEOUT_TEMP_NOT_ACHIEVED\x10\x05\x12!\n\x1dPRECONDITIONING_ERROR_SOC_LOW\x10\x06\x12&\n\"PRECONDITIONING_ERROR_SYSTEM_FAULT\x10\x07\x12\x1f\n\x1bPRECONDITIONING_UNAVAILABLE\x10\x08\x12$\n PRECONDITIONING_TIMEOUT_COMPLETE\x10\t*\xe4\x01\n\x13PreconditioningType\x12$\n PRECONDITIONING_TYPE_UNSPECIFIED\x10\x00\x12&\n\"PRECONDITIONING_TYPE_USER_SELECTED\x10\x01\x12*\n&PRECONDITIONING_TYPE_SCREEN_PROTECTION\x10\x02\x12\"\n\x1ePRECONDITIONING_TYPE_SCHEDULED\x10\x03\x12/\n+PRECONDITIONING_TYPE_AUTO_CABIN_VENTILATION\x10\x04*?\n\x06\x41\x63tion\x12\x16\n\x12\x41\x43TION_UNSPECIFIED\x10\x00\x12\r\n\tACTION_ON\x10\x01\x12\x0e\n\nACTION_OFF\x10\x02*\xba\x01\n\x16\x43limateHoldStatusValue\x12#\n\x1f\x43LIMATE_HOLD_STATUS_UNSPECIFIED\x10\x00\x12#\n\x1f\x43LIMATE_HOLD_STATUS_UNAVAILABLE\x10\x01\x12\x1b\n\x17\x43LIMATE_HOLD_STATUS_OFF\x10\x02\x12\x1a\n\x16\x43LIMATE_HOLD_STATUS_ON\x10\x03\x12\x1d\n\x19\x43LIMATE_HOLD_STATUS_FAULT\x10\x04*\x9d\x01\n\x17\x43limateHoldAvailability\x12)\n%CLIMATE_HOLD_AVAILABILITY_UNSPECIFIED\x10\x00\x12\x1a\n\x16\x43LIMATE_HOLD_AVAILABLE\x10\x01\x12\x1d\n\x19\x43LIMATE_HOLD_CONTROLLABLE\x10\x02\x12\x1c\n\x18\x43LIMATE_HOLD_UNAVAILABLE\x10\x03*\xc7\x01\n\x1f\x43limateHoldUnavailabilityReason\x12+\n\'CLIMATE_HOLD_UNAVAILABILITY_UNSPECIFIED\x10\x00\x12\'\n#CLIMATE_HOLD_UNAVAILABILITY_UNKNOWN\x10\x01\x12\'\n#CLIMATE_HOLD_UNAVAILABILITY_LOW_SOC\x10\x02\x12%\n!CLIMATE_HOLD_UNAVAILABILITY_FAULT\x10\x03*\x82\x01\n\rDefrostStatus\x12\x1e\n\x1a\x44\x45\x46ROST_STATUS_UNSPECIFIED\x10\x00\x12\x11\n\rDEFROST_DEFOG\x10\x01\x12\x12\n\x0e\x44\x45\x46ROST_ACTIVE\x10\x02\x12\x19\n\x15\x44\x45\x46ROST_DEFOG_DEFROST\x10\x03\x12\x0f\n\x0b\x44\x45\x46ROST_OFF\x10\x04*~\n\x13PetModeCabinClimate\x12&\n\"PET_MODE_CABIN_CLIMATE_COMFORTABLE\x10\x00\x12\x1f\n\x1bPET_MODE_CABIN_CLIMATE_COLD\x10\x01\x12\x1e\n\x1aPET_MODE_CABIN_CLIMATE_HOT\x10\x02*]\n\x0cPetModeState\x12\x10\n\x0cPET_MODE_OFF\x10\x00\x12\x0f\n\x0bPET_MODE_ON\x10\x01\x12\x15\n\x11PET_MODE_DISABLED\x10\x02\x12\x13\n\x0fPET_MODE_FAULTY\x10\x03*\x9a\x01\n\x18PetModeTemperatureStatus\x12 \n\x1cPET_MODE_TEMPERATURE_DEFAULT\x10\x00\x12\x1d\n\x19PET_MODE_TEMPERATURE_COLD\x10\x01\x12\x1c\n\x18PET_MODE_TEMPERATURE_HOT\x10\x02\x12\x1f\n\x1bPET_MODE_TEMPERATURE_FAULTY\x10\x03*\xce\x02\n\x0c\x43\x61\x62inSurface\x12\x1d\n\x19\x43\x41\x42IN_SURFACE_UNSPECIFIED\x10\x00\x12\x12\n\x0eSTEERING_WHEEL\x10\x01\x12\x0e\n\nREAR_GLASS\x10\x02\x12\x0f\n\x0b\x46RONT_GLASS\x10\x03\x12\x14\n\x10SIDEVIEW_MIRRORS\x10\x04\x12\x13\n\x0fSEAT_ROW_1_LEFT\x10\x05\x12\x15\n\x11SEAT_ROW_1_MIDDLE\x10\x06\x12\x14\n\x10SEAT_ROW_1_RIGHT\x10\x07\x12\x13\n\x0fSEAT_ROW_2_LEFT\x10\x08\x12\x15\n\x11SEAT_ROW_2_MIDDLE\x10\t\x12\x14\n\x10SEAT_ROW_2_RIGHT\x10\n\x12\x13\n\x0fSEAT_ROW_3_LEFT\x10\x0b\x12\x15\n\x11SEAT_ROW_3_MIDDLE\x10\x0c\x12\x14\n\x10SEAT_ROW_3_RIGHT\x10\r\x12\x0e\n\nWIPER_AREA\x10\x0e*c\n\x10\x43onditioningType\x12!\n\x1d\x43ONDITIONING_TYPE_UNSPECIFIED\x10\x00\x12\x15\n\x11\x43ONDITIONING_HEAT\x10\x01\x12\x15\n\x11\x43ONDITIONING_VENT\x10\x02*\x85\x01\n\x11\x43onditioningLevel\x12\"\n\x1e\x43ONDITIONING_LEVEL_UNSPECIFIED\x10\x00\x12\x18\n\x14\x43ONDITIONING_LEVEL_1\x10\x01\x12\x18\n\x14\x43ONDITIONING_LEVEL_2\x10\x02\x12\x18\n\x14\x43ONDITIONING_LEVEL_3\x10\x03\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'rivian.parallax.proto.comfort_pb2', _globals) if not _descriptor._USE_C_DESCRIPTORS: DESCRIPTOR._loaded_options = None - _globals['_PRECONDITIONINGSTATUS']._serialized_start=1784 - _globals['_PRECONDITIONINGSTATUS']._serialized_end=2173 - _globals['_PRECONDITIONINGTYPE']._serialized_start=2176 - _globals['_PRECONDITIONINGTYPE']._serialized_end=2404 - _globals['_CLIMATEHOLDSTATUSVALUE']._serialized_start=2407 - _globals['_CLIMATEHOLDSTATUSVALUE']._serialized_end=2593 - _globals['_CLIMATEHOLDAVAILABILITY']._serialized_start=2596 - _globals['_CLIMATEHOLDAVAILABILITY']._serialized_end=2753 - _globals['_CLIMATEHOLDUNAVAILABILITYREASON']._serialized_start=2756 - _globals['_CLIMATEHOLDUNAVAILABILITYREASON']._serialized_end=2955 - _globals['_DEFROSTSTATUS']._serialized_start=2958 - _globals['_DEFROSTSTATUS']._serialized_end=3088 - _globals['_PETMODECABINCLIMATE']._serialized_start=3090 - _globals['_PETMODECABINCLIMATE']._serialized_end=3216 - _globals['_PETMODESTATE']._serialized_start=3218 - _globals['_PETMODESTATE']._serialized_end=3311 - _globals['_PETMODETEMPERATURESTATUS']._serialized_start=3314 - _globals['_PETMODETEMPERATURESTATUS']._serialized_end=3468 - _globals['_CABINSURFACE']._serialized_start=3471 - _globals['_CABINSURFACE']._serialized_end=3805 - _globals['_CONDITIONINGTYPE']._serialized_start=3807 - _globals['_CONDITIONINGTYPE']._serialized_end=3906 - _globals['_CONDITIONINGLEVEL']._serialized_start=3909 - _globals['_CONDITIONINGLEVEL']._serialized_end=4042 + _globals['_PRECONDITIONINGSTATUS']._serialized_start=1850 + _globals['_PRECONDITIONINGSTATUS']._serialized_end=2239 + _globals['_PRECONDITIONINGTYPE']._serialized_start=2242 + _globals['_PRECONDITIONINGTYPE']._serialized_end=2470 + _globals['_ACTION']._serialized_start=2472 + _globals['_ACTION']._serialized_end=2535 + _globals['_CLIMATEHOLDSTATUSVALUE']._serialized_start=2538 + _globals['_CLIMATEHOLDSTATUSVALUE']._serialized_end=2724 + _globals['_CLIMATEHOLDAVAILABILITY']._serialized_start=2727 + _globals['_CLIMATEHOLDAVAILABILITY']._serialized_end=2884 + _globals['_CLIMATEHOLDUNAVAILABILITYREASON']._serialized_start=2887 + _globals['_CLIMATEHOLDUNAVAILABILITYREASON']._serialized_end=3086 + _globals['_DEFROSTSTATUS']._serialized_start=3089 + _globals['_DEFROSTSTATUS']._serialized_end=3219 + _globals['_PETMODECABINCLIMATE']._serialized_start=3221 + _globals['_PETMODECABINCLIMATE']._serialized_end=3347 + _globals['_PETMODESTATE']._serialized_start=3349 + _globals['_PETMODESTATE']._serialized_end=3442 + _globals['_PETMODETEMPERATURESTATUS']._serialized_start=3445 + _globals['_PETMODETEMPERATURESTATUS']._serialized_end=3599 + _globals['_CABINSURFACE']._serialized_start=3602 + _globals['_CABINSURFACE']._serialized_end=3936 + _globals['_CONDITIONINGTYPE']._serialized_start=3938 + _globals['_CONDITIONINGTYPE']._serialized_end=4037 + _globals['_CONDITIONINGLEVEL']._serialized_start=4040 + _globals['_CONDITIONINGLEVEL']._serialized_end=4173 _globals['_HVACSETTINGSSTATUS']._serialized_start=64 _globals['_HVACSETTINGSSTATUS']._serialized_end=112 _globals['_USERMODESSTATE']._serialized_start=115 @@ -69,16 +71,18 @@ _globals['_CABINVENTILATIONSETTING']._serialized_end=801 _globals['_CLIMATEHOLDSETTING']._serialized_start=803 _globals['_CLIMATEHOLDSETTING']._serialized_end=841 - _globals['_CLIMATEHOLDSTATUS']._serialized_start=844 - _globals['_CLIMATEHOLDSTATUS']._serialized_end=1187 - _globals['_CLIMATEHOLDSTATUS_ENDTIME']._serialized_start=1161 - _globals['_CLIMATEHOLDSTATUS_ENDTIME']._serialized_end=1187 - _globals['_DEFROSTDEFOGSTATUS']._serialized_start=1189 - _globals['_DEFROSTDEFOGSTATUS']._serialized_end=1265 - _globals['_PETMODESTATUS']._serialized_start=1268 - _globals['_PETMODESTATUS']._serialized_end=1486 - _globals['_SEATCONDITIONINGSTATUS']._serialized_start=1489 - _globals['_SEATCONDITIONINGSTATUS']._serialized_end=1781 - _globals['_SEATCONDITIONINGSTATUS_SURFACE']._serialized_start=1590 - _globals['_SEATCONDITIONINGSTATUS_SURFACE']._serialized_end=1781 + _globals['_ACTIONREQUEST']._serialized_start=843 + _globals['_ACTIONREQUEST']._serialized_end=907 + _globals['_CLIMATEHOLDSTATUS']._serialized_start=910 + _globals['_CLIMATEHOLDSTATUS']._serialized_end=1253 + _globals['_CLIMATEHOLDSTATUS_ENDTIME']._serialized_start=1227 + _globals['_CLIMATEHOLDSTATUS_ENDTIME']._serialized_end=1253 + _globals['_DEFROSTDEFOGSTATUS']._serialized_start=1255 + _globals['_DEFROSTDEFOGSTATUS']._serialized_end=1331 + _globals['_PETMODESTATUS']._serialized_start=1334 + _globals['_PETMODESTATUS']._serialized_end=1552 + _globals['_SEATCONDITIONINGSTATUS']._serialized_start=1555 + _globals['_SEATCONDITIONINGSTATUS']._serialized_end=1847 + _globals['_SEATCONDITIONINGSTATUS_SURFACE']._serialized_start=1656 + _globals['_SEATCONDITIONINGSTATUS_SURFACE']._serialized_end=1847 # @@protoc_insertion_point(module_scope) diff --git a/src/rivian/parallax/proto/comfort_pb2.pyi b/src/rivian/parallax/proto/comfort_pb2.pyi index 6e14bc4..2d24d8d 100644 --- a/src/rivian/parallax/proto/comfort_pb2.pyi +++ b/src/rivian/parallax/proto/comfort_pb2.pyi @@ -28,6 +28,12 @@ class PreconditioningType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): PRECONDITIONING_TYPE_SCHEDULED: _ClassVar[PreconditioningType] PRECONDITIONING_TYPE_AUTO_CABIN_VENTILATION: _ClassVar[PreconditioningType] +class Action(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + ACTION_UNSPECIFIED: _ClassVar[Action] + ACTION_ON: _ClassVar[Action] + ACTION_OFF: _ClassVar[Action] + class ClimateHoldStatusValue(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): __slots__ = () CLIMATE_HOLD_STATUS_UNSPECIFIED: _ClassVar[ClimateHoldStatusValue] @@ -123,6 +129,9 @@ PRECONDITIONING_TYPE_USER_SELECTED: PreconditioningType PRECONDITIONING_TYPE_SCREEN_PROTECTION: PreconditioningType PRECONDITIONING_TYPE_SCHEDULED: PreconditioningType PRECONDITIONING_TYPE_AUTO_CABIN_VENTILATION: PreconditioningType +ACTION_UNSPECIFIED: Action +ACTION_ON: Action +ACTION_OFF: Action CLIMATE_HOLD_STATUS_UNSPECIFIED: ClimateHoldStatusValue CLIMATE_HOLD_STATUS_UNAVAILABLE: ClimateHoldStatusValue CLIMATE_HOLD_STATUS_OFF: ClimateHoldStatusValue @@ -238,6 +247,12 @@ class ClimateHoldSetting(_message.Message): duration: int def __init__(self, duration: _Optional[int] = ...) -> None: ... +class ActionRequest(_message.Message): + __slots__ = ("action",) + ACTION_FIELD_NUMBER: _ClassVar[int] + action: Action + def __init__(self, action: _Optional[_Union[Action, str]] = ...) -> None: ... + class ClimateHoldStatus(_message.Message): __slots__ = ("status", "availability", "unavailability_reason", "end_time") class EndTime(_message.Message): diff --git a/tests/parallax/test_comfort.py b/tests/parallax/test_comfort.py index aec1f47..282352f 100644 --- a/tests/parallax/test_comfort.py +++ b/tests/parallax/test_comfort.py @@ -4,7 +4,12 @@ import pytest -from rivian.parallax import CLIMATE_HOLD_SETTING_RVM, encode_climate_hold_setting +from rivian.parallax import ( + CLIMATE_HOLD_SETTING_RVM, + encode_climate_hold, + encode_climate_hold_setting, + encode_pet_mode, +) from rivian.parallax.proto import comfort_pb2 as comfort from .helpers import decode @@ -86,6 +91,12 @@ def test_climate_hold_setting() -> None: assert decode(CLIMATE_HOLD_SETTING_RVM, setting) == {"climateHoldDuration": 7200} +def test_climate_hold_and_pet_mode() -> None: + """On and off encode like the Rivian app's.""" + assert encode_climate_hold(True) == encode_pet_mode(True) == b"\x08\x01" + assert encode_climate_hold(False) == encode_pet_mode(False) == b"\x08\x02" + + def test_climate_hold_status() -> None: """The end time is read from its {seconds} wrapper.""" status = comfort.ClimateHoldStatus