Skip to content
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

Handle Hue errors better #12845

Merged
merged 2 commits into from Mar 2, 2018

Conversation

Projects
None yet
4 participants
@balloob
Copy link
Member

commented Mar 2, 2018

Description:

If a user has 2 networks behind the same IP with both a Hue hub, Hue component would fail to setup.

What would happen is that Home Assistant would get the IP address from the cloud discovery and try to connect. This would raise an OSError and we only handled ConnectionRefusedError. I've also added a generic exception handler to make sure we don't disturb the setup process of other hubs.

Example entry for configuration.yaml (if applicable):

hue:

balloob added some commits Mar 2, 2018

@balloob balloob added this to the 0.64.3 milestone Mar 2, 2018

@balloob balloob merged commit d333593 into dev Mar 2, 2018

3 of 5 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
hound No violations found. Woof!

balloob added a commit that referenced this pull request Mar 2, 2018

Handle Hue errors better (#12845)
* Handle Hue errors better

* Lint

@balloob balloob referenced this pull request Mar 2, 2018

Merged

0.64.3 #12848

@@ -192,7 +192,7 @@ def setup(self):
self.bridge = phue.Bridge(
self.host,
config_file_path=self.hass.config.path(self.filename))
except ConnectionRefusedError: # Wrong host was given
except (ConnectionRefusedError, OSError): # Wrong host was given

This comment has been minimized.

Copy link
@MartinHjelmare

MartinHjelmare Mar 2, 2018

Member

ConnectionRefusedError is a subclass of OSError.

This comment has been minimized.

Copy link
@balloob

balloob Mar 2, 2018

Author Member

Oh.

Well good thing that I am going to throw it all away when we migrate to aiohue #12830

This comment has been minimized.

Copy link
@balloob

balloob Mar 2, 2018

Author Member

I tested it locally before committing but only tested

>>> isinstance(ConnectionRefusedError, OSError)
False

But classes are of type Type.

Instantiating did the trick:

>>> isinstance(ConnectionRefusedError(), OSError)
True

@balloob balloob deleted the hue-error-handling branch Mar 2, 2018

@robertw

This comment has been minimized.

Copy link

commented Mar 3, 2018

After recent update error still there fyi

18-03-03 07:34:59 ERROR (SyncWorker_0) [homeassistant.components.hue] Unknown error connecting with Hue bridge at 192.168.1.87
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/hue.py", line 194, in setup
    config_file_path=self.hass.config.path(self.filename))
  File "/usr/lib/python3.6/site-packages/phue.py", line 629, in __init__
    self.connect()
  File "/usr/lib/python3.6/site-packages/phue.py", line 752, in connect
    self.register_app()
  File "/usr/lib/python3.6/site-packages/phue.py", line 706, in register_app
    response = self.request('POST', '/api', registration_request)
  File "/usr/lib/python3.6/site-packages/phue.py", line 667, in request
    return json.loads(response.decode('utf-8'))
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2018-03-03 07:35:00 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform hue
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/hue.py", line 106, in setup_platform
    unthrottled_update_lights(hass, bridge, add_devices)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/hue.py", line 123, in unthrottled_update_lights
    api = bridge.get_api()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/hue.py", line 254, in get_api
    return self.bridge.get_api()
AttributeError: 'NoneType' object has no attribute 'get_api'
@@ -201,6 +201,9 @@ def setup(self):
self.host)
self.request_configuration()
return
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unknown error connecting with Hue bridge at %s",
self.host)

This comment has been minimized.

Copy link
@MartinHjelmare

MartinHjelmare Mar 3, 2018

Member

We should probably return here.

This comment has been minimized.

Copy link
@balloob

balloob Mar 4, 2018

Author Member

Good point. Will include it in my #12830 branch

hmn added a commit to hmn/home-assistant-dev that referenced this pull request Mar 3, 2018

Merge branch 'dev' into ps4
* dev: (119 commits)
  Grammar fix 'an unique' (home-assistant#12870)
  Add support for Zillow Zestimate sensor (home-assistant#12597)
  Add unique id for Tibber sensor (home-assistant#12864)
  Updated to use latest ihcsdk version (home-assistant#12865)
  Fix dead Sonos web interface even more (home-assistant#12851)
  IndexError (list index out of range) fixed. (home-assistant#12858)
  Fix light group update before add (home-assistant#12844)
  PyXiaomiGateway version bumped. (home-assistant#12828)
  Keep auto groups during group reload (home-assistant#12841)
  Address upcloud post-merge comments (home-assistant#12011) (home-assistant#12835)
  Update volvooncall.py (home-assistant#12834)
  Handle Hue errors better (home-assistant#12845)
  Cloud unauth (home-assistant#12840)
  Fix sensibo default IDs to be according to schema (home-assistant#12837)
  is_allowed_path: Also unit test folder home-assistant#12788 home-assistant#12807 (home-assistant#12810)
  Version bump to 0.64.3
  Handle Hue errors better (home-assistant#12845)
  Skip flaky light.group test [skipci] (home-assistant#12847)
  Fix sensibo default IDs to be according to schema (home-assistant#12837)
  Cloud unauth (home-assistant#12840)
  ...
@balloob

This comment has been minimized.

Copy link
Member Author

commented Mar 4, 2018

@robertw so it looks like your Philips Hue hub is not returning JSON. Could you update /usr/lib/python3.6/site-packages/phue.py and put a print(response.decode('utf-8')) before line 667

@robertw

This comment has been minimized.

Copy link

commented Mar 4, 2018

i would love to but i am running hass.io so i have no clue unless you can walk me through.....

@balloob

This comment has been minimized.

Copy link
Member Author

commented Mar 4, 2018

Ah yes, that won't work :/

@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.
You can’t perform that action at this time.