mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Explicitly pass in the config_entry in twinkly coordinator (#137889)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
b54b90a604
commit
3153c54d1a
@ -5,23 +5,19 @@ import logging
|
|||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
from ttls.client import Twinkly
|
from ttls.client import Twinkly
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_HOST, Platform
|
from homeassistant.const import CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import TwinklyCoordinator
|
from .coordinator import TwinklyConfigEntry, TwinklyCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.LIGHT, Platform.SELECT]
|
PLATFORMS = [Platform.LIGHT, Platform.SELECT]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
type TwinklyConfigEntry = ConfigEntry[TwinklyCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: TwinklyConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: TwinklyConfigEntry) -> bool:
|
||||||
"""Set up entries from config flow."""
|
"""Set up entries from config flow."""
|
||||||
# We setup the client here so if at some point we add any other entity for this device,
|
# We setup the client here so if at some point we add any other entity for this device,
|
||||||
@ -30,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TwinklyConfigEntry) -> b
|
|||||||
|
|
||||||
client = Twinkly(host, async_get_clientsession(hass))
|
client = Twinkly(host, async_get_clientsession(hass))
|
||||||
|
|
||||||
coordinator = TwinklyCoordinator(hass, client)
|
coordinator = TwinklyCoordinator(hass, entry, client)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from aiohttp import ClientError
|
|||||||
from awesomeversion import AwesomeVersion
|
from awesomeversion import AwesomeVersion
|
||||||
from ttls.client import Twinkly, TwinklyError
|
from ttls.client import Twinkly, TwinklyError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
@ -17,6 +18,8 @@ from .const import DEV_NAME, DOMAIN, MIN_EFFECT_VERSION
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type TwinklyConfigEntry = ConfigEntry[TwinklyCoordinator]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TwinklyData:
|
class TwinklyData:
|
||||||
@ -33,15 +36,19 @@ class TwinklyData:
|
|||||||
class TwinklyCoordinator(DataUpdateCoordinator[TwinklyData]):
|
class TwinklyCoordinator(DataUpdateCoordinator[TwinklyData]):
|
||||||
"""Class to manage fetching Twinkly data from API."""
|
"""Class to manage fetching Twinkly data from API."""
|
||||||
|
|
||||||
|
config_entry: TwinklyConfigEntry
|
||||||
software_version: str
|
software_version: str
|
||||||
supports_effects: bool
|
supports_effects: bool
|
||||||
device_name: str
|
device_name: str
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, client: Twinkly) -> None:
|
def __init__(
|
||||||
|
self, hass: HomeAssistant, config_entry: TwinklyConfigEntry, client: Twinkly
|
||||||
|
) -> None:
|
||||||
"""Initialize global Twinkly data updater."""
|
"""Initialize global Twinkly data updater."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=timedelta(seconds=30),
|
update_interval=timedelta(seconds=30),
|
||||||
)
|
)
|
||||||
|
@ -10,8 +10,8 @@ from homeassistant.const import ATTR_SW_VERSION, CONF_HOST, CONF_IP_ADDRESS, CON
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import TwinklyConfigEntry
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .coordinator import TwinklyConfigEntry
|
||||||
|
|
||||||
TO_REDACT = [CONF_HOST, CONF_IP_ADDRESS, CONF_MAC]
|
TO_REDACT = [CONF_HOST, CONF_IP_ADDRESS, CONF_MAC]
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ from homeassistant.components.light import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import TwinklyConfigEntry, TwinklyCoordinator
|
|
||||||
from .const import DEV_LED_PROFILE, DEV_PROFILE_RGB, DEV_PROFILE_RGBW
|
from .const import DEV_LED_PROFILE, DEV_PROFILE_RGB, DEV_PROFILE_RGBW
|
||||||
|
from .coordinator import TwinklyConfigEntry, TwinklyCoordinator
|
||||||
from .entity import TwinklyEntity
|
from .entity import TwinklyEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -10,7 +10,7 @@ from homeassistant.components.select import SelectEntity
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import TwinklyConfigEntry, TwinklyCoordinator
|
from .coordinator import TwinklyConfigEntry, TwinklyCoordinator
|
||||||
from .entity import TwinklyEntity
|
from .entity import TwinklyEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user