alandtse / tesla

Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login.
Apache License 2.0
591 stars 100 forks source link

Buttons not loading after 3.9.0 release - TypeError: argument of type 'NoneType' is not iterable #466

Closed tubalainen closed 1 year ago

tubalainen commented 1 year ago

Version of the custom_component

3.90

Configuration

N/A

Logs

Add your logs here.
2022-12-29 14:48:17.157 ERROR (MainThread) [homeassistant.components.button] Error while setting up tesla_custom platform for button
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/tesla_custom/button.py", line 30, in async_setup_entry
    entities.append(TeslaCarEmissionsTest(hass, car, coordinator))
  File "/config/custom_components/tesla_custom/button.py", line 182, in __init__
    self._enabled_by_default = self._car.pedestrian_speaker
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/car.py", line 502, in pedestrian_speaker
    if "P3WS" in self._vehicle_data.get("option_codes", {}):
TypeError: argument of type 'NoneType' is not iterable

Describe the bug

The buttons are not loading since the 3.9.0 release. (see log). The the new emission test button did not appear, so I removed the component and re-added it. And after that I get the errors and the buttons does not load. Backed down to 3.8.1 and that version loads just fine.

I am running Home Assistant Container.

Debug log


2022-12-29 14:51:39.293 DEBUG (MainThread) [teslajsonpy.controller] 40802: Updating VEHICLE_DATA
2022-12-29 14:51:39.294 DEBUG (MainThread) [teslajsonpy.connection] Token expiration in 7:55:10
2022-12-29 14:51:39.294 DEBUG (MainThread) [teslajsonpy.connection] get: https://owner-api.teslamotors.com/api/1/vehicles/929648675583341/vehicle_data {}
2022-12-29 14:51:39.631 DEBUG (MainThread) [teslajsonpy.connection] 200: {"response":{"id":92964XXXXXXXX,"user_id":16891628XXXXXX,"vehicle_id":168920566XXXXXX,"vin":"LRWYGCEK5PCXXXXXX","display_name":"Teslan","option_codes":null,"color":null,"access_type":"OWNER","tokens":["141d761410561d49","f430624aa06091b6"],"state":"online","in_service":false,"id_s":"929648675583341","calendar_enabled":true,"api_version":51,"backseat_token":null,"backseat_token_updated_at":null,"charge_state":{"battery_heater_on":false,"battery_level":74,"battery_range":237.79,"charge_amps":16,"charge_current_request":16,"charge_current_request_max":16,"charge_enable_request":true,"charge_energy_added":0.0,"charge_limit_soc":90,"charge_limit_soc_max":100,"charge_limit_soc_min":50,"charge_limit_soc_std":90,"charge_miles_added_ideal":0.0,"charge_miles_added_rated":0.0,"charge_port_cold_weather_mode":false,"charge_port_color":"<invalid>","charge_port_door_open":true,"charge_port_latch":"Engaged","charge_rate":0.0,"charger_actual_current":0,"charger_phases":null,"charger_pilot_current":16,"charger_power":0,"charger_voltage":2,"charging_state":"NoPower","conn_charge_cable":"IEC","est_battery_range":186.21,"fast_charger_brand":"<invalid>","fast_charger_present":false,"fast_charger_type":"<invalid>","ideal_battery_range":237.79,"managed_charging_active":false,"managed_charging_start_time":null,"managed_charging_user_canceled":false,"max_range_charge_counter":0,"minutes_to_full_charge":0,"not_enough_power_to_heat":null,"off_peak_charging_enabled":false,"off_peak_charging_times":"all_week","off_peak_hours_end_time":360,"preconditioning_enabled":false,"preconditioning_times":"weekdays","scheduled_charging_mode":"Off","scheduled_charging_pending":false,"scheduled_charging_start_time":null,"scheduled_charging_start_time_app":0,"scheduled_departure_time":1672216200,"scheduled_departure_time_minutes":570,"supercharger_session_trip_planner":false,"time_to_full_charge":0.0,"timestamp":1672321899486,"trip_charging":false,"usable_battery_level":73,"user_charge_enable_request":null},"climate_state":{"allow_cabin_overheat_protection":true,"auto_seat_climate_left":false,"auto_seat_climate_right":false,"battery_heater":false,"battery_heater_no_power":null,"bioweapon_mode":false,"cabin_overheat_protection":"On","cabin_overheat_protection_actively_cooling":false,"climate_keeper_mode":"off","cop_activation_temperature":"High","defrost_mode":0,"driver_temp_setting":19.5,"fan_status":0,"hvac_auto_request":"On","inside_temp":9.6,"is_auto_conditioning_on":false,"is_climate_on":false,"is_front_defroster_on":false,"is_preconditioning":false,"is_rear_defroster_on":false,"left_temp_direction":762,"max_avail_temp":28.0,"min_avail_temp":15.0,"outside_temp":5.5,"passenger_temp_setting":19.5,"remote_heater_control_enabled":false,"right_temp_direction":762,"seat_heater_left":0,"seat_heater_rear_center":0,"seat_heater_rear_left":0,"seat_heater_rear_right":0,"seat_heater_right":0,"side_mirror_heaters":false,"steering_wheel_heater":false,"supports_fan_only_cabin_overheat_protection":true,"timestamp":1672321899486,"wiper_blade_heater":false},"drive_state":{"active_route_latitude":59.33375,"active_route_longitude":13.511139,"active_route_traffic_minutes_delay":0.0,"gps_as_of":1672321653,"heading":227,"latitude":59.333677,"longitude":13.51114,"native_latitude":59.333677,"native_location_supported":1,"native_longitude":13.51114,"native_type":"wgs","power":0,"shift_state":null,"speed":null,"timestamp":1672321899486},"gui_settings":{"gui_24_hour_time":true,"gui_charge_rate_units":"kW","gui_distance_units":"km/hr","gui_range_display":"Rated","gui_temperature_units":"C","gui_tirepressure_units":"Bar","show_range_units":false,"timestamp":1672321899486},"vehicle_config":{"aux_park_lamps":"Eu","badge_version":1,"can_accept_navigation_requests":true,"can_actuate_trunks":true,"car_special_type":"base","car_type":"modely","charge_port_type":"CCS","cop_user_set_temp_supported":true,"dashcam_clip_save_supported":true,"default_charge_to_max":false,"driver_assist":"TeslaAP3","ece_restrictions":true,"efficiency_package":"MY2021","eu_vehicle":true,"exterior_color":"PearlWhite","exterior_trim":"Black","exterior_trim_override":"","has_air_suspension":false,"has_ludicrous_mode":false,"has_seat_cooling":false,"headlamp_type":"Global","interior_trim_type":"Black2","key_version":2,"motorized_charge_port":true,"paint_color_override":"29,49,62,0.7,0.04","performance_package":"Base","plg":true,"pws":true,"rear_drive_unit":"PM216MOSFET","rear_seat_heaters":1,"rear_seat_type":0,"rhd":false,"roof_color":"RoofColorGlass","seat_type":null,"spoiler_type":"None","sun_roof_installed":null,"supports_qr_pairing":false,"third_row_seats":"None","timestamp":1672321899486,"trim_badging":"74d","use_range_badging":true,"utc_offset":3600,"webcam_selfie_supported":true,"webcam_supported":true,"wheel_type":"Apollo19"},"vehicle_state":{"api_version":51,"autopark_state_v2":"standby","autopark_style":"dead_man","calendar_supported":true,"car_version":"2022.44.25.3 ff63b3ae90e2","center_display_state":0,"dashcam_clip_save_available":true,"dashcam_state":"Recording","df":0,"dr":0,"fd_window":0,"feature_bitmask":"dffbff,0","fp_window":0,"ft":0,"is_user_present":false,"last_autopark_error":"no_error","locked":true,"media_info":{"audio_volume":2.6667,"audio_volume_increment":0.333333,"audio_volume_max":10.333333,"media_playback_status":"Stopped","now_playing_album":"","now_playing_artist":"","now_playing_duration":0,"now_playing_elapsed":0,"now_playing_source":"12","now_playing_station":"","now_playing_title":""},"media_state":{"remote_control_enabled":true},"notifications_supported":true,"odometer":906.26682,"parsed_calendar_supported":true,"pf":0,"pr":0,"rd_window":0,"remote_start":false,"remote_start_enabled":true,"remote_start_supported":true,"rp_window":0,"rt":0,"santa_mode":1,"sentry_mode":false,"sentry_mode_available":true,"service_mode":false,"service_mode_plus":false,"smart_summon_available":true,"software_update":{"download_perc":0,"expected_duration_sec":2700,"install_perc":1,"status":"","version":" "},"speed_limit_mode":{"active":false,"current_limit_mph":85.0,"max_limit_mph":120,"min_limit_mph":50.0,"pin_code_set":false},"summon_standby_mode_enabled":false,"timestamp":1672321899486,"tpms_hard_warning_fl":false,"tpms_hard_warning_fr":false,"tpms_hard_warning_rl":false,"tpms_hard_warning_rr":false,"tpms_last_seen_pressure_time_fl":1672318292,"tpms_last_seen_pressure_time_fr":1672318292,"tpms_last_seen_pressure_time_rl":1672318310,"tpms_last_seen_pressure_time_rr":1672318292,"tpms_pressure_fl":3.225,"tpms_pressure_fr":3.125,"tpms_pressure_rl":3.25,"tpms_pressure_rr":3.175,"tpms_rcp_front_value":2.9,"tpms_rcp_rear_value":2.9,"tpms_soft_warning_fl":false,"tpms_soft_warning_fr":false,"tpms_soft_warning_rl":false,"tpms_soft_warning_rr":false,"valet_mode":false,"valet_pin_needed":true,"vehicle_name":"Teslan","webcam_available":true}}}
2022-12-29 14:51:39.783 ERROR (MainThread) [homeassistant.components.button] Error while setting up tesla_custom platform for button
  File "/config/custom_components/tesla_custom/button.py", line 30, in async_setup_entry
  File "/config/custom_components/tesla_custom/button.py", line 182, in __init__
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/car.py", line 502, in pedestrian_speaker
alandtse commented 1 year ago

@InTheDaylight14 looks like we need to account for null option_codes.

tubalainen commented 1 year ago

Some progress - I had enabled "Force cars awake on startup". Now when I disabled the "force cars awake on startup" checkbox and restarted HASS. It populated the "buttons" but when it refreshes it still doesnt work and the same logs errors shows. image

InTheDaylight14 commented 1 year ago

@InTheDaylight14 looks like we need to account for null option_codes.

When the option codes are not available should we default self._enabled_by_default to True or False?

alandtse commented 1 year ago

If we can't tell, I think we can just assume it's not there. Users can enable them if they really have it.

alandtse commented 1 year ago

teslajsonpy 3.7.1 should be published shortly.

tubalainen commented 1 year ago

Works great now Thanks! <3