Skip to content
Snippets Groups Projects
Unverified Commit 28e68eaa authored by Chris Talkington's avatar Chris Talkington Committed by GitHub
Browse files

Reload sonarr config entry on options update (#41958)

parent b04837e9
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,6 @@ from homeassistant.const import (
)
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
......@@ -125,9 +124,7 @@ def _async_start_reauth(hass: HomeAssistantType, entry: ConfigEntry):
async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry) -> None:
"""Handle options update."""
async_dispatcher_send(
hass, f"sonarr.{entry.entry_id}.entry_options_update", entry.options
)
await hass.config_entries.async_reload(entry.entry_id)
class SonarrEntity(Entity):
......
......@@ -7,7 +7,6 @@ from sonarr import Sonarr, SonarrConnectionError, SonarrError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_GIGABYTES
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
import homeassistant.util.dt as dt_util
......@@ -291,18 +290,6 @@ class SonarrUpcomingSensor(SonarrSensor):
unit_of_measurement="Episodes",
)
async def async_added_to_hass(self):
"""Listen for signals."""
await super().async_added_to_hass()
self.async_on_remove(
async_dispatcher_connect(
self.hass,
f"sonarr.{self._entry_id}.entry_options_update",
self.async_update_entry_options,
)
)
@sonarr_exception_handler
async def async_update(self) -> None:
"""Update entity."""
......@@ -313,10 +300,6 @@ class SonarrUpcomingSensor(SonarrSensor):
start=start.isoformat(), end=end.isoformat()
)
async def async_update_entry_options(self, options: dict) -> None:
"""Update sensor settings when config entry options are update."""
self._days = options[CONF_UPCOMING_DAYS]
@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the state attributes of the entity."""
......@@ -352,28 +335,12 @@ class SonarrWantedSensor(SonarrSensor):
enabled_default=False,
)
async def async_added_to_hass(self):
"""Listen for signals."""
await super().async_added_to_hass()
self.async_on_remove(
async_dispatcher_connect(
self.hass,
f"sonarr.{self._entry_id}.entry_options_update",
self.async_update_entry_options,
)
)
@sonarr_exception_handler
async def async_update(self) -> None:
"""Update entity."""
self._results = await self.sonarr.wanted(page_size=self._max_items)
self._total = self._results.total
async def async_update_entry_options(self, options: dict) -> None:
"""Update sensor settings when config entry options are update."""
self._max_items = options[CONF_WANTED_MAX_ITEMS]
@property
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the state attributes of the entity."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment