bastienleonard / pysensors

Easy Linux hardware monitoring in Python
https://bastienleonard.github.io/pysensors
Other
29 stars 8 forks source link

SensorsException when WiFi NIC is rfkilled #5

Closed kyrias closed 3 years ago

kyrias commented 7 years ago

When my intel WiFi NICs are rfkilled sensorsd can't get the temperature anymore it seems, and when my i3 bar tries to get the value for the sensors.SUBFEATURE_TEMP_INPUT subfeature I get an exception raised:

sensors.SensorsException: I/O error
kyrias commented 7 years ago

Preferably if it's possible to detect that something like this is the case it would either return None, or raise a specific error that could just be ignored. Preferably it would be possible to check whether it is possible to get the value before actually trying to get the value and getting the exception thrown at you though.

bastienleonard commented 7 years ago

Glad to know that some people use this project!

It looks like libsensors only provides an error string, with no way to know if the error is somewhat fatal or not. One possibility would be to add a method that returns None in case of error, with no way to get the error description. What's wrong with using a try/except block, though?

kyrias commented 7 years ago

What's wrong is mostly that it's not really clear that you really do need to have it around the get_value calls and such, since it's not documented that it can and will raise exceptions, so code using it isn't properly protected against it.

bastienleonard commented 7 years ago

Is get_value() called from this project? https://github.com/enkore/i3pystatus/ https://i3pystatus.readthedocs.io/en/latest/i3pystatus.html#temp

From what I remember, the libsensors documentation is pretty minimal as well and there is no way to know the error cases other than trial and error.

I see two possible actions:

In any case, i3pystatus will need to be updated.

kyrias commented 7 years ago

Yeah. I think any of the solutions would be acceptable, though get_value_or_none would likely be most useful and userfriendly.