Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion homeassistant/components/melcloud/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PROPERTY_ZONE_2_OPERATION_MODE,
Zone,
)
import voluptuous as vol

from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
Expand All @@ -27,11 +28,23 @@
)
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)

Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -116,6 +141,30 @@ def name(self):
"""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
Comment thread
vilppuvuorinen marked this conversation as resolved.
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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the vertical vane dependent on the horizontal vane?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aww.. That requires another PR to fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There you go: #33580

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."""
Expand Down Expand Up @@ -181,6 +230,22 @@ def fan_modes(self) -> Optional[List[str]]:
"""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."""
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/melcloud/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@

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,
Expand Down
23 changes: 23 additions & 0 deletions homeassistant/components/melcloud/services.yaml
Original file line number Diff line number Diff line change
@@ -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"