Skip to content

Commit

Permalink
Avoid reloading config when not in correct state
Browse files Browse the repository at this point in the history
  • Loading branch information
pnbruckner committed Feb 29, 2024
1 parent 7782561 commit 4dc7517
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions custom_components/illuminance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
7 changes: 2 additions & 5 deletions custom_components/illuminance/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/illuminance/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4dc7517

Please sign in to comment.