aijayadams / hass-blueair

BlueAir sensor integration for HomeAssistant
34 stars 15 forks source link

[bug] List index out of range when only an air filter is registered #1

Closed piranha32 closed 2 years ago

piranha32 commented 3 years ago

In a configuration where there are no air quality sensors (only an air filter is registered), the component raises an exception during initialization:

2021-07-28 23:40:04 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up blueair platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/blueair/sensor.py", line 23, in setup_platform
BlueAirFilter(config=config, uuid=dev["uuid"], name=dev["name"], api=api)
File "/config/custom_components/blueair/sensor.py", line 41, in __init__
self.update()
File "/config/custom_components/blueair/sensor.py", line 67, in update
self._ba_attrs = self._api.get_current_data_point(self._ba_uuid)
File "/config/custom_components/blueair/blueair/blueair.py", line 185, in get_current_data_point
return results[-1]
IndexError: list index out of range

Call to the API returns the following record: {'uuid': <uuid>, 'start': 0, 'end': 0, 'sensors': ['time', 'pm', 'tmp', 'hum', 'co2', 'voc', 'allpollu'], 'units': ['s', 'ugm3', 'C', 'pc', 'ppm', 'ppb', '%'], 'datapoints': []}

results variable returned by transform_data_point is an empty list.

blueair command from the blueair python package returns the following list of device attributes:

auto_mode_dependency: pm
brightness: 4
child_lock: 0
fan_speed: 0
fan_usage: 2271;158;14196;269;14624;37216
filter_status: OK
mode: manual
wifi_status: 1
aijayadams commented 2 years ago

This issue should have been addressed by several recent patches around compatibility with classic models and not crashing the update_device calls when air sensor datapoints are not available or not in the expected format.