home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.59k stars 29.91k forks source link

Nissan Leaf stuck with update_in_progress: true #29308

Closed Skeletorjus closed 4 years ago

Skeletorjus commented 4 years ago

Home Assistant release with the issue:

0.102.2

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Hass.io on Debian

Integration:

https://www.home-assistant.io/integrations/nissan_leaf/

Description of problem: The sensors stops updating after a while with the attribute update_in_progress stuck on true. No new updates will happen after that until a restart of Home Assistant. ha.nissan.log

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

nissan_leaf:
  username: !secret leaf_user
  password: !secret leaf_pass
  region: "NE"
  update_interval:
    hours: 24
  update_interval_charging:
    hours: 24
  update_interval_climate:
    minutes: 5

Traceback (if applicable):

Additional information: I do updates with automations via the nissan_leaf.update service (1hr normal, 15min while plugged), but I've also observed this through regular updates.

Log:

2019-12-02 07:01:51 ERROR (MainThread) [homeassistant.components.nissan_leaf] An error occurred getting battery status.
2019-12-02 07:03:43 ERROR (SyncWorker_21) [pycarwings2.pycarwings2] Invalid JSON returned
2019-12-02 07:03:43 ERROR (MainThread) [homeassistant.components.nissan_leaf] An error occurred getting battery status.
2019-12-02 07:08:44 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f9074ee79e0>
2019-12-02 07:09:52 ERROR (SyncWorker_4) [pycarwings2.pycarwings2] Invalid JSON returned
2019-12-02 07:09:52 ERROR (MainThread) [homeassistant.components.nissan_leaf] An error occurred getting battery status.
2019-12-02 07:14:53 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f9072a51560>
2019-12-02 07:16:14 ERROR (SyncWorker_3) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 503}
2019-12-02 07:19:15 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 234, in async_update_data
    await self.async_refresh_data(now)
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 286, in async_refresh_data
    server_response = await self.async_get_battery()
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 344, in async_get_battery
    request = await self.hass.async_add_executor_job(self.leaf.request_update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 230, in request_update
    return response["resultKey"]
KeyError: 'resultKey'
2019-12-02 07:20:01 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f9074d68c20>
2019-12-02 07:25:02 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f907462c8c0>
2019-12-02 07:35:01 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f9074c7b950>
2019-12-02 07:40:02 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f90731ddc20>
2019-12-02 07:45:52 ERROR (SyncWorker_25) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408}
2019-12-02 07:50:01 WARNING (MainThread) [homeassistant.core] Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x7f9071b08f80>
2019-12-02 07:51:42 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 503}
2019-12-02 07:52:55 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] Invalid JSON returned
2019-12-02 07:52:55 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 153, in _request
    j = json.loads(response.text)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1261, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 348, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 370, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/switch.py", line 58, in async_turn_off
    if await self.car.async_set_climate(False):
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 424, in async_set_climate
    result_function, request
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 290, in get_stop_climate_control_result
    "resultKey": result_key,
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 109, in _request_with_retry
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 174, in connect
    "lg": "en-US",
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 156, in _request
    raise CarwingsError
pycarwings2.pycarwings2.CarwingsError
probot-home-assistant[bot] commented 4 years ago

Hey there @filcole, mind taking a look at this issue as its been labeled with a integration (nissan_leaf) you are listed as a codeowner for? Thanks!

T-bond commented 4 years ago

I am experiencing the same issue, with the same error outputs. I use the default config for the timers with no manual update.

jyrki69 commented 4 years ago

Same here. I've reported this a while back, but its not fixed. The Nissan component is useless if you don't rely on restarting Home Assistant all the time.

Thanks for all the hard work @filcole, but I really hope you are able to fix this soon, thanks.

Updated after last restart, then totally stuck again.

next update

-

last attempt

2020-01-15T04:06:46.002401

updated on

2020-01-15T02:51:42.111655+00:00

update in progress

true

vwir commented 4 years ago

I think that I have a fix for the issue. Basically in line 385 of init.py there should be except for KeyError. So the code will look like:

except CarwingsError: _LOGGER.error("An error occurred getting battery status.") return None except KeyError: _LOGGER.error("An error occurred parsing response from server.") return None

async def async_get_climate(self):

I'm testing the code with such change and so far so good. It didn't get stuck even once.

slashdotdash commented 4 years ago

@vwir Could you submit a pull request with the above fix if it's working for you. I'm encountering the update in progress getting stuck quite frequently, at least once a week recently.

vwir commented 4 years ago

I added extra logging on my setup to make sure that it works. When it turns out that it's ok then I'll push the change.

pf4eva commented 4 years ago

Strange, I still have the same error, even with fixed posted here: 2020-09-21 00:16:34 ERROR (SyncWorker_1) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:32:18 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:48:03 ERROR (SyncWorker_23) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408}

springstan commented 3 years ago

Strange, I still have the same error, even with fixed posted here: 2020-09-21 00:16:34 ERROR (SyncWorker_1) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:32:18 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:48:03 ERROR (SyncWorker_23) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408}

@pf4eva please do not comment on close issues. Please open a new one for your problem, since it does not look like the original issue. Thanks for understanding :)

pf4eva commented 3 years ago

Strange, I still have the same error, even with fixed posted here: 2020-09-21 00:16:34 ERROR (SyncWorker_1) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:32:18 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408} 2020-09-21 00:48:03 ERROR (SyncWorker_23) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 408}

@pf4eva please do not comment on close issues. Please open a new one for your problem, since it does not look like the original issue. Thanks for understanding :)

This is the same issue reported by topic starter... Resolves only by restarting HA. What makes you think it is different?

springstan commented 3 years ago

You are correct that your error appears once in the original issue, however a long stack trace of the main error follows which you don't seem to have:

2019-12-02 07:51:42 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] carwings error; logging in and trying request again: {'status': 503}
2019-12-02 07:52:55 ERROR (SyncWorker_6) [pycarwings2.pycarwings2] Invalid JSON returned
2019-12-02 07:52:55 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 153, in _request
    j = json.loads(response.text)
  File "/usr/local/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1261, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 348, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 370, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/switch.py", line 58, in async_turn_off
    if await self.car.async_set_climate(False):
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 424, in async_set_climate
    result_function, request
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 290, in get_stop_climate_control_result
    "resultKey": result_key,
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 109, in _request_with_retry
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 174, in connect
    "lg": "en-US",
  File "/usr/local/lib/python3.7/site-packages/pycarwings2/pycarwings2.py", line 156, in _request
    raise CarwingsError
pycarwings2.pycarwings2.CarwingsError