Add auto discovery for nanoleaf aurora lights#14301
Add auto discovery for nanoleaf aurora lights#14301MartinHjelmare merged 5 commits intohome-assistant:devfrom
Conversation
| if not token: | ||
| token = nanoleaf.setup.generate_auth_token(host) | ||
| if not token: | ||
| _LOGGER.error("""Could not generate the auth token, did you press |
There was a problem hiding this comment.
Use one pair of double quotes around the log string. Break the line by ending with a double quote, and then continue with a new double quote on the next line.
| return | ||
|
|
||
| add_devices([AuroraLight(aurora_light)], True) | ||
| else: |
There was a problem hiding this comment.
The else is not needed since there is a return above.
|
|
||
| add_devices([AuroraLight(aurora_light)], True) | ||
| else: | ||
| aurora_light.hass_name = name |
There was a problem hiding this comment.
Don't put the name as an instance attribute on the aurora light instance. Pass the name as an additional parameter when creating the entity instance.
| if conf.get(host, {}).get('token'): | ||
| token = conf[host]['token'] | ||
| elif config is not None: | ||
| host = config.get(CONF_HOST) |
There was a problem hiding this comment.
Don't use dict.get(key) on required keys or keys that have a default value. Use dict[key].
| conf = load_json(hass.config.path(CONFIG_FILE)) | ||
| if conf.get(host, {}).get('token'): | ||
| token = conf[host]['token'] | ||
| elif config is not None: |
There was a problem hiding this comment.
This will never be None. Setup via discovery will pass an empty dict for config. Change the check to else:.
| token = nanoleaf.setup.generate_auth_token(host) | ||
| if not token: | ||
| _LOGGER.error("Could not generate the auth token, did you press" | ||
| " and hold the power button on %s for 5-7 seconds?", name) |
There was a problem hiding this comment.
continuation line under-indented for visual indent
| token = nanoleaf.setup.generate_auth_token(host) | ||
| if not token: | ||
| _LOGGER.error("Could not generate the auth token, did you press " | ||
| "and hold the power button on %s for 5-7 seconds?", name) |
There was a problem hiding this comment.
line too long (83 > 79 characters)
|
(hopefully) all done, thank you for the review! |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Looks good. Last comment.
|
|
||
| DATA_NANOLEAF_AURORA = 'nanoleaf_aurora' | ||
|
|
||
| CONFIG_FILE = 'nanoleaf_aurora.conf' |
There was a problem hiding this comment.
If the config file is not supposed to be edited by users, we want it to be hidden, ie start with a dot.
|
I definitely borked up the pull request on the doc, sorry about that. Should not do something like that late at night; I'll most likely send another pull request tomorrow after I've gotten some sleep... |
Description:
Added auto discovery to the nanoleaf aurora platform
Related issue (if applicable): none
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5313
Example entry for
configuration.yaml(if applicable):discovery:Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: