Closed henryruhs closed 3 years ago
Here comes my integration that includes a tempoary get_token
workaround:
Wanted code with a perfect setup of exceptions:
def api_factory(ip : str) -> Any:
api = None
try:
from nanoleafapi import Nanoleaf, NanoleafConnectionException, NanoleafRegistrationException
try:
api = Nanoleaf(ip, token)
except NanoleafConnectionException:
exit(wording.get('connection_no').format('NANOLEAF LIGHT') + wording.get('exclamation_mark'))
except NanoleafRegistrationException:
exit(wording.get('press_button').format('PAIRING', 'NANOLEAF LIGHT') + wording.get('exclamation_mark'))
return api
except ImportError:
exit(wording.get('package_no').format('NANOLEAF LIGHT') + wording.get('exclamation_mark'))
Implemented this in the latest package version (1.2.0), thanks for the suggestion!
Got your library running and works flawless accept the token handling.
It would be nice to have automated registration and storage of the token, on the first run an
NanoleafRegistrationException
should be thrown. The generalException
on false connection should also throw an more accurateNanoleafConnectionException
as pylint does not like except with undefinied exception type.I got use to this experience with
phue
that is made for Philips Hue and it's bridge:https://github.com/studioimaginaire/phue/blob/master/phue.py#L702-L722
It turns out they save the config file in the userspace according to the OS:
https://github.com/studioimaginaire/phue/blob/master/phue.py#L608-L615
This is how I integrated it - no need for token handling on my side what is perfect for a user:
https://github.com/redaxmedia/chroma-feedback/blob/master/chroma_feedback/consumer/philips_hue/api.py#L15-L29
@MylesMor Are you active on Discord? I tried to reach out to you for a live chat if you don't mind.