mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Explicitly pass in the config_entry in philips_js coordinator (#138042)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
28f83cefda
commit
4d5987fa80
@ -7,7 +7,6 @@ import logging
|
||||
from haphilipsjs import PhilipsTV
|
||||
from haphilipsjs.typing import SystemType
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_API_VERSION,
|
||||
CONF_HOST,
|
||||
@ -18,7 +17,7 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_SYSTEM
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
@ -30,8 +29,6 @@ PLATFORMS = [
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PhilipsTVConfigEntry = ConfigEntry[PhilipsTVDataUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: PhilipsTVConfigEntry) -> bool:
|
||||
"""Set up Philips TV from a config entry."""
|
||||
@ -44,7 +41,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: PhilipsTVConfigEntry) ->
|
||||
password=entry.data.get(CONF_PASSWORD),
|
||||
system=system,
|
||||
)
|
||||
coordinator = PhilipsTVDataUpdateCoordinator(hass, tvapi, entry.options)
|
||||
coordinator = PhilipsTVDataUpdateCoordinator(hass, entry, tvapi)
|
||||
|
||||
await coordinator.async_refresh()
|
||||
|
||||
|
@ -13,8 +13,7 @@ from homeassistant.components.binary_sensor import (
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
from .entity import PhilipsJsEntity
|
||||
|
||||
|
||||
|
@ -3,10 +3,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Mapping
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from haphilipsjs import (
|
||||
AutenticationFailure,
|
||||
@ -27,23 +25,28 @@ from .const import CONF_ALLOW_NOTIFY, CONF_SYSTEM, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type PhilipsTVConfigEntry = ConfigEntry[PhilipsTVDataUpdateCoordinator]
|
||||
|
||||
|
||||
class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
"""Coordinator to update data."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: PhilipsTVConfigEntry
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, api: PhilipsTV, options: Mapping[str, Any]
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: PhilipsTVConfigEntry,
|
||||
api: PhilipsTV,
|
||||
) -> None:
|
||||
"""Set up the coordinator."""
|
||||
self.api = api
|
||||
self.options = options
|
||||
self._notify_future: asyncio.Task | None = None
|
||||
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=DOMAIN,
|
||||
update_interval=timedelta(seconds=30),
|
||||
request_refresh_debouncer=Debouncer(
|
||||
@ -91,7 +94,7 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
self.api.on
|
||||
and self.api.powerstate == "On"
|
||||
and self.api.notify_change_supported
|
||||
and self.options.get(CONF_ALLOW_NOTIFY, False)
|
||||
and self.config_entry.options.get(CONF_ALLOW_NOTIFY, False)
|
||||
)
|
||||
|
||||
async def _notify_task(self):
|
||||
|
@ -7,7 +7,7 @@ from typing import Any
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
"serialnumber_encrypted",
|
||||
|
@ -21,8 +21,7 @@ from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.color import color_hsv_to_RGB, color_RGB_to_hsv
|
||||
|
||||
from . import PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
from .entity import PhilipsJsEntity
|
||||
|
||||
EFFECT_PARTITION = ": "
|
||||
|
@ -21,8 +21,8 @@ from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.trigger import PluggableAction
|
||||
|
||||
from . import LOGGER as _LOGGER, PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from . import LOGGER as _LOGGER
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
from .entity import PhilipsJsEntity
|
||||
from .helpers import async_get_turn_on_trigger
|
||||
|
||||
|
@ -16,8 +16,8 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.trigger import PluggableAction
|
||||
|
||||
from . import LOGGER, PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from . import LOGGER
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
from .entity import PhilipsJsEntity
|
||||
from .helpers import async_get_turn_on_trigger
|
||||
|
||||
|
@ -8,8 +8,7 @@ from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PhilipsTVConfigEntry
|
||||
from .coordinator import PhilipsTVDataUpdateCoordinator
|
||||
from .coordinator import PhilipsTVConfigEntry, PhilipsTVDataUpdateCoordinator
|
||||
from .entity import PhilipsJsEntity
|
||||
|
||||
HUE_POWER_OFF = "Off"
|
||||
|
Loading…
x
Reference in New Issue
Block a user