Skip to content

Handle Hue errors better#12845

Merged
balloob merged 2 commits intodevfrom
hue-error-handling
Mar 2, 2018
Merged

Handle Hue errors better#12845
balloob merged 2 commits intodevfrom
hue-error-handling

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob 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 balloob added this to the 0.64.3 milestone Mar 2, 2018
@balloob balloob merged commit d333593 into dev Mar 2, 2018
balloob added a commit that referenced this pull request Mar 2, 2018
* Handle Hue errors better

* Lint
@balloob balloob mentioned this pull request Mar 2, 2018
self.host,
config_file_path=self.hass.config.path(self.filename))
except ConnectionRefusedError: # Wrong host was given
except (ConnectionRefusedError, OSError): # Wrong host was given
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.

ConnectionRefusedError is a subclass of OSError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 March 2, 2018 23:00
@robertw
Copy link
Copy Markdown

robertw 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'

except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unknown error connecting with Hue bridge at %s",
self.host)

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.

We should probably return here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Will include it in my #12830 branch

@balloob
Copy link
Copy Markdown
Member Author

balloob 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
Copy link
Copy Markdown

robertw 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
Copy link
Copy Markdown
Member Author

balloob 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.

Labels

cla-signed integration: hue small-pr PRs with less than 30 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants