Explicitly pass in the config_entry in venstar coordinator (#137880)

* explicitly pass in the config_entry in coordinator

* use common name config_entry
This commit is contained in:
Michael 2025-02-09 14:37:31 +01:00 committed by GitHub
parent 4031f85acc
commit 4646d35054
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

@ -21,14 +21,14 @@ from .coordinator import VenstarDataUpdateCoordinator
PLATFORMS = [Platform.BINARY_SENSOR, Platform.CLIMATE, Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Set up the Venstar thermostat."""
username = config.data.get(CONF_USERNAME)
password = config.data.get(CONF_PASSWORD)
pin = config.data.get(CONF_PIN)
host = config.data[CONF_HOST]
username = config_entry.data.get(CONF_USERNAME)
password = config_entry.data.get(CONF_PASSWORD)
pin = config_entry.data.get(CONF_PIN)
host = config_entry.data[CONF_HOST]
timeout = VENSTAR_TIMEOUT
protocol = "https" if config.data[CONF_SSL] else "http"
protocol = "https" if config_entry.data[CONF_SSL] else "http"
client = VenstarColorTouch(
addr=host,
@ -41,19 +41,22 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
venstar_data_coordinator = VenstarDataUpdateCoordinator(
hass,
config_entry,
venstar_connection=client,
)
await venstar_data_coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[config.entry_id] = venstar_data_coordinator
await hass.config_entries.async_forward_entry_setups(config, PLATFORMS)
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = venstar_data_coordinator
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload the config and platforms."""
unload_ok = await hass.config_entries.async_unload_platforms(config, PLATFORMS)
unload_ok = await hass.config_entries.async_unload_platforms(
config_entry, PLATFORMS
)
if unload_ok:
hass.data[DOMAIN].pop(config.entry_id)
hass.data[DOMAIN].pop(config_entry.entry_id)
return unload_ok

View File

@ -8,6 +8,7 @@ from datetime import timedelta
from requests import RequestException
from venstarcolortouch import VenstarColorTouch
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import update_coordinator
@ -17,16 +18,19 @@ from .const import _LOGGER, DOMAIN, VENSTAR_SLEEP
class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator[None]):
"""Class to manage fetching Venstar data."""
config_entry: ConfigEntry
def __init__(
self,
hass: HomeAssistant,
*,
config_entry: ConfigEntry,
venstar_connection: VenstarColorTouch,
) -> None:
"""Initialize global Venstar data updater."""
super().__init__(
hass,
_LOGGER,
config_entry=config_entry,
name=DOMAIN,
update_interval=timedelta(seconds=60),
)