bachya / pyairvisual

☀️ A simple, clean, well-tested Python library for interacting with AirVisual©
MIT License
9 stars 4 forks source link

Not working with node pro in hass .116.3 #60

Closed scstraus closed 3 years ago

scstraus commented 3 years ago

Describe the bug Can create the integration, but it will not spawn any entities

To Reproduce Add air visual node pro integration, and look for entities.

Expected behavior Creating entities.

Additional context Here's a traceback:

020-10-16 00:01:53 DEBUG (MainThread) [pyairvisual.node] Node Pro measurements loaded: {'date_and_time': {'date': '2020/10/15', 'time': '23:47:20', 'timestamp': '1602805640'}, 'measurements': {'co2': '402', 'humidity': '89', 'aqi_cn': '6', 'aqi_us': '17', 'pm2_5': '4.0', 'temperature_C': '10.8', 'temperature_F': '51.4', 'voc': '-1'}, 'serial_number': 'SXP9JKS', 'settings': {'followed_station': '8262', 'is_aqi_usa': True, 'is_concentration_showed': True, 'is_indoor': False, 'is_lcd_on': False, 'is_network_time': True, 'is_temperature_celsius': True, 'language': 'en-GB', 'lcd_brightness': 40, 'node_name': 'hlubocepy', 'power_saving': {'2slots': [{'hour_off': 9, 'hour_on': 7}, {'hour_off': 22, 'hour_on': 18}], 'mode': 'yes', 'yes': [{'hour': 7, 'minute': 0}, {'hour': 21, 'minute': 0}]}, 'speed_unit': 'mph', 'timezone': 'Europe/Prague'}, 'status': {'app_version': '1.1532', 'battery': 100, 'datetime': 1602805640, 'model': '10', 'sensor_pm25_serial': '00000110030927030221', 'sync_time': 860000, 'system_version': 'KBG57F70', 'used_memory': 0, 'wifi_strength': 4}}
2020-10-16 00:01:53 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetc
hing Node/Pro data data: 'sensor_life'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 143, in async_r
efresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 131, in _async_
update_data
    return await self.update_method()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 275, in asyn
c_update_data
    return await node.async_get_latest_measurements()
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 219, in async_get_lates
t_measurements
    for pollutant, value in data["status"]["sensor_life"].items()
KeyError: 'sensor_life'
2020-10-16 00:01:53 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Nod
e/Pro data data in 0.114 seconds
2020-10-16 00:01:53 INFO (SyncWorker_14) [homeassistant.loader] Loaded air_quality from homeassis
tant.components.air_quality
2020-10-16 00:01:53 INFO (MainThread) [homeassistant.setup] Setting up air_quality
2020-10-16 00:01:53 INFO (MainThread) [homeassistant.setup] Setup of domain air_quality took 0.0 
seconds
bachya commented 3 years ago

Interesting – the JSON file on your unit is missing the sensor_life key. I wonder (a) if that will happen sporadically going forward and (b) what other fields may come and go without warning...

I'll put a guard in place around sensor_life and see how that treats us.

scstraus commented 3 years ago

Thank you.

scstraus commented 3 years ago

Just installed .117.1, but still having a similar error. Has the fix made it in yet (I wish I could figure out how to tell when a PR actually gets published into a release).

Here's the traceback:

2020-11-01 00:29:28 ERROR (MainThread) [homeassistant.components.sensor] airvisual: Error on device updat
e!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 357, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 235, in async_update
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 126, in async_request_r
efresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 73, in async_call
    await self.hass.async_add_hass_job(self._job)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 193, in async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 414, in update
    self.update_from_latest_data()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/air_quality.py", line 105, in update_from_latest_data
    for pollutant, lifespan in self.coordinator.data["status"][
KeyError: 'sensor_life'
bachya commented 3 years ago

@scstraus I made a good fix here, but totally neglected to make the proper adjustment in HASS. 🤦 I'll fix that now.

bachya commented 3 years ago

@scstraus Alright, this will get into 0.117.3: https://github.com/home-assistant/core/pull/42760