Separate the yolink garage door device from the door sensor (#84561)
* Separate the garage door device from the door sensor * Bump yolink api to 0.2.1 * fix suggest * fix typos * Bump yolink-api to 0.2.6 * Bump version to 0.2.7 and fix rename effects * change aiohttp min version to 3.8.1
This commit is contained in:
parent
4dba9c09fc
commit
d6e817aa62
15 changed files with 152 additions and 176 deletions
|
@ -3,6 +3,9 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
from yolink.const import ATTR_DEVICE_THERMOSTAT
|
||||
from yolink.thermostat_request_builder import ThermostatRequestBuilder, ThermostatState
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
ATTR_TARGET_TEMP_LOW,
|
||||
|
@ -20,7 +23,7 @@ from homeassistant.const import UnitOfTemperature
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import ATTR_COORDINATORS, ATTR_DEVICE_THERMOSTAT, DOMAIN
|
||||
from .const import DOMAIN
|
||||
from .coordinator import YoLinkCoordinator
|
||||
from .entity import YoLinkEntity
|
||||
|
||||
|
@ -46,7 +49,7 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up YoLink Thermostat from a config entry."""
|
||||
device_coordinators = hass.data[DOMAIN][config_entry.entry_id][ATTR_COORDINATORS]
|
||||
device_coordinators = hass.data[DOMAIN][config_entry.entry_id].device_coordinators
|
||||
entities = [
|
||||
YoLinkClimateEntity(config_entry, device_coordinator)
|
||||
for device_coordinator in device_coordinators.values()
|
||||
|
@ -107,12 +110,18 @@ class YoLinkClimateEntity(YoLinkEntity, ClimateEntity):
|
|||
"""Set new target hvac mode."""
|
||||
if (hvac_mode_id := HA_MODEL_2_YOLINK.get(hvac_mode)) is None:
|
||||
raise ValueError(f"Received an invalid hvac mode: {hvac_mode}")
|
||||
await self.call_device_api("setState", {"mode": hvac_mode_id})
|
||||
await self.call_device(
|
||||
ThermostatRequestBuilder.set_state_request(
|
||||
ThermostatState(mode=hvac_mode_id)
|
||||
)
|
||||
)
|
||||
await self.coordinator.async_refresh()
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set fan mode."""
|
||||
await self.call_device_api("setState", {"fan": fan_mode})
|
||||
await self.call_device(
|
||||
ThermostatRequestBuilder.set_state_request(ThermostatState(fan=fan_mode))
|
||||
)
|
||||
self._attr_fan_mode = fan_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
@ -121,16 +130,24 @@ class YoLinkClimateEntity(YoLinkEntity, ClimateEntity):
|
|||
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||
if target_temp_low is not None:
|
||||
await self.call_device_api("setState", {"lowTemp": target_temp_low})
|
||||
await self.call_device(
|
||||
ThermostatRequestBuilder.set_state_request(
|
||||
ThermostatState(lowTemp=target_temp_low)
|
||||
)
|
||||
)
|
||||
self._attr_target_temperature_low = target_temp_low
|
||||
if target_temp_high is not None:
|
||||
await self.call_device_api("setState", {"highTemp": target_temp_high})
|
||||
await self.call_device(
|
||||
ThermostatRequestBuilder.set_state_request(
|
||||
ThermostatState(highTemp=target_temp_high)
|
||||
)
|
||||
)
|
||||
self._attr_target_temperature_high = target_temp_high
|
||||
await self.coordinator.async_refresh()
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set preset mode."""
|
||||
eco_params = "on" if preset_mode == PRESET_ECO else "off"
|
||||
await self.call_device_api("setECO", {"mode": eco_params})
|
||||
await self.call_device(ThermostatRequestBuilder.set_eco_request(eco_params))
|
||||
self._attr_preset_mode = PRESET_ECO if eco_params == "on" else PRESET_NONE
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue