You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have both an Enviro (for inside) and an Enviro+ (for outside).
I am writing code to collect data from them. The same code will run on each device, with the only difference being that the Enviro+ also collects data from the gas sensor.
At the moment, I am using this rather nasty bit of code to detect if the gas sensor is available:
This works, however I am worried about what kind of exceptions might be thrown during read_all. Without the try/except, I get "OSError: [Errno 121] Remote I/O error" from the i2c code. I only hope that code is properly cleaning up after it fails to connect to the sensor, or that it doesn't modify anything.
It would be nice if the library provided a cleaner way to detect if the sensor is available. Something like an is_available method, which detects if the sensor is available/active before attempting to do anything with it.
I could be wrong, and my try/except method above is perfectly fine. But if that is the case then the library could just use that as the implementation of is_available.
The text was updated successfully, but these errors were encountered:
I can do the check just fine using exception handling. I just find that a bit icky. It would be better if the library could provide a way to check if the sensor is attached without having to try and read from it.
Insofar as I'm aware there's no way to check for the existence of an i2c device other than to attempt to read/write it- so the code you're using is correct. I agree that it would be worth having as a library feature, though.
Hello,
I have both an Enviro (for inside) and an Enviro+ (for outside).
I am writing code to collect data from them. The same code will run on each device, with the only difference being that the Enviro+ also collects data from the gas sensor.
At the moment, I am using this rather nasty bit of code to detect if the gas sensor is available:
This works, however I am worried about what kind of exceptions might be thrown during
read_all
. Without the try/except, I get "OSError: [Errno 121] Remote I/O error" from the i2c code. I only hope that code is properly cleaning up after it fails to connect to the sensor, or that it doesn't modify anything.It would be nice if the library provided a cleaner way to detect if the sensor is available. Something like an
is_available
method, which detects if the sensor is available/active before attempting to do anything with it.I could be wrong, and my try/except method above is perfectly fine. But if that is the case then the library could just use that as the implementation of
is_available
.The text was updated successfully, but these errors were encountered: