Skip to content

Commit 3cc9c94

Browse files
author
bruxy70
committed
clear state when options update
1 parent b99933f commit 3cc9c94

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

custom_components/garbage_collection/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ async def async_migrate_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bo
363363

364364
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
365365
"""Update listener - to re-create device after options update."""
366+
for entity in hass.data["garbage_collection"]["sensor"].values():
367+
if entity.unique_id == entry.entry_id:
368+
entity.clear_state()
369+
break
366370
await hass.config_entries.async_forward_entry_unload(entry, const.SENSOR_PLATFORM)
367371
hass.async_add_job(
368372
hass.config_entries.async_forward_entry_setup(entry, const.SENSOR_PLATFORM)

custom_components/garbage_collection/config_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import homeassistant.helpers.config_validation as cv
1111
import voluptuous as vol
1212
from homeassistant.const import ATTR_HIDDEN, CONF_ENTITIES, CONF_NAME, WEEKDAYS
13-
from homeassistant.core import callback
13+
from homeassistant.core import HomeAssistant, callback
1414
from homeassistant.helpers import selector
1515
from homeassistant.helpers.schema_config_entry_flow import (
1616
SchemaConfigFlowHandler,
@@ -183,8 +183,8 @@ def detail_config_schema(
183183

184184

185185
# mypy: ignore-errors
186-
class HolidaysConfigFlowHandler(SchemaConfigFlowHandler, domain=const.DOMAIN):
187-
"""Handle a config or options flow for Holdays."""
186+
class GarbageCollectionConfigFlowHandler(SchemaConfigFlowHandler, domain=const.DOMAIN):
187+
"""Handle a config or options flow for GarbageCollection."""
188188

189189
config_flow = CONFIG_FLOW
190190
options_flow = OPTIONS_FLOW

custom_components/garbage_collection/sensor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ async def async_added_to_hass(self) -> None:
170170
self.entity_id
171171
)
172172

173+
def clear_state(self) -> None:
174+
"""Erase the stored state (called when configuration change)."""
175+
self._attr_state = ""
176+
self._days = None
177+
self._next_date = None
178+
173179
async def async_will_remove_from_hass(self) -> None:
174180
"""When sensor is added to hassio, remove it."""
175181
await super().async_will_remove_from_hass()

0 commit comments

Comments
 (0)