From d9962ed485de3429b339e33fd9c2f24a2787963e Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sun, 6 Sep 2020 11:43:36 +0000 Subject: [PATCH 1/3] Make update more verbose --- custom_components/grocy/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/custom_components/grocy/__init__.py b/custom_components/grocy/__init__.py index 22aa389..57b280e 100644 --- a/custom_components/grocy/__init__.py +++ b/custom_components/grocy/__init__.py @@ -84,18 +84,27 @@ def __init__(self, hass, url, api_key, port_number, verify_ssl): async def _async_update_data(self): """Update data via library.""" + grocy_data = GrocyData(self.hass, self.api) data = {} + features = [] try: - grocy_data = GrocyData(self.hass, self.api) features = await async_supported_features(grocy_data) - for entity in self.entities: - if entity.enabled and entity.entity_type in features: + if not features: + raise UpdateFailed("No features enabled") + except Exception as exception: + raise UpdateFailed(exception) + + for entity in self.entities: + if entity.enabled and entity.entity_type in features: + try: data[entity.entity_type] = await grocy_data.async_update_data( entity.entity_type ) - return data - except Exception as exception: - raise UpdateFailed(exception) + except Exception as exception: + raise UpdateFailed( + f"Update of {entity.entity_type} failed with {exception}" + ) + return data async def async_supported_features(grocy_data) -> List[str]: From 6c63b6fccf0e7adf81349feb437048c784380a9e Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sun, 6 Sep 2020 12:14:26 +0000 Subject: [PATCH 2/3] WTF.... --- custom_components/grocy/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/grocy/__init__.py b/custom_components/grocy/__init__.py index 57b280e..f0c10e3 100644 --- a/custom_components/grocy/__init__.py +++ b/custom_components/grocy/__init__.py @@ -28,7 +28,7 @@ from .grocy_data import GrocyData, async_setup_image_api from .services import async_setup_services, async_unload_services -SCAN_INTERVAL = timedelta(seconds=30) +SCAN_INTERVAL = timedelta(seconds=10) _LOGGER = logging.getLogger(__name__) @@ -101,9 +101,13 @@ async def _async_update_data(self): entity.entity_type ) except Exception as exception: - raise UpdateFailed( + _LOGGER.error( f"Update of {entity.entity_type} failed with {exception}" ) + elif entity.entity_type not in features: + _LOGGER.warning( + f"You have enabled the entity for {entity.name}, but this feature is not enabled in Grocy", + ) return data @@ -112,23 +116,23 @@ async def async_supported_features(grocy_data) -> List[str]: features = [] config = await grocy_data.async_get_config() if config: - if config["FEATURE_FLAG_STOCK"]: + if config["FEATURE_FLAG_STOCK"] != "0": features.append(GrocyEntityType.STOCK) features.append(GrocyEntityType.PRODUCTS) features.append(GrocyEntityType.MISSING_PRODUCTS) features.append(GrocyEntityType.EXPIRED_PRODUCTS) features.append(GrocyEntityType.EXPIRING_PRODUCTS) - if config["FEATURE_FLAG_SHOPPINGLIST"]: + if config["FEATURE_FLAG_SHOPPINGLIST"] != "0": features.append(GrocyEntityType.SHOPPING_LIST) - if config["FEATURE_FLAG_TASKS"]: + if config["FEATURE_FLAG_TASKS"] != "0": features.append(GrocyEntityType.TASKS) - if config["FEATURE_FLAG_CHORES"]: + if config["FEATURE_FLAG_CHORES"] != "0": features.append(GrocyEntityType.CHORES) - if config["FEATURE_FLAG_RECIPES"]: + if config["FEATURE_FLAG_RECIPES"] != "0": features.append(GrocyEntityType.MEAL_PLAN) return features From cb080cc552d5b2af15b1d0da233db29c2fd684f7 Mon Sep 17 00:00:00 2001 From: Ludeeus Date: Sun, 6 Sep 2020 12:16:50 +0000 Subject: [PATCH 3/3] SCAN_INTERVAL=30 --- custom_components/grocy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/grocy/__init__.py b/custom_components/grocy/__init__.py index f0c10e3..e1f8e75 100644 --- a/custom_components/grocy/__init__.py +++ b/custom_components/grocy/__init__.py @@ -28,7 +28,7 @@ from .grocy_data import GrocyData, async_setup_image_api from .services import async_setup_services, async_unload_services -SCAN_INTERVAL = timedelta(seconds=10) +SCAN_INTERVAL = timedelta(seconds=30) _LOGGER = logging.getLogger(__name__)