From 7c206809ac35a686a16eb8b3b209d030a28463f7 Mon Sep 17 00:00:00 2001 From: Jeroen ter Heerdt Date: Fri, 10 May 2024 22:55:02 +0000 Subject: [PATCH] v2024.5.0 improvements to handling of OWM API versioning removal --- .../smart_irrigation/__init__.py | 67 +++++++++++++++++-- custom_components/smart_irrigation/const.py | 2 +- .../frontend/dist/smart-irrigation.js | 2 +- .../smart_irrigation/frontend/src/const.ts | 2 +- .../smart_irrigation/manifest.json | 2 +- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/custom_components/smart_irrigation/__init__.py b/custom_components/smart_irrigation/__init__.py index 376defc5..bb72246f 100644 --- a/custom_components/smart_irrigation/__init__.py +++ b/custom_components/smart_irrigation/__init__.py @@ -93,14 +93,20 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if const.CONF_OWM_API_KEY in entry.options: hass.data[const.DOMAIN][const.CONF_OWM_API_KEY] = entry.options.get( const.CONF_OWM_API_KEY - ).strip() - hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] = entry.options.get( - const.CONF_OWM_API_VERSION - ) + ) + if hass.data[const.DOMAIN][const.CONF_OWM_API_KEY] is not None: + hass.data[const.DOMAIN][const.CONF_OWM_API_KEY] = hass.data[ + const.DOMAIN + ][const.CONF_OWM_API_KEY].strip() + if const.CONF_OWM_API_VERSION in entry.options: + hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] = entry.options.get( + const.CONF_OWM_API_VERSION + ) # check if API version is 2.5, force it to be 3.0. API keys should still be valid. - if hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] == "2.5": - hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] = "3.0" + if const.CONF_OWM_API_VERSION in hass.data[const.DOMAIN]: + if hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] == "2.5": + hass.data[const.DOMAIN][const.CONF_OWM_API_VERSION] = "3.0" coordinator = SmartIrrigationCoordinator(hass, session, entry, store) device_registry = dr.async_get(hass) @@ -1426,7 +1432,55 @@ def _reset_event_fired_today(self, *args): @callback def async_get_all_modules(self): """Get all ModuleEntries""" + # disabling the use of loadModules here because of HA DEV warning ("Detected blocking call to import_module inside the event loop") and I don't know how to fix it res = [] + """res.append( + { + "name": "PyETO", + "description": "Calculate duration based on the FAO56 calculation from the PyETO library.", + "config": {}, + "schema": [ + { + "type": "boolean", + "name": "coastal", + "optional": True, + "default": False, + }, + { + "type": "select", + "options": [...], + "name": "solrad_behavior", + "required": True, + "default": {"name": "EstimateFromTemp", "value": "1"}, + }, + { + "type": "integer", + "name": "forecast_days", + "required": True, + "default": 0, + }, + ], + } + ) + res.append( + { + "name": "Static", + "description": "'Dummy' module with a static configurable delta.", + "config": {}, + "schema": [ + {"type": "float", "name": "delta", "required": True, "default": 0.0} + ], + } + ) + res.append( + { + "name": "Passthrough", + "description": "Passthrough module that returns the value of an Evapotranspiration sensor as delta.", + "config": {}, + "schema": [], + } + )""" + mods = loadModules(const.MODULE_DIR) for mod in mods: m = getattr(mods[mod]["module"], mods[mod]["class"]) @@ -1439,7 +1493,6 @@ def async_get_all_modules(self): "schema": s.schema_serialized(), } ) - return res async def async_remove_entity(self, zone_id: str): diff --git a/custom_components/smart_irrigation/const.py b/custom_components/smart_irrigation/const.py index c1b78362..bc71d5bc 100644 --- a/custom_components/smart_irrigation/const.py +++ b/custom_components/smart_irrigation/const.py @@ -1,7 +1,7 @@ """Store constants.""" -VERSION = "v2024.4.5" +VERSION = "v2024.5.0" NAME = "Smart Irrigation" MANUFACTURER = "@jeroenterheerdt" diff --git a/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js b/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js index b96d7447..fc5e8c5b 100644 --- a/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js +++ b/custom_components/smart_irrigation/frontend/dist/smart-irrigation.js @@ -1057,7 +1057,7 @@ a.version="2.29.4",i(Wa),a.fn=us,a.min=Xa,a.max=Ja,a.now=Qa,a.utc=p,a.unix=cs,a. .narrow=${this.narrow} >
${hi("title",this.hass.language)}
-
${"v2024.4.5"}
+
${"v2024.5.0"}