bretterer / home-assistant-rivian

Rivian (Unofficial) Integration for Home Assistant
Apache License 2.0
118 stars 19 forks source link

Session expires after 2 hours #18

Closed rfletcher closed 2 years ago

rfletcher commented 2 years ago

Rivian pushed out an update that signed many (all?) users out of the mobile app the other night, and I've had trouble with my HA Rivian sessions ever since.

  1. The long-lived session that had been active since initially setting up the integration was terminated.
  2. Using the HA web UI I deleted and re-added the Rivian integration.
  3. 2 hours later, the integration started throwing authentication errors again.

It looks like something related to API authentication has changed. Here's a traceback:

Oct 05 09:09:25 quicksand home-assistant[2865899]: 2022-10-05 09:09:25 ERROR (MainThread) [custom_components.rivian] Unexpected error fetching rivian data: Error communicating with API
Oct 05 09:09:25 quicksand home-assistant[2865899]: Traceback (most recent call last):
Oct 05 09:09:25 quicksand home-assistant[2865899]:   File "/config/custom_components/rivian/__init__.py", line 139, in _async_update_data
Oct 05 09:09:25 quicksand home-assistant[2865899]:     return await self._update_api_data()
Oct 05 09:09:25 quicksand home-assistant[2865899]:   File "/config/custom_components/rivian/__init__.py", line 126, in _update_api_data
Oct 05 09:09:25 quicksand home-assistant[2865899]:     vehicle_info = await self._api.get_vehicle_info(
Oct 05 09:09:25 quicksand home-assistant[2865899]:   File "/usr/local/lib/python3.10/site-packages/rivian/rivian.py", line 290, in get_vehicle_info
Oct 05 09:09:25 quicksand home-assistant[2865899]:     raise Exception(
Oct 05 09:09:25 quicksand home-assistant[2865899]: Exception: (401, {'error_code': -41, 'error_desc': "Authentication Error <class 'rcore.rexceptions.RPermissionErrorTokenInvalid'>", 'error_name': 'AuthError'}, {'User-Agent': 'RivianApp/707 CFNetwork/1237 Darwin/20.4.0', 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer <redacted>'}, {'car': '<redacted>', 'properties': ['core/ota_status/cgm_ota_install_fast_charging', 'core/ota_status/cgm_ota_install_hv_batt_low', 'core/ota_status/cgm_ota_install_not_parked', 'core/ota_status/cgm_ota_install_ready', 'core/power_modes/power_state', 'dynamics/hv_battery_notifications/BMS_thermal_event', 'dynamics/odometer/value', 'dynamics/powertrain_status/brake_fluid_level_low', 'dynamics/propulsion_status/PRNDL', 'dynamics/tires/tire_FL_pressure_status', 'dynamics/tires/tire_FR_pressure_status', 'dynamics/tires/tire_RL_pressure_status', 'dynamics/tires/tire_RR_pressure_status', 'energy_storage/charger/adjusted_soc', 'energy_storage/charger/EMS_charger_remainingtime_min_1', 'energy_storage/icd_cid_notifications/b_pack_thermal_runaway_propagation', 'energy_storage/icd_cid_notifications/range_threshold', 'energy_storage/vehicle_energy/vehicle_range', 'telematics/ota_status/available_version_number', 'telematics/ota_status/available_version_week', 'telematics/ota_status/available_version_year', 'telematics/ota_status/available_version', 'telematics/ota_status/current_version_number', 'telematics/ota_status/current_version_week', 'telematics/ota_status/current_version_year', 'telematics/ota_status/current_version', 'telematics/ota_status/download_progress', 'telematics/ota_status/install_duration', 'telematics/ota_status/install_progress', 'telematics/ota_status/install_time', 'telematics/ota_status/install_type', 'telematics/ota_status/pending_reason_active_mode', 'telematics/ota_status/pending_reason_lv_batt', 'telematics/ota_status/pending_reason_other', 'telematics/ota_status/status_current', 'telematics/ota_status/status', 'thermal/hvac_cabin_control/cabin_temperature', 'thermal/hvac_cabin_control/driver_temperature', 'thermal/hvac_settings/pet_mode_temperature_status', 'body/alarm/sound_alarm', 'body/closures/door_FL_locked_state', 'body/closures/door_FL_state', 'body/closures/door_FR_locked_state', 'body/closures/door_FR_state', 'body/closures/door_RL_locked_state', 'body/closures/door_RL_state', 'body/closures/door_RR_locked_state', 'body/closures/door_RR_state', 'body/closures/front_left_window_state', 'body/closures/front_right_window_state', 'body/closures/frunk_locked_state', 'body/closures/frunk_state', 'body/closures/gear_guard_locked_state', 'body/closures/liftgate_locked_state', 'body/closures/liftgate_state', 'body/closures/rear_left_window_state', 'body/closures/rear_right_window_state', 'body/closures/sidebin_L_locked_state', 'body/closures/sidebin_L_state', 'body/closures/sidebin_R_locked_state', 'body/closures/sidebin_R_state', 'body/closures/tailgate_locked_state', 'body/closures/tailgate_state', 'body/closures/tonneau_locked_state', 'body/closures/tonneau_state', 'body/door_control_log/BCM_WindowCalibrationFL_Status', 'body/door_control_log/BCM_WindowCalibrationFR_Status', 'body/door_control_log/BCM_WindowCalibrationRL_Status', 'body/door_control_log/BCM_WindowCalibrationRR_Status', 'body/wipers/fluid_state', 'dynamics/tires/tire_FL_pressure_status_valid', 'dynamics/tires/tire_FR_pressure_status_valid', 'dynamics/tires/tire_RL_pressure_status_valid', 'dynamics/tires/tire_RR_pressure_status_valid', 'energy_storage/charger/vehicle_charger_state', 'thermal/hvac_settings/pet_mode_status', 'thermal/tmm_status/cabin_precondition_state', '$gnss']})
Oct 05 09:09:25 quicksand home-assistant[2865899]: The above exception was the direct cause of the following exception:
Oct 05 09:09:25 quicksand home-assistant[2865899]: Traceback (most recent call last):
Oct 05 09:09:25 quicksand home-assistant[2865899]:   File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
Oct 05 09:09:25 quicksand home-assistant[2865899]:     self.data = await self._async_update_data()
Oct 05 09:09:25 quicksand home-assistant[2865899]:   File "/config/custom_components/rivian/__init__.py", line 150, in _async_update_data
Oct 05 09:09:25 quicksand home-assistant[2865899]:     raise Exception("Error communicating with API") from err
Oct 05 09:09:25 quicksand home-assistant[2865899]: Exception: Error communicating with API
bretterer commented 2 years ago

I am looking for a fix to this. Right now, it appears that a removal of the integration and re-addition will fix this. I know this is not ideal right now, but I am not sure of the best way to fix this at the moment

cdheiser commented 2 years ago

I haven't entirely figured out what's going on yet, but removal and re-addition seems to work for a very short time, but that's it.

bretterer commented 2 years ago

This should be resolved in 0.5.0-beta.3 https://github.com/bretterer/home-assistant-rivian/releases/tag/0.5.0-beta.3. Please give it a shot and let me know

cdheiser commented 2 years ago

So far so good

On Fri, Oct 7, 2022, 8:45 PM Brian Retterer @.***> wrote:

This should be resolved in 0.5.0-beta.3 https://github.com/bretterer/home-assistant-rivian/releases/tag/0.5.0-beta.3. Please give it a shot and let me know

— Reply to this email directly, view it on GitHub https://github.com/bretterer/home-assistant-rivian/issues/18#issuecomment-1272215714, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQARWT7P4BTTZU25BCMYZ3WCDU5PANCNFSM6AAAAAAQ5SNWZQ . You are receiving this because you commented.Message ID: @.***>

rfletcher commented 2 years ago

This should be resolved in 0.5.0-beta.3

Looks good to me. I upgraded ~8 hours ago and my session is still alive. Thanks!

bretterer commented 2 years ago

Resolved with 0.5.0