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

Update Avi-On to work with latest API #17780

Merged
merged 6 commits into from Oct 29, 2018

Conversation

@antsar
Contributor

antsar commented Oct 25, 2018

Description:

The light.avion component supports two ways of configuration: username/password (a web API is used to retrieve all device metadata), or manually enumerating devices by MAC address and ID. The Avi-On web API has changed, and the Home Assistant integration can no longer fetch devices. This PR updates Home Assistant to work with the new API.

Related issue (if applicable): fixes #17779

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

Example entry for configuration.yaml (if applicable):

This PR does not impact configuration. See current example config here.

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). N/A
  • New dependencies are only imported inside functions that use them (example). N/A
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py. N/A
  • New files were added to .coveragerc. N/A

If the code does not interact with devices:

  • Tests have been added to verify that the new code works. N/A

@antsar antsar force-pushed the antsar:avion-update branch from 983f3f2 to 25a2991 Oct 25, 2018


for address, device_config in config[CONF_DEVICES].items():
device = {}
device['name'] = device_config[CONF_NAME]
device['name'] = device_config.get(CONF_NAME, None)

This comment has been minimized.

@rohankapoorcom

rohankapoorcom Oct 25, 2018

Contributor

It's better to locate your default in the vol.Optional call so that you can use the [] method of accessing rather than needing to use .get() and passing in a default.

device['key'] = device_config[CONF_API_KEY]
device['address'] = address
device['id'] = device_config.get(CONF_ID, None)

This comment has been minimized.

@rohankapoorcom

rohankapoorcom Oct 25, 2018

Contributor

As above.


from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light,
PLATFORM_SCHEMA)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['avion==0.7']
REQUIREMENTS = ['antsar-avion==0.9']

This comment has been minimized.

@fabaff

fabaff Oct 25, 2018

Member

Why are you changing the requirement?

This comment has been minimized.

@antsar

antsar Oct 25, 2018

Contributor

@fabaff thanks for noticing/asking. I'm curious if I've gone about this the right way.

I've opened a PR making the necessary changes to avion. Since this vendor API change breaks the library, I thought I'd switch to my fork in the meantime to keep Home Assistant working. The author seems like a busy guy (my last PR took a few months to get merged).

avion PR: mjg59/python-avion#9
Previous avion PR : mjg59/python-avion#8 (merged, but I later realized the fix was incomplete)

Is switching a bad way to handle this? If it's preferable to wait for the avion PR to get merged, I'm ok with that.

Edit: If/when the upstream changes are merged, I'd want to change this back anyway. I had no intention of hijacking the library long-term.

This comment has been minimized.

@fabaff

fabaff Oct 25, 2018

Member

Is switching a bad way to handle this?

No, can be done especially If bugs are not addressed or the developer/maintainer is non-responsive. If @mjg59 is busy then we can go on with your fork. Would be nice if you could address those two things in your fork:

Also, I would like to suggest that you update the README in your fork with to make it clear that's a fork.

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Oct 25, 2018

Member

@antsar Instead of changing to your fork you could ask to be added as a collaborator to the main repo. Of course this depends on how @mjg59 feels about this.

This comment has been minimized.

@antsar

antsar Oct 26, 2018

Contributor

Thanks for the feedback. I think I've addressed both of those items in my fork now. I've also updated the README to mention that it's a fork.

I've also opened a PR with the changes: mjg59/python-avion#12

antsar added some commits Oct 25, 2018

devices = avion.get_devices(
config[CONF_USERNAME], config[CONF_PASSWORD])
for device in devices:
lights.append(AvionLight(device))

for address, device_config in config[CONF_DEVICES].items():
device = {}
device['name'] = device_config[CONF_NAME]

This comment has been minimized.

@fabaff

fabaff Oct 26, 2018

Member

If now default is defined will this lead to a KeyError. See comment above.

This comment has been minimized.

@antsar

antsar Oct 26, 2018

Contributor

Fixed. Thank you for catching this.

Edit: updated link to latest commit, initial fix was stupid.

mac[2], mac[3])
lights.append(AvionLight(device))
devices = avion.get_devices(
config[CONF_USERNAME], config[CONF_PASSWORD])

This comment has been minimized.

@fabaff

fabaff Oct 26, 2018

Member

Use .get(). No need to define a default in the configuration validation for the username and the password as None is the default already.

Thus I don't agree with this comment. Sometimes you want the KeyError to happen.

This comment has been minimized.

@antsar

antsar Oct 26, 2018

Contributor

This is inside a conditional block which ensures those keys exist, so I don't think .get() is necessary.

     if CONF_USERNAME in config and CONF_PASSWORD in config:
         devices = avion.get_devices(
             config[CONF_USERNAME], config[CONF_PASSWORD])

In places where keys might not be set, I've updated it to use .get().

antsar and others added some commits Oct 26, 2018

Remove unnecessary voluptuous defaults. Fix manually-configured devices.
API-discovered devices are already Avion objects, but manually-configured devices need to be instantiated as Avion objects first.
@houndci-bot

Some files could not be reviewed due to errors:

Traceback (most recent call last):
Traceback (most recent call last):
  File "/home/linters/.local/bin/flake8", line 7, in 
    from flake8.main.cli import main
ModuleNotFoundError: No module named 'flake8'
@antsar

This comment has been minimized.

Contributor

antsar commented on 2191e6a Oct 28, 2018

Thanks for the cleanup! I should've been more attentive 😨

@fabaff

fabaff approved these changes Oct 29, 2018

@fabaff fabaff merged commit 32cb666 into home-assistant:dev Oct 29, 2018

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls First build on avion-update at 93.197%
Details

@wafflebot wafflebot bot removed the in progress label Oct 29, 2018

@balloob balloob referenced this pull request Nov 9, 2018

Merged

0.82 #18335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment