From 207fe76cb1923e8d8f171c511abbb731d157e21a Mon Sep 17 00:00:00 2001 From: Kev Date: Sat, 16 Nov 2024 21:12:06 +0000 Subject: [PATCH] Allow location to be changed from the settings config --- custom_components/pirateweather/__init__.py | 11 +++++++++-- custom_components/pirateweather/manifest.json | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/custom_components/pirateweather/__init__.py b/custom_components/pirateweather/__init__.py index ace3243..5016651 100644 --- a/custom_components/pirateweather/__init__.py +++ b/custom_components/pirateweather/__init__.py @@ -44,8 +44,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Pirate Weather as config entry.""" name = entry.data[CONF_NAME] api_key = entry.data[CONF_API_KEY] - latitude = entry.data.get(CONF_LATITUDE, hass.config.latitude) - longitude = entry.data.get(CONF_LONGITUDE, hass.config.longitude) + latitude = _get_config_value(entry, CONF_LATITUDE) + longitude = _get_config_value(entry, CONF_LONGITUDE) forecast_mode = "daily" conditions = _get_config_value(entry, CONF_MONITORED_CONDITIONS) units = _get_config_value(entry, CONF_UNITS) @@ -55,9 +55,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: pw_entity_rounding = _get_config_value(entry, PW_ROUND) pw_scan_Int = _get_config_value(entry, CONF_SCAN_INTERVAL) + # If scan_interval config value is not configured fall back to the entry data config value if not pw_scan_Int: pw_scan_Int = entry.data[CONF_SCAN_INTERVAL] + # If latitude or longitude is not configured fall back to the HA location + if not latitude: + latitude = hass.config.latitude + if not longitude: + longitude = hass.config.longitude + pw_scan_Int = max(pw_scan_Int, 60) # Extract list of int from forecast days/ hours string if present diff --git a/custom_components/pirateweather/manifest.json b/custom_components/pirateweather/manifest.json index 605b344..5f2f921 100644 --- a/custom_components/pirateweather/manifest.json +++ b/custom_components/pirateweather/manifest.json @@ -9,5 +9,5 @@ "documentation": "https://github.com/alexander0042/pirate-weather-ha", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/alexander0042/pirate-weather-ha/issues", - "version": "1.6.1.1" -} + "version": "1.6.2b1" +} \ No newline at end of file