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

None not in STEERING_HEATER_OPTIONS #633

Closed iancg closed 1 year ago

iancg commented 1 year ago

Version of the custom_component

v3.13.0

Configuration

Add your logs here.

Describe the bug

I have a 2017 Model X which has the older heated steering wheel which doesn't have auto or multiple levels. Since the latest update which included a select for the heated steering wheel, I get an error from the integration and numerous sensors are not available.

I added some temporary debug logging as the value of _car.get_heated_steering_wheel_level() seemed to be interesting:

        current_value = self._car.get_heated_steering_wheel_level()
        _LOGGER.debug(f"current_value: {current_value}")

2023-06-14 11:11:03.188 DEBUG (MainThread) [custom_components.tesla_custom.select] current_value: None

Debug log


2023-06-14 10:26:19.720 ERROR (MainThread) [homeassistant.components.select] Error while setting up tesla_custom platform for select
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 312, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 845, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 585, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 147, in state
    if self.current_option is None or self.current_option not in self.options:
  File "/config/custom_components/tesla_custom/select.py", line 235, in current_option
    options_idx = STEERING_HEATER_OPTIONS.index(current_str)
ValueError: None is not in list
drlauridsen commented 1 year ago

Same with my 2017 model S with 3.13.0 integration. And I lost battery sensor..

iancg commented 1 year ago

@drlauridsen if you comment out line 90 of sensor.py in config/custom_components/tesla_custom and restart HA it will get it working again (but not heated steering wheel control) until it gets fixed properly.

    #entities.append(TeslaCarHeatedSteeringWheel(hass, car, coordinator))
iancg commented 1 year ago

Hi @Megabytemb , What's the best solution for this? Do you need any info from a 2017 era car to fix? I'm guessing our selects should just have Off/On or maybe we shouldn't have the select at all?

Megabytemb commented 1 year ago

hmm, if there's a way to identify that you don't have "Auto" that would be good. No idea how though.

for now, I wonder if it could be as simple as returning "None" for the current selection as it can't be determined?

someone wanna try updating the current option code to

    @property
    def current_option(self):
        """Return current heated steering setting."""
        if self._car.is_auto_steering_wheel_heat is True:
            current_str = "Auto"
        else:
            current_value = self._car.get_heated_steering_wheel_level()
            current_str = next(
                (
                    key
                    for key, val in STEERING_HEATER_OPTIONS_MAP.items()
                    if val == current_value
                ),
                None,
            )

        if current_str is None:
            return None

        options_idx = STEERING_HEATER_OPTIONS.index(current_str)

        return STEERING_HEATER_OPTIONS[options_idx]
iancg commented 1 year ago

hmm, if there's a way to identify that you don't have "Auto" that would be good. No idea how though.

This appears to work for the 2017 style cars (line 90 of sensor.py)

    if car.get_heated_steering_wheel_level() is not None:
        entities.append(TeslaCarHeatedSteeringWheel(hass, car, coordinator))

Given get_heated_steering_wheel_level() was returning None (and then it couldn't find None in the map and thus used None in the second lookup which caused the error I thought that might work - otherwise we are going to have a selector which has no value.

I don't have a dev environment for this (I'm just editing the file in my custom_components/tesla_custom directory on my "production" respberry pi) and I don't have a new enough car to test it still works for the cars with an auto heater, would you mind testing it @Megabytemb and submitting it if it still works for you please.

iEddie-cmd commented 1 year ago

Same issue for me with battery state not found at all and steering_wheel_heater

Megabytemb commented 1 year ago

Ok i've created a pull request that hopefully fixed this issue.

I tried to emulate an older model S using tests, so we'll see how we go

Morcegolas commented 1 year ago

@drlauridsen if you comment out line 90 of sensor.py in config/custom_components/tesla_custom and restart HA it will get it working again (but not heated steering wheel control) until it gets fixed properly.

    #entities.append(TeslaCarHeatedSteeringWheel(hass, car, coordinator))

I have the same problem, have a model 3 from 2019 and everything works fine except the battery information that is not showing up at all.

I don’t have that code on sensor.py, is there any other solution yet? Thanks.