mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add melcloud AtaDevice vane control (#32672)
* Add melcloud AtaDevice vane control * Return empty dict when no vane states available Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com> * Use constants for services and conf * Split state attribute assignment and fix suggested changes * Log valid positions when called with an invalid position * Improve service description Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com> Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
This commit is contained in:
parent
4caf65dc97
commit
4b2c45e668
@ -11,6 +11,7 @@ from pymelcloud.atw_device import (
|
||||
PROPERTY_ZONE_2_OPERATION_MODE,
|
||||
Zone,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
@ -27,11 +28,23 @@ from homeassistant.components.climate.const import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.util.temperature import convert as convert_temperature
|
||||
|
||||
from . import MelCloudDevice
|
||||
from .const import ATTR_STATUS, DOMAIN, TEMP_UNIT_LOOKUP
|
||||
from .const import (
|
||||
ATTR_STATUS,
|
||||
ATTR_VANE_HORIZONTAL,
|
||||
ATTR_VANE_HORIZONTAL_POSITIONS,
|
||||
ATTR_VANE_VERTICAL,
|
||||
ATTR_VANE_VERTICAL_POSITIONS,
|
||||
CONF_POSITION,
|
||||
DOMAIN,
|
||||
SERVICE_SET_VANE_HORIZONTAL,
|
||||
SERVICE_SET_VANE_VERTICAL,
|
||||
TEMP_UNIT_LOOKUP,
|
||||
)
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=60)
|
||||
|
||||
@ -73,6 +86,18 @@ async def async_setup_entry(
|
||||
True,
|
||||
)
|
||||
|
||||
platform = entity_platform.current_platform.get()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_VANE_HORIZONTAL,
|
||||
{vol.Required(CONF_POSITION): cv.string},
|
||||
"async_set_vane_horizontal",
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_VANE_VERTICAL,
|
||||
{vol.Required(CONF_POSITION): cv.string},
|
||||
"async_set_vane_vertical",
|
||||
)
|
||||
|
||||
|
||||
class MelCloudClimate(ClimateDevice):
|
||||
"""Base climate device."""
|
||||
@ -116,6 +141,30 @@ class AtaDeviceClimate(MelCloudClimate):
|
||||
"""Return the display name of this entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
|
||||
"""Return the optional state attributes with device specific additions."""
|
||||
attr = {}
|
||||
|
||||
vane_horizontal = self._device.vane_horizontal
|
||||
if vane_horizontal:
|
||||
attr.update(
|
||||
{
|
||||
ATTR_VANE_HORIZONTAL: vane_horizontal,
|
||||
ATTR_VANE_HORIZONTAL_POSITIONS: self._device.vane_horizontal_positions,
|
||||
}
|
||||
)
|
||||
|
||||
vane_vertical = self._device.vane_vertical
|
||||
if vane_horizontal:
|
||||
attr.update(
|
||||
{
|
||||
ATTR_VANE_VERTICAL: vane_vertical,
|
||||
ATTR_VANE_VERTICAL_POSITIONS: self._device.vane_vertical_positions,
|
||||
}
|
||||
)
|
||||
return attr
|
||||
|
||||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement used by the platform."""
|
||||
@ -181,6 +230,22 @@ class AtaDeviceClimate(MelCloudClimate):
|
||||
"""Return the list of available fan modes."""
|
||||
return self._device.fan_speeds
|
||||
|
||||
async def async_set_vane_horizontal(self, position: str) -> None:
|
||||
"""Set horizontal vane position."""
|
||||
if position not in self._device.vane_horizontal_positions:
|
||||
raise ValueError(
|
||||
f"Invalid horizontal vane position {position}. Valid positions: [{self._device.vane_horizontal_positions}]."
|
||||
)
|
||||
await self._device.set({ata.PROPERTY_VANE_HORIZONTAL: position})
|
||||
|
||||
async def async_set_vane_vertical(self, position: str) -> None:
|
||||
"""Set vertical vane position."""
|
||||
if position not in self._device.vane_vertical_positions:
|
||||
raise ValueError(
|
||||
f"Invalid vertical vane position {position}. Valid positions: [{self._device.vane_vertical_positions}]."
|
||||
)
|
||||
await self._device.set({ata.PROPERTY_VANE_VERTICAL: position})
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
|
@ -5,7 +5,16 @@ from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
|
||||
DOMAIN = "melcloud"
|
||||
|
||||
CONF_POSITION = "position"
|
||||
|
||||
ATTR_STATUS = "status"
|
||||
ATTR_VANE_HORIZONTAL = "vane_horizontal"
|
||||
ATTR_VANE_HORIZONTAL_POSITIONS = "vane_horizontal_positions"
|
||||
ATTR_VANE_VERTICAL = "vane_vertical"
|
||||
ATTR_VANE_VERTICAL_POSITIONS = "vane_vertical_positions"
|
||||
|
||||
SERVICE_SET_VANE_HORIZONTAL = "set_vane_horizontal"
|
||||
SERVICE_SET_VANE_VERTICAL = "set_vane_vertical"
|
||||
|
||||
TEMP_UNIT_LOOKUP = {
|
||||
UNIT_TEMP_CELSIUS: TEMP_CELSIUS,
|
||||
|
23
homeassistant/components/melcloud/services.yaml
Normal file
23
homeassistant/components/melcloud/services.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
set_vane_horizontal:
|
||||
description: Sets horizontal vane position.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the target entity
|
||||
example: "climate.ac_1"
|
||||
position:
|
||||
description: >
|
||||
Horizontal vane position. Possible options can be found in the
|
||||
vane_horizontal_positions state attribute.
|
||||
example: "auto"
|
||||
|
||||
set_vane_vertical:
|
||||
description: Sets vertical vane position.
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name of the target entity
|
||||
example: "climate.ac_1"
|
||||
position:
|
||||
description: >
|
||||
Vertical vane position. Possible options can be found in the
|
||||
vane_vertical_positions state attribute.
|
||||
example: "auto"
|
Loading…
x
Reference in New Issue
Block a user