tlyakhov / python-decora_wifi

Python Library for Interacting with Leviton Decora Smart WiFi Switches & Dimmers
MIT License
37 stars 21 forks source link

Repeated 'Remote end closed connection without response' error and cannot turn switch on or off from HASS #2

Closed marthoc closed 6 years ago

marthoc commented 7 years ago

I am experiencing a problem where the following error is repeated in the HASS logs and the Decora Wifi switch cannot be controlled (i.e. flipping the toggle in HASS does nothing):

2017-09-18 14:49:31 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:50:02 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:50:33 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:51:03 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:51:34 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:52:05 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:52:36 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:53:07 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-18 14:53:38 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30

If I look back in the logs to when the switch stopped responding, this is the traceback:

2017-09-17 00:05:32 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.dining_room_light fails
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 438, in send
    timeout=timeout
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/decora_wifi.py", line 145, in update
    self._switch.refresh()
  File "/config/deps/lib/python3.6/site-packages/decora_wifi/models/iot_switch.py", line 87, in refresh
    result = self._session.call_api(api, {}, 'get')
  File "/config/deps/lib/python3.6/site-packages/decora_wifi/__init__.py", line 48, in call_api
    response = getattr(self._session, method)(uri, data=payload_json)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 531, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 488, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
2017-09-17 00:05:46 WARNING (MainThread) [homeassistant.helpers.entity] Update of light.dining_room_light is taking over 10 seconds
2017-09-17 00:06:07 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-17 00:06:38 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30
2017-09-17 00:07:09 WARNING (MainThread) [homeassistant.components.light] Updating decora_wifi light took longer than the scheduled update interval 0:00:30

My setup in my configuration.yaml is basic:

light:
  - platform: decora_wifi
    username: my_username
    password: my_password

Since that error, I cannot turn the switch on or off from HASS. However, oddly, if I slide the brightness slider in HASS up or down, the light increases and decreases in intensity. Just the toggle switch doesn't work.

marthoc commented 7 years ago

Just setup a test environment and the result is the same with cli_test.py:

requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

Let me know if I can provide any other details to debug. Thanks!

tlyakhov commented 6 years ago

Sorry for the late response - looks like communication with the Leviton cloud is timing out... Not sure why. Nothing obvious in the traceback. Does restarting HASS help?

marthoc commented 6 years ago

Hey Tim, thanks for the response. Actually this problem seems to have resolved itself - haven't seen this error in a couple of months now. Maybe Leviton's cloud has gotten more reliable? In any event, I'll close this issue now.