Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Renpho Air Purifier AQI sensor, since AQI is deprecated. #1832

Merged
merged 1 commit into from Apr 16, 2024

Conversation

ThomasADavis
Copy link
Contributor

This fixes the deprecated AQI sensor setting in the Renpho Air Purifier, changing it from AQI to enum with a string mapping.

I've tested this against my purifiers, and it works.

@make-all
Copy link
Owner

Where are you seeing that aqi device class is deprecated? It is not mentioned in the documentation, and there is no blog post about it.

@ThomasADavis
Copy link
Contributor Author

@ThomasADavis
Copy link
Contributor Author

HA Also complains about it, and this fixes it.

@ThomasADavis
Copy link
Contributor Author

2024-04-15T23:04:51.665447134Z stderr F Traceback (most recent call last):
2024-04-15T23:04:51.665459399Z stderr F   File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 663, in state
2024-04-15T23:04:51.665470968Z stderr F     numerical_value = int(value)
2024-04-15T23:04:51.665479594Z stderr F                       ^^^^^^^^^^
2024-04-15T23:04:51.665487362Z stderr F ValueError: invalid literal for int() with base 10: 'fair'
2024-04-15T23:04:51.665497337Z stderr F 
2024-04-15T23:04:51.66550908Z stderr F During handling of the above exception, another exception occurred:
2024-04-15T23:04:51.665516559Z stderr F 
2024-04-15T23:04:51.665523304Z stderr F Traceback (most recent call last):
2024-04-15T23:04:51.665530194Z stderr F   File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 666, in state
2024-04-15T23:04:51.66553731Z stderr F     numerical_value = float(value)
2024-04-15T23:04:51.66555869Z stderr F                       ^^^^^^^^^^^^
2024-04-15T23:04:51.665570215Z stderr F ValueError: could not convert string to float: 'fair'
2024-04-15T23:04:51.665577895Z stderr F 
2024-04-15T23:04:51.665584857Z stderr F The above exception was the direct cause of the following exception:
2024-04-15T23:04:51.665594667Z stderr F 
2024-04-15T23:04:51.665605129Z stderr F Traceback (most recent call last):
2024-04-15T23:04:51.665613561Z stderr F   File "/config/custom_components/tuya_local/device.py", line 218, in receive_loop
2024-04-15T23:04:51.665620872Z stderr F     entity.async_write_ha_state()
2024-04-15T23:04:51.665632446Z stderr F   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
2024-04-15T23:04:51.665643218Z stderr F     self._async_write_ha_state()
2024-04-15T23:04:51.665650902Z stderr F   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
2024-04-15T23:04:51.665657872Z stderr F     state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
2024-04-15T23:04:51.665664817Z stderr F                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-15T23:04:51.665671888Z stderr F   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1056, in __async_calculate_state
2024-04-15T23:04:51.665682223Z stderr F     state = self._stringify_state(available)
2024-04-15T23:04:51.665690032Z stderr F             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-04-15T23:04:51.665697015Z stderr F   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in _stringify_state
2024-04-15T23:04:51.665703888Z stderr F     if (state := self.state) is None:
2024-04-15T23:04:51.665710814Z stderr F                  ^^^^^^^^^^
2024-04-15T23:04:51.665718093Z stderr F   File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 670, in state
2024-04-15T23:04:51.66572912Z stderr F     raise ValueError(
2024-04-15T23:04:51.665740542Z stderr F ValueError: Sensor sensor.master_air_purifier_air_quality has device class 'aqi', state class 'None' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'fair' (<class 'str'>)
``` is what this fixes.

@ThomasADavis
Copy link
Contributor Author

From the sensor classes, AQI according to the docs has no units defined..

SensorDeviceClass.AQI	None	Air Quality Index

but it wants an int/float, not a string.

@make-all
Copy link
Owner

I see they have added a list of non-numeric device classes, and aqi is not among them. I guess it does make sense, since the I in AQI stands for index, so it should really be numeric, even though many devices have something labelled AQI which is a good/fair/poor categorisation like this.

@make-all make-all merged commit 3fed0fe into make-all:main Apr 16, 2024
4 checks passed
make-all added a commit that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants