-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Refactor hue to split bridge support from light platform #10691
Conversation
Hi @andreacampi, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
homeassistant/components/hue.py
Outdated
self.config_request_id = configurator.request_config( | ||
"Philips Hue", | ||
lambda data: self.setup(), | ||
description=("Press the button on the bridge to register Philips Hue " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (82 > 79 characters)
homeassistant/components/hue.py
Outdated
# We got an error if this method is called while we are configuring | ||
if self.config_request_id: | ||
configurator.notify_errors( | ||
self.config_request_id, "Failed to register, please try again.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (80 > 79 characters)
homeassistant/components/hue.py
Outdated
|
||
try: | ||
api = self.bridge.get_api() | ||
except phue.PhueRequestTimeout: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'phue'
homeassistant/components/hue.py
Outdated
os.path.join(os.path.dirname(__file__), 'services.yaml')) | ||
self.hass.services.register(DOMAIN, SERVICE_HUE_SCENE, hue_activate_scene, | ||
descriptions.get(SERVICE_HUE_SCENE), | ||
schema=SCENE_SCHEMA) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
homeassistant/components/hue.py
Outdated
descriptions = load_yaml_config_file( | ||
os.path.join(os.path.dirname(__file__), 'services.yaml')) | ||
self.hass.services.register(DOMAIN, SERVICE_HUE_SCENE, hue_activate_scene, | ||
descriptions.get(SERVICE_HUE_SCENE), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
homeassistant/components/hue.py
Outdated
|
||
GROUP_NAME_ALL_HUE_LIGHTS = "All Hue Lights" | ||
|
||
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines, found 1
tests/components/test_hue.py
Outdated
self.assertEqual(1, len(self.hass.states.all())) | ||
self.assertEqual('configure', self.hass.states.all()[0].state) | ||
self.assertEqual('Failed to register, please try again.', | ||
self.hass.states.all()[0].attributes.get(configurator.ATTR_ERRORS)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/test_hue.py
Outdated
|
||
# We should see a total of two identical calls | ||
args = call('localhost', | ||
config_file_path=get_test_config_dir(hue.PHUE_CONFIG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/test_hue.py
Outdated
|
||
# We should see a total of two identical calls | ||
args = call('localhost', | ||
config_file_path=get_test_config_dir(hue.PHUE_CONFIG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/test_hue.py
Outdated
|
||
# We should see a total of two identical calls | ||
args = call('localhost', | ||
config_file_path=get_test_config_dir(hue.PHUE_CONFIG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
There are a few things I still have to clean up, but I wanted to get the ball rolling and get early feedback. To do:
Re config, this changes from:
to:
I find this makes more sense when the component can support more than just lights, yes? |
cc @robmarkcole |
Hi @andreacampi, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
tests/components/test_hue.py
Outdated
|
||
mock_bridge.assert_called_once_with( | ||
'localhost', | ||
config_file_path=get_test_config_dir(hue.PHUE_CONFIG_FILE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (83 > 79 characters)
tests/components/test_hue.py
Outdated
|
||
with assert_setup_component(1): | ||
with patch('homeassistant.components.hue._find_host_from_config', | ||
return_value='localhost') as mock_config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
local variable 'mock_config' is assigned to but never used
tests/components/test_hue.py
Outdated
with patch('homeassistant.helpers.discovery.load_platform') \ | ||
as mock_load: | ||
self.assertTrue(setup_component( | ||
self.hass, hue.DOMAIN, {hue.DOMAIN: {CONF_HOST: 'localhost'}})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (83 > 79 characters)
tests/components/test_hue.py
Outdated
|
||
from homeassistant.components import configurator, hue | ||
# import homeassistant.components.configurator as configurator | ||
from homeassistant.const import CONF_HOST, CONF_PLATFORM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'homeassistant.const.CONF_PLATFORM' imported but unused
tests/components/test_hue.py
Outdated
import logging | ||
import unittest | ||
from unittest.mock import call, MagicMock, patch | ||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'os' imported but unused
tests/components/test_hue.py
Outdated
|
||
import logging | ||
import unittest | ||
from unittest.mock import call, MagicMock, patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'unittest.mock.MagicMock' imported but unused
Hi @andreacampi, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
It seems like you have some commits in this branch that are not yours, please base your work off a fresh copy of the dev branch. |
I haven't looked at the code at all, but yes, migrating hue from just a platform to be a component for auth and a platform for lights = 👍 |
Im not sure I follow this refactor, appears to be a lot of light specific code in |
@robmarkcole yeah that's fair, not sure why I decided to go that way. I'll clean that up and/or explain. |
I'll rebase and check the failed tests; just not today as I've had a long day on ~4 hours of sleep. |
tests/components/light/test_hue.py
Outdated
self.mock_bridge, mock.ANY, self.mock_bridge_type, | ||
self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, | ||
True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
call(0, {'name': 'All Hue Lights', 'state': {'any_on': True}}, | ||
self.mock_bridge, mock.ANY, self.mock_bridge_type, | ||
self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.mock_bridge.allow_in_emulated_hue, True), | ||
call(0, {'name': 'All Hue Lights', 'state': {'any_on': True}}, | ||
self.mock_bridge, mock.ANY, self.mock_bridge_type, | ||
self.mock_bridge.allow_unreachable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.mock_bridge_type, self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, True), | ||
call(0, {'name': 'All Hue Lights', 'state': {'any_on': True}}, | ||
self.mock_bridge, mock.ANY, self.mock_bridge_type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
mock_hue_light.assert_has_calls([ | ||
call(2, {'state': 'off'}, self.mock_bridge, mock.ANY, | ||
self.mock_bridge_type, self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.mock_bridge.allow_in_emulated_hue, True), | ||
call(2, {'state': 'off'}, self.mock_bridge, mock.ANY, | ||
self.mock_bridge_type, self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.mock_bridge_type, self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, True), | ||
call(2, {'state': 'off'}, self.mock_bridge, mock.ANY, | ||
self.mock_bridge_type, self.mock_bridge.allow_unreachable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
mock_hue_light.assert_has_calls([ | ||
call(1, {'state': 'on'}, self.mock_bridge, mock.ANY, | ||
self.mock_bridge_type, self.mock_bridge.allow_unreachable, | ||
self.mock_bridge.allow_in_emulated_hue, True), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.assertEquals(len(ret), 3) | ||
mock_hue_light.assert_has_calls([ | ||
call(1, {'state': 'on'}, self.mock_bridge, mock.ANY, | ||
self.mock_bridge_type, self.mock_bridge.allow_unreachable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
tests/components/light/test_hue.py
Outdated
self.mock_api.get.return_value = {1: {'state': 'on'}, 2: {'state': 'off'}} | ||
|
||
ret = hue_light.process_groups(self.hass, | ||
self.mock_api, self.mock_bridge, self.mock_bridge_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuation line under-indented for visual indent
Not only this looks nicer, but it also nicely solves additional bridges being added after initial setup (e.g. pairing a second bridge should work now, I believe it required a restart before).
…t phue in tests, yay!
🎉 🐬 Awesome, great job ! |
…ent-being-nonexistent * origin/dev: Volvo on call: Optional use of Scandinavian miles. Also add average fuel consumption property (home-assistant#11051) add custom bypass status to total connect (home-assistant#11042) Refactor hue to split bridge support from light platform (home-assistant#10691) Add GPS coords to meraki (home-assistant#10998) Add a caldav calendar component (home-assistant#10842) Added support for cover in tellstick (home-assistant#10858)
…into dev * 'dev' of https://github.com/home-assistant/home-assistant: Volvo on call: Optional use of Scandinavian miles. Also add average fuel consumption property (home-assistant#11051) add custom bypass status to total connect (home-assistant#11042) Refactor hue to split bridge support from light platform (home-assistant#10691) Add GPS coords to meraki (home-assistant#10998) Add a caldav calendar component (home-assistant#10842) Added support for cover in tellstick (home-assistant#10858)
These changes seem to be allowing HASS to discover it's own emulated hue bridge as a bridge device and throws an error because it can't find the config file. |
I'm also having some problems since this commit after re-working my configuration. Once the hubs are added with emulated hue disabled, I see the error below for each light. Should I open up a new issue?
|
See #11126 |
Another pull request: #11128 |
* Update documentation for Philips Hue changes. See home-assistant/core#10691 for more info. * Update hue.markdown
How would one set the Leaving this in place with the new Hue component seemed to break the configuration. Once I know the new way to set a Thanks! |
Please open an issue if you suspect a bug. If you need help please use our help channels: Merged PRs should not be used for support or bug reports. Thanks! |
This work appears to change the filename of the default
And to fail to connect to the bridge. My hue bridge is in the roof and pressing the button was quite a pain. It would be handy to either, upgrade (i.e. rename) the existing May also be useful to update the docs to give the filename of the hue token file, since I looked there first of all to see if there'd been a change. |
Please open an issue in the appropriate reoo if you suspect a bug or there's a problem with documentation. If you need help please use our help channels: Merged PRs should not be used for support or bug reports. You can link to the PR that you want to tag from the issue. Thanks! |
Description:
This is in preparation to supporting sensors.
Related issue (if applicable): fixes #10609
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4099
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.