Is this capable of checking if a smart plug is plugged in? #126
-
Is this capable of checking if a smart plug is plugged in without an error that crashes within a try except clause. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I'm not sure I understand your issue, could you elaborate what are you trying to do and what is failing? Do you mean not raising an exception if the device is unavailable (ie., unplugged from mains), or something else? What is your expected behavior if the device cannot be reached? |
Beta Was this translation helpful? Give feedback.
-
I am curious if there is an easy way to detect if the device is on the network/plugged in with this or if I should just use something like this instead. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((self.ras_pi, 22))
if result == 0:
print("Raspberry Pi is running") I will admit I just realized I could use this so I may have not needed to check for this function within this module at all. |
Beta Was this translation helpful? Give feedback.
Or you could simple ping the device :-)
This library is more aimed to control & read information from those devices and not really aimed for connectivity tracking.
Anyway, to answer your question, something like this should work with this library:
The exception block catches all exceptions (e.g., maybe there is a device in the given address, but it isn't a supported one and replies with something unexpected) which may be too wide depending on what exactly (an…