bachya / pyairvisual

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

Randomly stopped connecting #67

Closed scstraus closed 3 years ago

scstraus commented 3 years ago

Describe the bug Today in the morning the component stopped connecting to both my airvisual nodes and didn't update sensors all day. I can mount the SMB shares on both devices and can ping from my homeassistant server.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

here's the traceback:


Logger: homeassistant.components.airvisual
Source: components/airvisual/__init__.py:250
Integration: AirVisual (documentation, issues)
First occurred: November 28, 2020, 1:14:41 AM (8 occurrences)
Last logged: November 28, 2020, 8:08:33 AM

    Unexpected error fetching Node/Pro data data: [Errno 110] Operation timed out
    Unexpected error fetching Node/Pro data data: [Errno 113] Host is unreachable

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 144, in async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 132, in _async_update_data
    return await self.update_method()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
    async with NodeSamba(
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
    await self.async_connect()
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
    await self._loop.run_in_executor(None, connect)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
    self._conn.connect(self._ip_or_hostname)
  File "/usr/local/lib/python3.8/site-packages/smb/SMBConnection.py", line 113, in connect
    self.sock.connect(( ip, port ))
TimeoutError: [Errno 110] Operation timed out
bachya commented 3 years ago

These lines stand out:

Unexpected error fetching Node/Pro data data: [Errno 110] Operation timed out
Unexpected error fetching Node/Pro data data: [Errno 113] Host is unreachable

The integration can't reach the Samba port on the Node. Can you mount the shares from the Home Assistant machine itself?

scstraus commented 3 years ago

Not sure I have what's needed as the strict new rules for supervised support mean I can't install stuff like that on the server. Anyhow, I confirmed I could reach it from the server, and could mount from my PC on the same subnet. Then after not getting any updated sensor for 13 hours, I restarted hass and the sensor immediately started updating again.. Looks to me like something in the backend crashed and wouldn't allow hass specifically to reach the server by SMB.. Maybe the SMB subsystem in hass failed somehow?

scstraus commented 3 years ago

All network problems solved by a hass restart 5 minutes ago? It was able to reach every other device on my network (of which there are many).

image image

bachya commented 3 years ago

Got it. Not sure what to do with that just yet. Might be worthwhile setting DEBUG-level logging for homeassistant.components.airvisual and pyairvisual for a while; if this happens again, that surrounding info might perhaps clue us in.

scstraus commented 3 years ago

I've got debug as default on everything. If it happens again I will try to grab a bigger snippet.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

scstraus commented 3 years ago

Haven't had the problem lately. Seemed like it happened one more time but I didn't get logs.. May have been hass version specific. I'll close it for now and re-open if it happens again.

bachya commented 3 years ago

New report from @scstraus:

Describe the bug This is just a reopening of #67. Today in the morning the component stopped connecting to both my airvisual nodes and didn't update sensors all day. I can mount the SMB shares on both devices and can ping from my homeassistant server.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

here's the log from when it switched from working to not working. It continues like the bottom until I restart:

2021-03-31 02:17:34 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.128 seconds
2021-03-31 02:18:02 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:18:02 DEBUG (MainThread) [pyairvisual.node] Node Pro measurements loaded: {'date_and_time': {'date': '2021/03/31', 'time': '02:15:30', 'timestamp': '1617156930'}, 'measurements': {'co2': '724', 'humidity': '38', 'pm0_1': '3', 'pm1_0': '6', 'aqi_cn': '9', 'aqi_us': '25', 'pm2_5': '6.0', 'temperature_C': '23.4', 'temperature_F': '74.1', 'voc': '-1'}, 'serial_number': 'TKKGJWV', 'settings': {'follow_mode': 'device', 'followed_station': 'qhofpkt2', 'is_aqi_usa': True, 'is_concentration_showed': False, 'is_indoor': True, 'is_lcd_on': False, 'is_network_time': True, 'is_temperature_celsius': True, 'language': 'en-GB', 'lcd_brightness': 100, 'node_name': 'Home', 'power_saving': {'2slots': [{'hour_off': 9, 'hour_on': 7}, {'hour_off': 22, 'hour_on': 18}], 'mode': 'yes', 'running_time': 99, 'yes': [{'hour': 8, 'minute': 0}, {'hour': 21, 'minute': 0}]}, 'sensor_mode': {'custom_mode_interval': 5, 'mode': 2}, 'speed_unit': 'mph', 'timezone': 'Europe/Prague'}, 'status': {'app_version': '1.1651', 'battery': 100, 'datetime': 1617156930, 'device_name': 'AIRVISUAL-TKKGJWV', 'ip_address': '10.10.10.140', 'mac_address': '54c9dfd65a20', 'model': '20', 'sensor_life': {'pm2_5': 1529984983665}, 'sensor_pm25_serial': '00000005041102031047', 'sync_time': 250000, 'system_version': 'KBG60F82', 'used_memory': 3, 'wifi_strength': 5}}
2021-03-31 02:18:02 INFO (MainThread) [homeassistant.components.airvisual] Fetching Node/Pro data data recovered
2021-03-31 02:18:02 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.157 seconds
2021-03-31 02:18:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.airvisual_home_battery, old_state=<state sensor.airvisual_home_battery=unavailable; unit_of_measurement=%, friendly_name=Home Node/Pro: Battery, device_class=battery @ 2021-03-31T02:17:02.060840+02:00>, new_state=<state sensor.airvisual_home_battery=100; attribution=Data provided by AirVisual, unit_of_measurement=%, friendly_name=Home Node/Pro: Battery, device_class=battery @ 2021-03-31T02:18:02.272170+02:00>>
2021-03-31 02:18:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.airvisual_home_humidity, old_state=<state sensor.airvisual_home_humidity=unavailable; unit_of_measurement=%, friendly_name=Home Node/Pro: Humidity, device_class=humidity @ 2021-03-31T02:17:02.061000+02:00>, new_state=<state sensor.airvisual_home_humidity=38; attribution=Data provided by AirVisual, unit_of_measurement=%, friendly_name=Home Node/Pro: Humidity, device_class=humidity @ 2021-03-31T02:18:02.272418+02:00>>
2021-03-31 02:18:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.home_airvisual_temperature, old_state=<state sensor.home_airvisual_temperature=unavailable; unit_of_measurement=°C, friendly_name=Home Node/Pro: Temperature, device_class=temperature @ 2021-03-31T02:17:02.061155+02:00>, new_state=<state sensor.home_airvisual_temperature=23.4; attribution=Data provided by AirVisual, unit_of_measurement=°C, friendly_name=Home Node/Pro: Temperature, device_class=temperature @ 2021-03-31T02:18:02.272620+02:00>>
2021-03-31 02:18:02 DEBUG (MainThread) [homeassistant.components.alexa.state_report] Not exposing sensor.home_airvisual_temperature because filtered by config
2021-03-31 02:18:34 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:18:34 DEBUG (MainThread) [pyairvisual.node] Node Pro measurements loaded: {'date_and_time': {'date': '2021/03/31', 'time': '02:03:50', 'timestamp': '1617156230'}, 'measurements': {'co2': '451', 'humidity': '59', 'aqi_cn': '21', 'aqi_us': '57', 'pm2_5': '15.0', 'temperature_C': '10.3', 'temperature_F': '50.5', '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': 1617156230, 'model': '10', 'sensor_pm25_serial': '00000110030927030221', 'sync_time': 860000, 'system_version': 'KBG57F70', 'used_memory': 0, 'wifi_strength': 4, 'sensor_life': {}}}
2021-03-31 02:18:34 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.236 seconds
2021-03-31 02:19:02 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:19:02 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:19:02 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.018 seconds
2021-03-31 02:19:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.airvisual_home_battery, old_state=<state sensor.airvisual_home_battery=100; attribution=Data provided by AirVisual, unit_of_measurement=%, friendly_name=Home Node/Pro: Battery, device_class=battery @ 2021-03-31T02:18:02.272170+02:00>, new_state=<state sensor.airvisual_home_battery=unavailable; unit_of_measurement=%, friendly_name=Home Node/Pro: Battery, device_class=battery @ 2021-03-31T02:19:02.040527+02:00>>
2021-03-31 02:19:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.airvisual_home_humidity, old_state=<state sensor.airvisual_home_humidity=38; attribution=Data provided by AirVisual, unit_of_measurement=%, friendly_name=Home Node/Pro: Humidity, device_class=humidity @ 2021-03-31T02:18:02.272418+02:00>, new_state=<state sensor.airvisual_home_humidity=unavailable; unit_of_measurement=%, friendly_name=Home Node/Pro: Humidity, device_class=humidity @ 2021-03-31T02:19:02.040719+02:00>>
2021-03-31 02:19:02 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.home_airvisual_temperature, old_state=<state sensor.home_airvisual_temperature=23.4; attribution=Data provided by AirVisual, unit_of_measurement=°C, friendly_name=Home Node/Pro: Temperature, device_class=temperature @ 2021-03-31T02:18:02.272620+02:00>, new_state=<state sensor.home_airvisual_temperature=unavailable; unit_of_measurement=°C, friendly_name=Home Node/Pro: Temperature, device_class=temperature @ 2021-03-31T02:19:02.040823+02:00>>
2021-03-31 02:19:02 DEBUG (MainThread) [homeassistant.components.alexa.state_report] Not exposing sensor.home_airvisual_temperature because filtered by config
2021-03-31 02:19:34 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:19:34 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:19:34 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.022 seconds
2021-03-31 02:20:02 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:20:02 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:20:02 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.008 seconds
2021-03-31 02:20:34 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:20:34 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:20:34 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.003 seconds
2021-03-31 02:21:02 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:21:02 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:21:02 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.007 seconds
2021-03-31 02:21:34 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
2021-03-31 02:21:34 ERROR (MainThread) [homeassistant.components.airvisual] Unexpected error fetching Node/Pro data data: filedescriptor out of range in select()
  File "/usr/src/homeassistant/homeassistant/components/airvisual/__init__.py", line 250, in async_update_data
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 137, in __aenter__
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 175, in async_connect
  File "/usr/local/lib/python3.8/site-packages/pyairvisual/node.py", line 172, in connect
2021-03-31 02:21:34 DEBUG (MainThread) [homeassistant.components.airvisual] Finished fetching Node/Pro data data in 0.008 seconds
2021-03-31 02:22:02 INFO (MainThread) [SMB.SMBConnection] Authentication with remote machine "AIRVISUAL" for user "airvisual" will be using NTLM v2 authentication (with extended security)
bachya commented 3 years ago

@scstraus I'm still not experiencing this myself, unfortunately. This appears to be related to the underlying Samba connection and pyairvisual happens to be using an older version of pysmb. One troubleshooting idea for you would be to manually upgrade it:

$ pip3 install -U pysmb

...and see if any issues reappear after awhile.

scstraus commented 3 years ago

I’m trying to keep my supervised installation “supported” so I’m really trying not to install any individual packages other than the required ones on the machine.

bachya commented 3 years ago

You can run a second instance?

scstraus commented 3 years ago

I guess i could put one on a Mac or something. Sounds like you want me to run core on bare metal, yes?

bachya commented 3 years ago

Doesn't have to be bare metal – the container would work, too. Any option that would allow you to upgrade pysmb.

scstraus commented 3 years ago

Would I install it inside the container or outside the container on base os?

bachya commented 3 years ago

It would be installed in the container.

scstraus commented 3 years ago

Oh in that case I don’t mind doing it to my main instance. Let me see if those tools are actually there to do it.

scstraus commented 3 years ago

I'm going to upgrade before doing this and wait for it to hang again before monkeying with the SMB version. In the meantime, I noticed this is the supervisor logs, seems like it could be related. I've never installed any addon related to samba, so must be some kind of system addon.

21-04-18 21:58:24 WARNING (MainThread) [supervisor.addons.addon] Add-on core_samba new schema is not compatible 21-04-18 21:58:24 WARNING (MainThread) [supervisor.misc.tasks] Add-on core_samba will be ignored, schema tests failed

bachya commented 3 years ago

There is no AirVisual-related HASS add-on. It's entirely possible that something with the supervisor is tangling with something in this library, but since I'm not a supervisor user, I can't validate that.

scstraus commented 3 years ago

I realized I actually was running the samba addon. Thought I had been accessing it on the system level but I was wrong. Probably just need to hit update . Will do it after system update.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

scstraus commented 3 years ago

I haven't had this issue yet on 2021.6. I will close until the next time.