diff --git a/homeassistant/components/melcloud/climate.py b/homeassistant/components/melcloud/climate.py index c661b1a59ad..df3d9e89392 100644 --- a/homeassistant/components/melcloud/climate.py +++ b/homeassistant/components/melcloud/climate.py @@ -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.""" diff --git a/homeassistant/components/melcloud/const.py b/homeassistant/components/melcloud/const.py index c6ce4391294..d58f483d441 100644 --- a/homeassistant/components/melcloud/const.py +++ b/homeassistant/components/melcloud/const.py @@ -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, diff --git a/homeassistant/components/melcloud/services.yaml b/homeassistant/components/melcloud/services.yaml new file mode 100644 index 00000000000..40faa097d9b --- /dev/null +++ b/homeassistant/components/melcloud/services.yaml @@ -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"