mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Explicitly pass in the config_entry in flick_electric coordinator (#137816)
* explicitly pass in the config_entry in coordinator * Apply suggestions from code review Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com> --------- Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
parent
97cde37702
commit
21dd6fa53d
@ -9,7 +9,6 @@ from pyflick import FlickAPI
|
|||||||
from pyflick.authentication import SimpleFlickAuth
|
from pyflick.authentication import SimpleFlickAuth
|
||||||
from pyflick.const import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET
|
from pyflick.const import DEFAULT_CLIENT_ID, DEFAULT_CLIENT_SECRET
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ACCESS_TOKEN,
|
CONF_ACCESS_TOKEN,
|
||||||
CONF_CLIENT_ID,
|
CONF_CLIENT_ID,
|
||||||
@ -35,9 +34,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FlickConfigEntry) -> boo
|
|||||||
"""Set up Flick Electric from a config entry."""
|
"""Set up Flick Electric from a config entry."""
|
||||||
auth = HassFlickAuth(hass, entry)
|
auth = HassFlickAuth(hass, entry)
|
||||||
|
|
||||||
coordinator = FlickElectricDataCoordinator(
|
coordinator = FlickElectricDataCoordinator(hass, entry, FlickAPI(auth))
|
||||||
hass, FlickAPI(auth), entry.data[CONF_SUPPLY_NODE_REF]
|
|
||||||
)
|
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
@ -53,7 +50,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: FlickConfigEntry) -> bo
|
|||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
||||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_migrate_entry(
|
||||||
|
hass: HomeAssistant, config_entry: FlickConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Migrate old entry."""
|
"""Migrate old entry."""
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Migrating configuration from version %s.%s",
|
"Migrating configuration from version %s.%s",
|
||||||
|
@ -13,6 +13,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
|
from .const import CONF_SUPPLY_NODE_REF
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(minutes=5)
|
SCAN_INTERVAL = timedelta(minutes=5)
|
||||||
@ -23,17 +25,23 @@ type FlickConfigEntry = ConfigEntry[FlickElectricDataCoordinator]
|
|||||||
class FlickElectricDataCoordinator(DataUpdateCoordinator[FlickPrice]):
|
class FlickElectricDataCoordinator(DataUpdateCoordinator[FlickPrice]):
|
||||||
"""Coordinator for flick power price."""
|
"""Coordinator for flick power price."""
|
||||||
|
|
||||||
|
config_entry: FlickConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, api: FlickAPI, supply_node_ref: str
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: FlickConfigEntry,
|
||||||
|
api: FlickAPI,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize FlickElectricDataCoordinator."""
|
"""Initialize FlickElectricDataCoordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Flick Electric",
|
name="Flick Electric",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
self.supply_node_ref = supply_node_ref
|
self.supply_node_ref = config_entry.data[CONF_SUPPLY_NODE_REF]
|
||||||
self._api = api
|
self._api = api
|
||||||
|
|
||||||
async def _async_update_data(self) -> FlickPrice:
|
async def _async_update_data(self) -> FlickPrice:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user