StephanJoubert / home_assistant_solarman

Home Assistant component for Solarman collectors used with a variety of inverters.
Apache License 2.0
524 stars 194 forks source link

UnboundLocalError causes sensors to stop updating #218

Open dagwud opened 1 year ago

dagwud commented 1 year ago

Symptoms: sensors have not been updated in a while, ie the values are not changing to reflect current load.

I then found this in the logs. It looks as if it happens sporadically, with the last logged time approximately matching the last update of the sensors

First occurred: 03:39:05 (389 occurrences) 
Last logged: 05:47:58

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 548, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_device_update
    raise exc
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/solarman/sensor.py", line 140, in update
    self.inverter.update()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 190, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/solarman/solarman.py", line 175, in update
    self.get_statistics()
  File "/config/custom_components/solarman/solarman.py", line 234, in get_statistics
    sock.close()
UnboundLocalError: local variable 'sock' referenced before assignment
dagwud commented 1 year ago

This may or may not be related - ie perhaps just a timeout that could be handled more gracefully


Logger: custom_components.solarman.solarman
Source: custom_components/solarman/solarman.py:175 
Integration: solarman ([documentation](https://github.com/StephanJoubert/home_assistant_solarman/blob/main/README.md), [issues](https://github.com/StephanJoubert/home_assistant_solarman/issues)) 
First occurred: 03:39:05 (502 occurrences) 
Last logged: 05:54:31

Querying failed on connection start with exception [OSError]
Querying registers [150 - 248] failed, aborting.
Querying failed on connection start with exception [TimeoutError]
Querying registers [3 - 112] failed, aborting.