robinostlund / homeassistant-volkswagencarnet

Volkswagen Carnet Component for home assistant
GNU General Public License v3.0
321 stars 60 forks source link

[BUG] Error after upgrading to Home Assistant 2023.5.0 #474

Closed stickpin closed 1 year ago

stickpin commented 1 year ago

Before you post a new issue - you must first check the following (and check the boxes with an "X" below)

Environment

Describe the bug

After the latest Home Assistant upgrade (2023.5.0), the "datetime" values are no longer shown.

Steps to Reproduce

Expected behavior

Screenshots

Screenshot 2023-05-04 at 08 30 06

Traceback/Error logs

2023-05-04 08:18:48.562 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 579, in state
    numerical_value = int(value)
ValueError: invalid literal for int() with base 10: '2023-05-03 16:25:33'

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 204, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 349, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 146, in async_update_listeners
    update_callback()
  File "/config/custom_components/volkswagencarnet/__init__.py", line 344, in async_write_ha_state
    or str(self.state or STATE_UNKNOWN) != str(prev.state)
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
    raise ValueError(
ValueError: Sensor sensor.vw_touran_parking_time has device class None, state class None unit  and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: 2023-05-03 16:25:33 (<class 'str'>)

Debug information - all JSON responses from logfile

Additional context

stickpin commented 1 year ago

There are many complaints on HA Git about similar issue:

Let's see what HA Devs will say about it.

sorenlouv commented 1 year ago

I'm also seeing issues after upgrading to 2023.5.0. Sensors like sensor.{car_id}_battery_level are no longer updated. Only when restarting HA (or reloading the integration) the sensor state is updated.

stickpin commented 1 year ago

I've submitted the fix: https://github.com/robinostlund/homeassistant-volkswagencarnet/pull/475 If you don't want to wait for the merge just edit the sensor.py file inside the integration folder (/config/custom_components/volkswagencarnet/sensor.py).

Change this code:

    @property
    def _attr_native_unit_of_measurement(self):
        """Return the unit of measurement."""
        return self.instrument.unit

To this code:

    @property
    def _attr_native_unit_of_measurement(self):
        """Return the unit of measurement."""
        if self.instrument.unit:
            return self.instrument.unit
chrisandsally commented 1 year ago

Thank you stickpin! all good with your fix.

only sensor.vw_charger_max_ampere [unavail] to go since 2023.5.0. update

Thanks

moostmartijn commented 1 year ago

Thanks for the quick fix. I do have one more sensor which is still not working besided the max_ampere sensor:

sensor.volkswagen_charging_time_left

stickpin commented 1 year ago

Sorry, I don't have E-VW, so I cannot debug it properly on my end. :(

moostmartijn commented 1 year ago

If I can help you debugging, please let me know.

skallberg commented 1 year ago

Hi, I have updated to the new version but still the integration is not auto updating so I have to reload the integration to get updated sensor values.

Also I missing sensor charging time left. image

sparkelende commented 1 year ago

Same here. Sensors not updating without reloading integration. Only battery level is working. So I have maximum range with 0% battery sometimes. :) Remote climatisation works but switch won't stay toggled and therefore unable to turn climatisation off again.

Also missing sensor charging time left. Using latest version.

LookedPath commented 1 year ago

I'm also having the same issues even after patching to version v4.4.60

Here is a stack trace of the error that causes the Charging Time Left sensor to not be displayed correctly:

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:583
Integration: Sensor (documentation, issues)
First occurred: 07:40:15 (4 occurrences)
Last logged: 11:19:24

Error adding entities for domain sensor with platform volkswagencarnet
Error while setting up volkswagencarnet platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 579, in state
    numerical_value = int(value)
ValueError: invalid literal for int() with base 10: '10:30'

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

Traceback (most recent call last):
  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 846, in add_to_platform_finish
    self.async_write_ha_state()
  File "/config/custom_components/volkswagencarnet/__init__.py", line 346, in async_write_ha_state
    super().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/sensor/__init__.py", line 583, in state
    raise ValueError(
ValueError: Sensor sensor.e_up_charging_time_left has device class None, state class None unit h and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: 10:30 (<class 'str'>)
stickpin commented 1 year ago

well, as far as I can see, there are two approaches to solving this:

  1. To update the HA plugging to exclude those two sensors inside the _attr_native_unit_of_measurement function. Which I guess gonna be a bit ugly.
  2. To update the Python library to pass empty units for not int sensors. This approach may break some other integrations except HA: https://github.com/robinostlund/volkswagencarnet/blob/master/volkswagencarnet/vw_dashboard.py

@robinostlund what is your opinion?

robinostlund commented 1 year ago

@stickpin i suggest to update the vw_dashboad.py in volkswagencarnet as that is only used for the home assistant integration 😄 , thanks for helping out, i don't have a car with weconnect anymore so i appreciate all the help i can get 😄

stickpin commented 1 year ago

@robinostlund thanks! :) I've pushed the fix: https://github.com/robinostlund/volkswagencarnet/pull/202

robinostlund commented 1 year ago

@stickpin lovely, i will release a new version of the library, can you do a PR to this repo and update the version in this file once it is released? :) https://github.com/robinostlund/homeassistant-volkswagencarnet/blob/master/requirements.txt

stickpin commented 1 year ago

@robinostlund sure, will do. :)

robinostlund commented 1 year ago

@stickpin relased :) https://pypi.org/project/volkswagencarnet/

stickpin commented 1 year ago

@robinostlund PR created: https://github.com/robinostlund/homeassistant-volkswagencarnet/pull/477 :)

sparkelende commented 1 year ago

All working fine again after latest update. Thanks!

chrisandsally commented 1 year ago

Thank you so much stickpin and team. Legends.

skallberg commented 1 year ago

Thank you very much!!