Skip to content

Add support for Nanoleaf Aurora Light Panels#13456

Merged
emlove merged 6 commits intohome-assistant:devfrom
Oro:light-aurora
Apr 6, 2018
Merged

Add support for Nanoleaf Aurora Light Panels#13456
emlove merged 6 commits intohome-assistant:devfrom
Oro:light-aurora

Conversation

@Oro
Copy link
Copy Markdown
Contributor

@Oro Oro commented Mar 25, 2018

Description:

Added support for Nanoleaf Aurora lights

Related issue (if applicable): None, discussion at https://community.home-assistant.io/t/nanoleaf-aurora-component/21054/

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5018

Example entry for configuration.yaml (if applicable):

light:
  - platform: aurora
    host: 192.168.1.10
    token: xxxxxxxxxxxxxxxxxxxxx

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@Oro
Copy link
Copy Markdown
Contributor Author

Oro commented Mar 26, 2018

seems like there was a recent change to RGB_COLOR and xy colors instead of rgb; I'll need to dig in to that to check (see #11288 )
Also it seems as if I am not importing modules within functions, which I'll also dig in soon (this weekend hopefully)
I'd appreciate any and all pointers

@Oro Oro changed the title Added support for Nanoleaf Aurora Light Panels WIP - Add support for Nanoleaf Aurora Light Panels Mar 27, 2018
@Oro Oro changed the title WIP - Add support for Nanoleaf Aurora Light Panels Add support for Nanoleaf Aurora Light Panels Mar 30, 2018
Copy link
Copy Markdown
Contributor

@emlove emlove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great work! I've just added a few comments here for best practices.

host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
token = config.get(CONF_TOKEN)
aurora_light = aurora().Aurora(host, token)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just import nanoleaf in setup_platform. The wrapper isn't necessary.


def __init__(self, light):
"""Initialize an Aurora."""
self._brightness = light.brightness
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the update logic here, just assign self._light ans self._name, and then pass True as the second argument (update_before_add) of add_devices. Hass will then call update before adding the entity to the state machine.

Example:
https://github.com/home-assistant/home-assistant/blob/a502c4db3485cc2ec9f9755e6ea28d6713cf6c66/homeassistant/components/light/iglo.py#L39

@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return "mdi:triangle-outline"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about overriding the icon for a light, but no strong feelings myself if it's aligned with the actual device. Could you add some screenshots of what this looks like in a card?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like it since the device itself is a triangle, however this is more of a special snowflake kind of situation, so if you'd like to keep this as a regular light bulb I'll happily oblige.

It looks like this (I hope it's okay to attach it here, I don't think it fits into the documentation itself):
screen shot 2018-04-04 at 15 36 19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks nice to me, and these aren't normal lights, so a different icon seems reasonable to me.

image

@Oro
Copy link
Copy Markdown
Contributor Author

Oro commented Apr 4, 2018

@armills Thanks for the review and the comments!
pylint now results in

W:146, 8: Attribute '_hs_color' defined outside init (attribute-defined-outside-init)

I'd simply __init__ them with None instead of leaving them out, would that be OK as well?

@emlove
Copy link
Copy Markdown
Contributor

emlove commented Apr 4, 2018

Ah yeah, that's my mistake. They should be initialized to None in the constructor.

@Norien
Copy link
Copy Markdown

Norien commented Apr 4, 2018

This is working great for me on .66 thanks for all you do. I was just wondering if it's possible to get the motion sensor exposed to use with automations!

@Oro
Copy link
Copy Markdown
Contributor Author

Oro commented Apr 6, 2018

@Norien glad it works!
if possible, please use the community thread for requests (I'm also monitoring it) https://community.home-assistant.io/t/nanoleaf-aurora-component/21054/

@emlove emlove merged commit 0a25d30 into home-assistant:dev Apr 6, 2018
@emlove
Copy link
Copy Markdown
Contributor

emlove commented Apr 6, 2018

Thanks for the contribution! 🌟

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting for possible improvement in a future PR.

https://github.com/software-2/nanoleaf

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.nanoleaf_aurora/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The url is wrong. It should end with the platform name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I get it. There is no platform for the nanoleaf aurora lights, there is however a aurora sensor which has nothing to do with those lights (which is why I named the documentation light.nanoleaf_aurora) - did I misunderstand something/do something incorrectly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the platform module is aurora.py. Then you have to name the docs page https://home-assistant.io/components/light.aurora/ eg.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it now, thanks - If I rename it to aurora the component page will display a link to the binary sensor, thinking they are related, is there a way to overwrite that behaviour or do you recon that this is OK? - if not, I will probably have to rename the component itself

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we shouldn't have two platforms with the same name that are not connected. Please rename this platform. nanoleaf_aurora.py is ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've renamed it in #13831 , for the others I'll create separate PRs as well, if possible it would be great if this could get in 0.67 so that nobody has to update their config in the version following afterwards

if aurora_light.on is None:
_LOGGER.error("Could not connect to \
Nanoleaf Aurora: %s on %s", name, host)
add_devices([AuroraLight(aurora_light)], True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want to add devices if the above error happens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, my mistake - I'll send a PR hopefully this weekend

name = config.get(CONF_NAME)
token = config.get(CONF_TOKEN)
aurora_light = nanoleaf.Aurora(host, token)
aurora_light.hass_name = name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why put the name on the aurora light instance? You can pass the name separately when instantiating the entity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very good question, probably not needed. I'll have a look at it this weekend, thank you for the comments!

@balloob balloob mentioned this pull request Apr 13, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants