Airthings / airthings-ble

Library to control Airthings devices through BLE, primarily meant to be used in Home Assistant.
MIT License
21 stars 11 forks source link

AirThings hardware sometimes omits data #12

Closed WillCodeForCats closed 1 year ago

WillCodeForCats commented 1 year ago

Describe the bug Sometimes the airthings hardware does not include a given data point in a polling cycle with Home Assistant that it previously has, which causes a key not to be populated and raises an uncaught exception within in Home Assistant. It's relatively uncommon and does not persist long, but it does happen.

To Reproduce Steps to reproduce the behavior:

1) Let an Airthings BLE device run and observe it until it randomly happens.

Additional context Claimed to be a library bug although I don't really think it is, and I believe it could be handled gracefully (and trivially) within HA by a simple try/except when returning native_value for the sensor.

Ref: https://github.com/home-assistant/core/pull/96735

Logs:

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 229, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 374, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 431, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 478, in state
value = self.native_value
^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/airthings_ble/sensor.py", line 186, in native_value
return self.coordinator.data.sensors[self.entity_description.key]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'illuminance'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 229, in _handle_refresh_interval
await self._async_refresh(log_failures=True, scheduled=True)
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 374, in _async_refresh
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 431, in _handle_coordinator_update
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 810, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 478, in state
value = self.native_value
^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/airthings_ble/sensor.py", line 186, in native_value
return self.coordinator.data.sensors[self.entity_description.key]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'radon_1day_level'
vincegio commented 1 year ago

Thanks for this issue and the PR you sent to core, sent a reply so we'll keep this issue open until we get an answer from them there :+1:

WillCodeForCats commented 1 year ago

Marked https://github.com/home-assistant/core/pull/96735 as ready, hopefully it will be accepted this time.

WillCodeForCats commented 1 year ago

Closing because this was never a library bug and the PR is stuck facing constant delays in spite of my efforts to quickly address them.