Explicitly pass in the config_entry in switchbee coordinator (#137923)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 21:19:08 +01:00 committed by GitHub
parent a7dbcf72c2
commit 43569df537
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -63,10 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
websession = async_get_clientsession(hass, verify_ssl=False) websession = async_get_clientsession(hass, verify_ssl=False)
api = await get_api_object(central_unit, user, password, websession) api = await get_api_object(central_unit, user, password, websession)
coordinator = SwitchBeeCoordinator( coordinator = SwitchBeeCoordinator(hass, entry, api)
hass,
api,
)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
entry.async_on_unload(entry.add_update_listener(update_listener)) entry.async_on_unload(entry.add_update_listener(update_listener))

View File

@ -10,6 +10,7 @@ from switchbee.api import CentralUnitPolling, CentralUnitWsRPC
from switchbee.api.central_unit import SwitchBeeError from switchbee.api.central_unit import SwitchBeeError
from switchbee.device import DeviceType, SwitchBeeBaseDevice from switchbee.device import DeviceType, SwitchBeeBaseDevice
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.device_registry import format_mac
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
@ -22,9 +23,12 @@ _LOGGER = logging.getLogger(__name__)
class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevice]]): class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevice]]):
"""Class to manage fetching SwitchBee data API.""" """Class to manage fetching SwitchBee data API."""
config_entry: ConfigEntry
def __init__( def __init__(
self, self,
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry,
swb_api: CentralUnitPolling | CentralUnitWsRPC, swb_api: CentralUnitPolling | CentralUnitWsRPC,
) -> None: ) -> None:
"""Initialize.""" """Initialize."""
@ -39,6 +43,7 @@ class SwitchBeeCoordinator(DataUpdateCoordinator[Mapping[int, SwitchBeeBaseDevic
super().__init__( super().__init__(
hass, hass,
_LOGGER, _LOGGER,
config_entry=config_entry,
name=DOMAIN, name=DOMAIN,
update_interval=timedelta(seconds=SCAN_INTERVAL_SEC[type(self.api)]), update_interval=timedelta(seconds=SCAN_INTERVAL_SEC[type(self.api)]),
) )