Code cleanups for lookin (#64106)

This commit is contained in:
J. Nick Koston 2022-01-14 14:22:06 -10:00 committed by GitHub
parent b949199866
commit 06329a2f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 149 additions and 185 deletions

View file

@ -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(