Skip to content

Commit

Permalink
clear state when options update
Browse files Browse the repository at this point in the history
  • Loading branch information
bruxy70 committed Jul 14, 2022
1 parent b99933f commit 3cc9c94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions custom_components/garbage_collection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ async def async_migrate_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bo

async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update listener - to re-create device after options update."""
for entity in hass.data["garbage_collection"]["sensor"].values():
if entity.unique_id == entry.entry_id:
entity.clear_state()
break
await hass.config_entries.async_forward_entry_unload(entry, const.SENSOR_PLATFORM)
hass.async_add_job(
hass.config_entries.async_forward_entry_setup(entry, const.SENSOR_PLATFORM)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/garbage_collection/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.const import ATTR_HIDDEN, CONF_ENTITIES, CONF_NAME, WEEKDAYS
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import (
SchemaConfigFlowHandler,
Expand Down Expand Up @@ -183,8 +183,8 @@ def detail_config_schema(


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

config_flow = CONFIG_FLOW
options_flow = OPTIONS_FLOW
Expand Down
6 changes: 6 additions & 0 deletions custom_components/garbage_collection/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ async def async_added_to_hass(self) -> None:
self.entity_id
)

def clear_state(self) -> None:
"""Erase the stored state (called when configuration change)."""
self._attr_state = ""
self._days = None
self._next_date = None

async def async_will_remove_from_hass(self) -> None:
"""When sensor is added to hassio, remove it."""
await super().async_will_remove_from_hass()
Expand Down

0 comments on commit 3cc9c94

Please sign in to comment.