Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please implement PhueConnectionException and fix PhueRequestTimeout #157

Open
henryruhs opened this issue Jul 12, 2019 · 0 comments
Open

Comments

@henryruhs
Copy link

henryruhs commented Jul 12, 2019

Hello,

passing various invalid strings to the constructor is causing different errors and exceptions:

  1. ip = 1.1.1 ~ OSError: [Errno 101] Network is unreachable
  2. ip = 1.1.1.1 ~ json.decoder.JSONDecodeError: Expecting value
  3. ´ip = invalid` ~ socket.gaierror: [Errno -2] Name or service not known
  4. PhueRequestTimeout does not always catch socket.timeout for some reason
  5. Using an ip that does not exist causes socket.timeout on line 743, in connectand line 652, in request

it would be nice to have the following exceptions to be thrown:

  1. Discovery failed while using Bridge() so throw PhueConnectionException
  2. Socket that don't respond should throw PhueTimeoutException
  3. Keep the PhueRegistrationException

Hacky solution that is currently working properly accept random socket.timeout:

def bridge_factory(ip):
	bridge = None

	# handle import

	try:
		from phue import Bridge, PhueRegistrationException, PhueRequestTimeout
	except ImportError:
		exit(wording.get('package_no').format('PHUE') + wording.get('exclamation_mark'))

	# create instance

	try:
		bridge = Bridge(ip)
	except (PhueRequestTimeout, OSError, ValueError):
		exit(wording.get('connection_no').format('PHILIPS HUE') + wording.get('exclamation_mark'))
	except PhueRegistrationException:
		exit(wording.get('press_button').format('PAIRING', 'PHILIPS HUE BRIDGE') + wording.get('exclamation_mark'))
	return bridge

Wanted solution that throws PhueConnectionException, PhueTimeoutException and PhueRegistrationException:

def bridge_factory(ip):
	bridge = None

	# handle import

	try:
		from phue import Bridge, PhueRegistrationException, PhueTimeoutException
	except ImportError:
		exit(wording.get('package_no').format('PHUE') + wording.get('exclamation_mark'))

	# create instance

	try:
		bridge = Bridge(ip)
	except (PhueConnectionException, PhueTimeoutException):
		exit(wording.get('connection_no').format('PHILIPS HUE') + wording.get('exclamation_mark'))
	except PhueRegistrationException:
		exit(wording.get('press_button').format('PAIRING', 'PHILIPS HUE BRIDGE') + wording.get('exclamation_mark'))
	return bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant