mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.38k stars 479 forks source link

Catching ANY Broadlink Exception with a Base Exception #706

Closed bytos closed 2 years ago

bytos commented 2 years ago

What are the possible exceptions for each of these functions (RM4 Mini remote): hello(), auth(), check_temperature(), check_humidity(), send(), learn().

No knowing which functions can generate a given exception, prefer to simply catch any exception with a base exception and print error text.

felipediel commented 2 years ago

You can do it with BroadlinkException. Here's a list of all exceptions https://github.com/mjg59/python-broadlink/blob/a86e9cbb9ce44c25485226d46541a1cdcff940b7/broadlink/exceptions.py#L114-L136.

bytos commented 2 years ago

To avoid debugging the library, I'd have to test for all/some each time I try to blindly catch any exceptions.

Is there a document where it is indicated which exceptions can be raised by each function in the library (suspicion is no from older posts)?

You are supposed to catch "expected" exceptions, but they can't be expected if you don't know which exceptions are raised by a function.

Ended up catching any exceptions (not using BL exceptions) because it is shorter.

felipediel commented 2 years ago

Most of them come from the firmware. There is no manual, at least we don't have access to it. In Home Assistant we usually catch BroadlinkException and use specific exceptions in known cases.

bytos commented 2 years ago

Thanks for the info. My application works standalone and is responsible for turning off equipment, hence, the need to know the options.