From d6e9b9d1ab9242c7e385281c6770cfe3288eb798 Mon Sep 17 00:00:00 2001 From: Aron Brown Date: Tue, 28 Jan 2025 14:36:01 -0500 Subject: [PATCH 1/3] Add constants for "Include all" category and account options. --- custom_components/ynab/const.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/ynab/const.py b/custom_components/ynab/const.py index f629df6..796e661 100644 --- a/custom_components/ynab/const.py +++ b/custom_components/ynab/const.py @@ -32,5 +32,7 @@ CONF_BUDGET_KEY = "budget" CONF_BUDGET_NAME_KEY = "budget_name" CONF_CATEGORIES_KEY = "categories" +CONF_CATEGORIES_ALL = "categories_all" CONF_ACCOUNTS_KEY = "accounts" +CONF_ACCOUNTS_ALL = "accounts_all" CONF_CURRENCY_KEY = "currency" \ No newline at end of file From ebfd3df0d960520527514ee4f19acde3a169c56d Mon Sep 17 00:00:00 2001 From: Aron Brown Date: Tue, 28 Jan 2025 14:40:14 -0500 Subject: [PATCH 2/3] Add Category and Account "All" checkboxes to the config flow. --- custom_components/ynab/config_flow.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/ynab/config_flow.py b/custom_components/ynab/config_flow.py index fb32f27..6cc0d3f 100644 --- a/custom_components/ynab/config_flow.py +++ b/custom_components/ynab/config_flow.py @@ -3,8 +3,10 @@ import voluptuous as vol from .const import ( CONF_ACCOUNTS_KEY, + CONF_ACCOUNTS_ALL, CONF_BUDGET_KEY, CONF_CATEGORIES_KEY, + CONF_CATEGORIES_ALL, CONF_CURRENCY_KEY, DOMAIN ) @@ -77,6 +79,7 @@ async def async_step_budgets(self, user_input=None): async def async_step_categories(self, user_input=None): if user_input is not None: + self.data[CONF_CATEGORIES_ALL] = user_input[CONF_CATEGORIES_ALL] if CONF_CATEGORIES_KEY in user_input: self.data[CONF_CATEGORIES_KEY] = user_input[CONF_CATEGORIES_KEY] else: @@ -87,6 +90,7 @@ async def async_step_categories(self, user_input=None): categories_by_name = await self.fetch_categories() data_schema = { + vol.Required(CONF_CATEGORIES_ALL): bool, vol.Optional(CONF_CATEGORIES_KEY): selector({ "select": { "options": [{"label": name, "value": category.id} for name, category in categories_by_name.items()], @@ -111,6 +115,7 @@ async def fetch_categories(self): async def async_step_accounts(self, user_input=None): if user_input is not None: + self.data[CONF_ACCOUNTS_ALL] = user_input[CONF_ACCOUNTS_ALL] if CONF_ACCOUNTS_KEY in user_input: self.data[CONF_ACCOUNTS_KEY] = user_input[CONF_ACCOUNTS_KEY] else: @@ -124,6 +129,7 @@ async def async_step_accounts(self, user_input=None): accounts_response = await self.hass.async_add_executor_job(self.ynab.accounts.get_accounts, self.data["budget"]) data_schema = { + vol.Required(CONF_ACCOUNTS_ALL): bool, vol.Optional(CONF_ACCOUNTS_KEY): selector({ "select": { "options": [{"label": account.name, "value": account.id} for account in accounts_response.data.accounts], From 59e456012eef497b0b0b7240e4b74d19320bf9b4 Mon Sep 17 00:00:00 2001 From: Aron Brown Date: Tue, 28 Jan 2025 14:48:34 -0500 Subject: [PATCH 3/3] Update Sensor and Data coordinator to use the "All" options for categories and accounts --- custom_components/ynab/api/data_coordinator.py | 8 ++++++-- custom_components/ynab/sensor.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/custom_components/ynab/api/data_coordinator.py b/custom_components/ynab/api/data_coordinator.py index f4895a3..0c70707 100644 --- a/custom_components/ynab/api/data_coordinator.py +++ b/custom_components/ynab/api/data_coordinator.py @@ -13,7 +13,9 @@ CONF_CURRENCY_KEY, CONF_BUDGET_KEY, CONF_CATEGORIES_KEY, + CONF_CATEGORIES_ALL, CONF_ACCOUNTS_KEY, + CONF_ACCOUNTS_ALL, DEFAULT_API_ENDPOINT, DOMAIN ) @@ -61,7 +63,9 @@ def __init__(self, hass, config): self.api_key = config[CONF_API_KEY] self.budget = config[CONF_BUDGET_KEY] self.categories = config[CONF_CATEGORIES_KEY] + self.categories_all = config[CONF_CATEGORIES_ALL] self.accounts = config[CONF_ACCOUNTS_KEY] + self.accounts_all = config[CONF_ACCOUNTS_ALL] async def _async_update_data(self): @@ -128,7 +132,7 @@ async def _async_update_data(self): # get accounts accounts: dict[str, AccountModel] = {} for account in get_data.accounts: - if account.id not in self.accounts: + if not self.accounts_all and account.id not in self.accounts: continue accounts.update([(account.id, AccountModel(account.name, account.balance / 1000))]) @@ -179,7 +183,7 @@ async def _async_update_data(self): # get remaining category balances categories: dict[str, CategoryModel] = {} for category in month.categories: - if category.id not in self.categories: + if not self.categories_all and category.id not in self.categories: continue categories.update( diff --git a/custom_components/ynab/sensor.py b/custom_components/ynab/sensor.py index d03b3b1..0a0c274 100644 --- a/custom_components/ynab/sensor.py +++ b/custom_components/ynab/sensor.py @@ -2,9 +2,9 @@ import logging from homeassistant.helpers.entity import DeviceInfo -from .const import (DOMAIN, CONF_ACCOUNTS_KEY, +from .const import (DOMAIN, CONF_ACCOUNTS_KEY, CONF_ACCOUNTS_ALL, CONF_BUDGET_KEY, CONF_CATEGORIES_KEY, - CONF_BUDGET_NAME_KEY) + CONF_CATEGORIES_ALL, CONF_BUDGET_NAME_KEY) from .sensors.balance_sensor import CategorySensor, AccountSensor from .sensors.budget_sensor import BudgetSensor @@ -35,14 +35,18 @@ async def async_setup_entry( sensors = [BudgetSensor(coordinator, budget_id, budget_name, device_info)] categories = [] - if CONF_CATEGORIES_KEY in config_entry.data: + if config_entry.data[CONF_CATEGORIES_ALL]: + categories = coordinator.data.categories.keys() + elif CONF_CATEGORIES_KEY in config_entry.data: categories = config_entry.data[CONF_CATEGORIES_KEY] for category in categories: sensors.append(CategorySensor(coordinator, category_id=category, device_info=device_info, budget_name=budget_name)) accounts = [] - if CONF_ACCOUNTS_KEY in config_entry.data: + if config_entry.data[CONF_ACCOUNTS_ALL]: + accounts = coordinator.data.accounts.keys() + elif CONF_ACCOUNTS_KEY in config_entry.data: accounts = config_entry.data[CONF_ACCOUNTS_KEY] for account in accounts: