Code cleanups for lookin (#64106)
This commit is contained in:
parent
b949199866
commit
06329a2f43
7 changed files with 149 additions and 185 deletions
|
@ -1,8 +1,6 @@
|
|||
"""The lookin integration climate platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any, Final, cast
|
||||
|
||||
|
@ -29,12 +27,17 @@ from homeassistant.components.climate.const import (
|
|||
SWING_OFF,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_WHOLE,
|
||||
TEMP_CELSIUS,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, TYPE_TO_PLATFORM
|
||||
from .entity import LookinCoordinatorEntity
|
||||
from .models import LookinData
|
||||
|
||||
|
@ -77,30 +80,10 @@ async def async_setup_entry(
|
|||
entities = []
|
||||
|
||||
for remote in lookin_data.devices:
|
||||
if remote["Type"] != "EF":
|
||||
if TYPE_TO_PLATFORM.get(remote["Type"]) != Platform.CLIMATE:
|
||||
continue
|
||||
uuid = remote["UUID"]
|
||||
|
||||
def _wrap_async_update(
|
||||
uuid: str,
|
||||
) -> Callable[[], Coroutine[None, Any, Climate]]:
|
||||
"""Create a function to capture the uuid cell variable."""
|
||||
|
||||
async def _async_update() -> Climate:
|
||||
return await lookin_data.lookin_protocol.get_conditioner(uuid)
|
||||
|
||||
return _async_update
|
||||
|
||||
coordinator = DataUpdateCoordinator(
|
||||
hass,
|
||||
LOGGER,
|
||||
name=f"{config_entry.title} {uuid}",
|
||||
update_method=_wrap_async_update(uuid),
|
||||
update_interval=timedelta(
|
||||
seconds=60
|
||||
), # Updates are pushed (fallback is polling)
|
||||
)
|
||||
await coordinator.async_refresh()
|
||||
coordinator = lookin_data.device_coordinators[uuid]
|
||||
device: Climate = coordinator.data
|
||||
entities.append(
|
||||
ConditionerEntity(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue