wxt9861 / ynab

YNAB component for Home Assistant
MIT License
50 stars 20 forks source link

Error on device update (new install) #14

Closed mugzy closed 1 year ago

mugzy commented 3 years ago

I just installed this integration and from the start, it is not working. Here is what the logs show. Any ideas?

2021-08-27 17:52:53 ERROR (MainThread) [homeassistant.components.sensor] ynab: Error on device update! Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity await entity.async_device_update(warning=False) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 646, in async_device_update await task File "/config/custom_components/ynab/sensor.py", line 31, in async_update await self.hass.data[DOMAIN_DATA]["client"].update_data() File "/config/custom_components/ynab/init.py", line 107, in update_data self.all_budgets = await self.hass.async_add_executor_job( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.9/site-packages/ynab_sdk/api/budgets.py", line 13, in get_budgets return BudgetSummaryResponse.from_dict(response) File "/usr/local/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 102, in from_dict data = Data.from_dict(obj.get("data")) File "/usr/local/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 91, in from_dict budgets = parsers.from_list(Budget.from_dict, obj.get("budgets")) File "/usr/local/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 47, in from_list return [f(y) for y in x] File "/usr/local/lib/python3.9/site-packages/ynab_sdk/utils/parsers.py", line 47, in return [f(y) for y in x] File "/usr/local/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 71, in from_dict date_format = DateFormat.from_dict(obj.get("date_format")) File "/usr/local/lib/python3.9/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 48, in from_dict assert isinstance(obj, dict) AssertionError

wxt9861 commented 3 years ago

This looks like ynab-sdk is not able to get a list of budgets. Can you enable debug and put the log here. Remove any sensitive info.

logger:
  logs:
    custom_components.ynab: debug
linuxboss182 commented 2 years ago

I had the same issue and just found a fix for this. The issue is from the underlying sdk, it expects "currency_format" in the JSON to be non-null. However it is null until you modify it in YNAB. Once I opened my budget and then selected "budget settings" in YNAB and saved I got a non-null payload for current_format and the API worked.

Manazer commented 1 year ago

New error emerged today, pls help :( Tried fix from @linuxboss182, not working.

Logger: homeassistant.components.sensor
Source: custom_components/ynab/__init__.py:113
Integration: Sensor (documentation, issues)
First occurred: 21:24:55 (1 occurrences)
Last logged: 21:24:55

ynab: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 493, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in async_device_update
    await task
  File "/config/custom_components/ynab/sensor.py", line 32, in async_update
    await self.hass.data[DOMAIN_DATA]["client"].update_data()
  File "/config/custom_components/ynab/__init__.py", line 113, in update_data
    self.all_budgets = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/api/budgets.py", line 13, in get_budgets
    return BudgetSummaryResponse.from_dict(response)
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 102, in from_dict
    data = Data.from_dict(obj.get("data"))
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 91, in from_dict
    budgets = parsers.from_list(Budget.from_dict, obj.get("budgets"))
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/utils/parsers.py", line 47, in from_list
    return [f(y) for y in x]
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/utils/parsers.py", line 47, in <listcomp>
    return [f(y) for y in x]
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 72, in from_dict
    currency_format = CurrencyFormat.from_dict(obj.get("currency_format"))
  File "/usr/local/lib/python3.10/site-packages/ynab_sdk/api/models/responses/budget_summary.py", line 21, in from_dict
    assert isinstance(obj, dict)
AssertionError