From 1970f73a74e0709a8493c727fa8e7da2372ecb17 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Thu, 29 Feb 2024 13:41:42 -0600 Subject: [PATCH] Avoid reloading config when not in correct state (#62) --- .github/workflows/validate.yml | 2 +- custom_components/illuminance/__init__.py | 2 ++ custom_components/illuminance/config_flow.py | 7 ++----- custom_components/illuminance/sensor.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index c3069e1..e8a997d 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,7 +10,7 @@ jobs: name: With hassfest steps: - name: 📥 Checkout the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 🏃 Hassfest validation uses: "home-assistant/actions/hassfest@master" diff --git a/custom_components/illuminance/__init__.py b/custom_components/illuminance/__init__.py index 32c9e6f..7a71294 100644 --- a/custom_components/illuminance/__init__.py +++ b/custom_components/illuminance/__init__.py @@ -99,6 +99,8 @@ async def reload_config(call: ServiceCall | None = None) -> None: async def entry_updated(hass: HomeAssistant, entry: ConfigEntry) -> None: """Handle config entry update.""" + if not entry.state.recoverable: + return await hass.config_entries.async_reload(entry.entry_id) diff --git a/custom_components/illuminance/config_flow.py b/custom_components/illuminance/config_flow.py index b478389..de3356a 100644 --- a/custom_components/illuminance/config_flow.py +++ b/custom_components/illuminance/config_flow.py @@ -132,12 +132,9 @@ async def async_step_import(self, data: dict[str, Any]) -> FlowResult: cast(timedelta, data[CONF_SCAN_INTERVAL]).total_seconds() / 60 ) if existing_entry := await self.async_set_unique_id(data.pop(CONF_UNIQUE_ID)): - if not self.hass.config_entries.async_update_entry( + self.hass.config_entries.async_update_entry( existing_entry, title=title, options=data - ): - self.hass.async_create_task( - self.hass.config_entries.async_reload(existing_entry.entry_id) - ) + ) return self.async_abort(reason="already_configured") return self.async_create_entry(title=title, data={}, options=data) diff --git a/custom_components/illuminance/sensor.py b/custom_components/illuminance/sensor.py index 8547606..8a24c5c 100644 --- a/custom_components/illuminance/sensor.py +++ b/custom_components/illuminance/sensor.py @@ -153,7 +153,7 @@ class Mode(Enum): @dataclass -class IlluminanceSensorEntityDescription(SensorEntityDescription): +class IlluminanceSensorEntityDescription(SensorEntityDescription): # type: ignore[misc] """Illuminance sensor entity description.""" weather_entity: str | None = None