Limych / ha-iaquk

Indoor Air Quality Sensor Component for Home Assistant
MIT License
111 stars 16 forks source link

Device class None #109

Closed cinghialino closed 1 year ago

cinghialino commented 1 year ago

Environment

Describe the bug

Sensor sensor.iaquk_home_indoor_air_quality_level has device class None, state class measurement and unit None thus indicating it has a numeric value; however, it has the non-numeric value: Good (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

Configuration.yaml


iaquk:
  air_quality_index:
    name: "Home"
    sources:
      temperature: sensor.average_temperature
      humidity: sensor.average_humidity
      co2: sensor.vindriktning1_co2_level
#      tvoc: sensor.kitchen_tvoc
      pm:
        - sensor.vindriktning1_particulate_matter_2_5um_concentration
        - sensor.pure_cool_link_particulates
    sensors:
      - iaq_level
      - iaq_index

Steps to Reproduce update HA to 2023.02

Expected behavior not having an error in the log

Debug log


Sensor sensor.iaquk_home_indoor_air_quality_level has device class None, state class measurement and unit None thus indicating it has a numeric value; however, it has the non-numeric value: Good (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

Additional context

none

penica commented 1 year ago

Same error here. Sensor sensor.unnamed_device_2 has device class None, state class measurement and unit None thus indicating it has a numeric value; however, it has the non-numeric value: Fair (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.

cinghialino commented 1 year ago

Hello, I'm just wondering if a solution for this error will be included in the next release, thanks

Spiffo commented 1 year ago

Same here, flooding log, if you have some time to look at this that would be nice

smarrk commented 1 year ago

Issue home-assistant/core/#92635 suggest to remove unit_of_measurement from the entities. That probably affects lines 79-81 in sensor.py

smarrk commented 1 year ago

Current tests also fail with the same error message:

FAILED tests/test_sensor.py::test_entity_initialization - ValueError: Sensor sensor.unnamed_device has device class None, state class measurement unit None and suggested precision None thus indicating it has a numeric value; however, it has the ...

Results (0.27s):
      17 passed
       1 failed
         - tests/test_sensor.py:26 test_entity_initialization
McGiverGim commented 1 year ago

The problem remains with HA 2023.6.0

cinghialino commented 1 year ago

I think the dev got drafted..

andrewjswan commented 1 year ago

2023.6.0

2023-06-08 12:16:05.830 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.childroom_iaq_level fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'Good'

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 559, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in async_device_update
    await self.async_update()
  File "/config/custom_components/iaquk/sensor.py", line 102, in async_update
    if self.state == LEVEL_EXCELLENT
       ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
    raise ValueError(
ValueError: Sensor sensor.childroom_iaq_level has device class 'None', state class 'measurement' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'Good' (<class 'str'>)
smarrk commented 1 year ago

This has been fixed in #116 for HA >= v2023.5 (I just tested sucessfully against v2023.6.0).

lahayeg commented 1 year ago

This has been fixed in #116 for HA >= v2023.5 (I just tested sucessfully against v2023.6.0).

would it be possible to merge PR and release?

jjanderson commented 1 year ago

Hi, has this issue been resolved? Been holding back updating (currently still on 2023.4.6) and I just wanted to check before I do the update to 2023.6.3? Many thanks

lahayeg commented 1 year ago

as temp solution I copy / paste change on my custom_components folder and restart... no more warning message

smarrk commented 1 year ago

Until the relevant PR (#116) is merged you can use my forked repo (containing the necessary fixes):
Remove the original integration and then add my forked one; restart afterwards.

! Do not forget to switch back to the original integration after the PR is merged !

jjanderson commented 1 year ago

cool thanks gents, is the only modified file sensor.py from what I can see?

smarrk commented 1 year ago

Yes, only sensors.py is affected. The fix basically is setting the state_class attribute only for the IAQ-Index entities. The PR additionally adjusts the tests, but that's is not relevant for the functionality of the integration.

jjanderson commented 1 year ago

cool, made the change and working like a charm, system now fully updated! I assume that when the component is updated and we update from HACS all the original repo source files will be restored as per this repo? Thanks all

Teleportist commented 1 year ago

Until the relevant PR (#116) is merged you can use my forked repo (containing the necessary fixes): Remove the original integration and then add my forked one; restart afterwards.

! Do not forget to switch back to the original integration after the PR is merged !

Thank you so much. Have swapped in the sensors.py file from your fork and all's well. Much appreciated