bretterer / home-assistant-rivian

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

Possible issue with HomeAssistant 2022.11.1 #25

Closed OverZealous closed 2 years ago

OverZealous commented 2 years ago

My integration has been stuck in a loop since I upgraded to 2022.11.1. It's possible this was a coincidence, but I haven't tried rolling back yet. The integration was working up until I rebooted after the core update.

The error in the logs is:

This error originated from a custom integration.

Logger: custom_components.rivian
Source: custom_components/rivian/__init__.py:203
Integration: Rivian (Unofficial) (documentation)
First occurred: 12:25:05 PM (4 occurrences)
Last logged: 12:49:06 PM

Unexpected error fetching rivian data: Error communicating with API
Traceback (most recent call last):
  File "/config/custom_components/rivian/__init__.py", line 156, in _update_api_data
    vehicle_info = await self._api.get_vehicle_info(
  File "/usr/local/lib/python3.10/site-packages/rivian/rivian.py", line 292, in get_vehicle_info
    raise Exception(
Exception: (503, {'error_code': -20, 'error_desc': 'Cesium was unable to communicate with a service it depends on.', 'error_name': 'IntraServiceError'}, {'User-Agent': 'RivianApp/707 CFNetwork/1237 Darwin/20.4.0', 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer '}, {'car': '7FCTGAAL7NN004056', '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/modes/drive_mode', '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_efficiency/lifetime_wh_per_km', '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', 'telematics/gnss/position']})

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/rivian/__init__.py", line 190, in _async_update_data
    return await self._update_api_data()
  File "/config/custom_components/rivian/__init__.py", line 185, in _update_api_data
    raise Exception("Error communicating with API") from err
Exception: Error communicating with API

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/rivian/__init__.py", line 203, in _async_update_data
    raise Exception("Error communicating with API") from err
Exception: Error communicating with API
alexdw369 commented 2 years ago

Same here

rfletcher commented 2 years ago

I have the same error. I'd reported it in issue #28, but closed that as a duplicate.

This is not specific Home Assistant 2022.11.1. I'm still running 2022.7.7.

jrgutier commented 2 years ago

I fixed this issue here. Just waiting for it to be committed.

krazos commented 2 years ago

v0.5.1 is not working for me so far -- API errors similar to the above.

I manually downgraded the rivian-python-client package to the prior release (0.0.1a5) and reverted the version requirement in manifest.json, and it started working again, so I suspect there may be an issue with v0.1.3 of the underlying Python package.

Just noticed that v0.1.4 has been published. I tried that one as well, but it isn't working for me either.

OverZealous commented 2 years ago

Sadly, I'm still seeing the error, too, even after removing and re-adding the integration.

One thought I had is possibly the client ID/secret we have isn't valid anymore, but I've only ever found the one pair.

krazos commented 2 years ago

The issue for me is pretty clearly the underlying Python package. If I edit manifest.json to hardcode rivian-python-client==0.0.1a5, everything works. If I allow the integration to install a subsequent version of the package (e.g., 0.1.3 or 0.1.4), the integration is unable to access the API.

{
    "domain": "rivian",
    "name": "Rivian (Unofficial)",
    "config_flow": true,
    "documentation": "https://github.com/bretterer/home-assistant-rivian",
    "requirements": [
        "rivian-python-client==0.0.1a5"
    ],
    "codeowners": [
        "@bretterer"
    ],
    "iot_class": "cloud_polling",
    "loggers": [
        "rivian"
    ],
  "version": "0.5.1"
}
krazos commented 2 years ago

I haven't had time to do a deep dive, but quickly comparing the source code of 0.1.3+ of rivian-python-client with 0.0.1a5, I believe line 250 is the source of the issue:

    async def get_vehicle_info(
        self, vin: str, access_token: str, properties: dict[str]
    ) -> dict[str, Any]:
        """get the vehicle info"""
        url = CESIUM_BASEPATH + "/vehicle/latest"

        headers = dict()
        headers.update(BASE_HEADERS)
        headers.update({
            "Authorization": "Bearer " + self._access_token,
        })

When I revert the change to line 250 by changing self._access_token back to access_token and rebuild the Python package, the integration starts working again.

Edit: Oops, I see that @tmack8001 has already submitted a PR for this upstream. I believe that PR will resolve the issue, at least for me.

tmack8001 commented 2 years ago

Yes, that is right @krazos that is the error and was a mistake on my part in adding some new endpoints and structure for reuse with the graphql endpoints we will be migrating over to.

Talking with @jrgutier and @bretterer we should lock the version of the python-client and only release updates to the HA integration when intended vs getting these changes reflected auto-magically since the python-client for the most part is stable now.

krazos commented 2 years ago

Grateful for the work you all have done to date, and excited to see how this project grows and develops. It looks like the new endpoints may return some additional data, including more granular charging data from the Rivian wall charger. Looking forward to that!

bretterer commented 2 years ago

Looks like we may have a fix for this with the integration 0.5.2. Please update and it should be resolved

krazos commented 2 years ago

Confirming that all is well on my end with 0.5.2. Thanks!

OverZealous commented 2 years ago

Works for me, too! I'll close this out, thank you all!