Reload sonarr config entry on options update (#41958)
This commit is contained in:
parent
b04837e901
commit
28e68eaada
2 changed files with 1 additions and 37 deletions
|
@ -18,7 +18,6 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
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.entity import Entity
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
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:
|
async def _async_update_listener(hass: HomeAssistantType, entry: ConfigEntry) -> None:
|
||||||
"""Handle options update."""
|
"""Handle options update."""
|
||||||
async_dispatcher_send(
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
hass, f"sonarr.{entry.entry_id}.entry_options_update", entry.options
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SonarrEntity(Entity):
|
class SonarrEntity(Entity):
|
||||||
|
|
|
@ -7,7 +7,6 @@ from sonarr import Sonarr, SonarrConnectionError, SonarrError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import DATA_GIGABYTES
|
from homeassistant.const import DATA_GIGABYTES
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
@ -291,18 +290,6 @@ class SonarrUpcomingSensor(SonarrSensor):
|
||||||
unit_of_measurement="Episodes",
|
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
|
@sonarr_exception_handler
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update entity."""
|
"""Update entity."""
|
||||||
|
@ -313,10 +300,6 @@ class SonarrUpcomingSensor(SonarrSensor):
|
||||||
start=start.isoformat(), end=end.isoformat()
|
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
|
@property
|
||||||
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Return the state attributes of the entity."""
|
"""Return the state attributes of the entity."""
|
||||||
|
@ -352,28 +335,12 @@ class SonarrWantedSensor(SonarrSensor):
|
||||||
enabled_default=False,
|
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
|
@sonarr_exception_handler
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update entity."""
|
"""Update entity."""
|
||||||
self._results = await self.sonarr.wanted(page_size=self._max_items)
|
self._results = await self.sonarr.wanted(page_size=self._max_items)
|
||||||
self._total = self._results.total
|
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
|
@property
|
||||||
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Return the state attributes of the entity."""
|
"""Return the state attributes of the entity."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue