Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ClimateEntity for horizontal swing support #2309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
70 changes: 70 additions & 0 deletions blog/2024-09-10-climate-horizontal-swing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
author: G Johansson
authorURL: https://github.com/gjohansson-ST
authorImageURL: https://avatars.githubusercontent.com/u/62932417?v=4
authorTwitter: GJohansson
title: "Climate entity now supports independent horizontal swing"
---

As of Home Assistant Core 2024.10, we have implemented an independent property and method for controling horizontal swing in `ClimateEntity`.

Integrations that supports completely independent control and state for vertical and horizontal swing can now use the previous `swing_mode` for vertical support only and use the new `swing_horizontal_mode` for providing the horizontal vane state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the grammatical error.

The sentence should be:

Integrations that support completely independent control and state for vertical and horizontal swing can now use the previous swing_mode for vertical support only and use the new swing_horizontal_mode for providing the horizontal vane state.

-Integrations that supports completely independent control and state for vertical and horizontal swing can now use the previous `swing_mode` for vertical support only and use the new `swing_horizontal_mode` for providing the horizontal vane state.
+Integrations that support completely independent control and state for vertical and horizontal swing can now use the previous `swing_mode` for vertical support only and use the new `swing_horizontal_mode` for providing the horizontal vane state.
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Integrations that supports completely independent control and state for vertical and horizontal swing can now use the previous `swing_mode` for vertical support only and use the new `swing_horizontal_mode` for providing the horizontal vane state.
Integrations that support completely independent control and state for vertical and horizontal swing can now use the previous `swing_mode` for vertical support only and use the new `swing_horizontal_mode` for providing the horizontal vane state.
Tools
LanguageTool

[grammar] ~11-~11: The plural noun “Integrations” expects the verb form “support”.
Context: ... in ClimateEntity. Integrations that supports completely independent control and stat...

(NNS_THAT_VBZ)


Integrations that don't have independent control should still keep using the current `swing_mode` for both vertical and horizontal support.


### Example

Example requirements to implement `swing` and `swing_horizontal` in your climate entity.

```python

class MyClimateEntity(ClimateEntity):
"""Implementation of my climate entity."""

@property
def supported_features(self) -> ClimateEntityFeature:
"""Return the list of supported features."""
return ClimateEntityFeature.SWING_MODE | ClimateEntityFeature.SWING_HORIZONTAL_MODE

@property
def swing_mode(self) -> str | None:
"""Return the swing setting.

Requires ClimateEntityFeature.SWING_MODE.
"""
return self._attr_swing_mode

@property
def swing_modes(self) -> list[str] | None:
"""Return the list of available swing modes.

Requires ClimateEntityFeature.SWING_MODE.
"""
return self._attr_swing_modes

@property
def swing_mode(self) -> str | None:
"""Return the swing setting.

Requires ClimateEntityFeature.SWING_HORIZONTAL_MODE.
"""
return self._attr_swing_horizontal_mode

@property
def swing_modes(self) -> list[str] | None:
"""Return the list of available swing modes.

Requires ClimateEntityFeature.SWING_HORIZONTAL_MODE.
"""
return self._attr_swing_horizontal_modes

async def async_set_swing_mode(self, swing_mode: str) -> None:
"""Set new target swing operation."""
await self.api.set_swing_mode(swing_mode)

async def async_set_swing_horizontal_mode(self, swing_horizontal_mode: str) -> None:
"""Set new target horizontal swing operation."""
await self.api.set_swing_horizontal_mode(swing_horizontal_mode)

```
37 changes: 37 additions & 0 deletions docs/core/entity/climate.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Properties should always only return information from memory and not do I/O (lik
| preset_modes | <code>list[str] &#124; None</code> | **Required by SUPPORT_PRESET_MODE** | The available presets. |
| swing_mode | <code>str &#124; None</code> | **Required by SUPPORT_SWING_MODE** | The swing setting. |
| swing_modes | <code>list[str] &#124; None</code> | **Required by SUPPORT_SWING_MODE** | Returns the list of available swing modes. |
| swing_horizontal_mode | <code>str &#124; None</code> | **Required by SUPPORT_SWING_HORIZONTAL_MODE** | The horizontal swing setting. |
| swing_horizontal_modes | <code>list[str] &#124; None</code> | **Required by SUPPORT_SWING_HORIZONTAL_MODE** | Returns the list of available horizontal swing modes. |
| target_humidity | <code>float &#124; None</code> | `None` | The target humidity the device is trying to reach. |
| target_temperature | <code>float &#124; None</code> | `None` | The temperature currently set to be reached. |
| target_temperature_high | <code>float &#124; None</code> | **Required by TARGET_TEMPERATURE_RANGE** | The upper bound target temperature |
Expand Down Expand Up @@ -102,6 +104,12 @@ A device's fan can have different states. There are a couple of built-in fan mod

The device fan can have different swing modes that it wants the user to know about/control.

:::note

In the case integrations don't have independent control of vertical and horizontal swing, then all possible options should be listed in `swing_modes`, otherwise `swing_modes` provide vertical support and `swing_horizontal_modes` should provide all horizontal options.

:::

| Name | Description |
| ------------------ | ------------------------------------------------- |
| `SWING_OFF` | The fan is not swinging. |
Expand All @@ -110,6 +118,21 @@ The device fan can have different swing modes that it wants the user to know abo
| `SWING_HORIZONTAL` | The fan is swinging horizontal. |
| `SWING_BOTH` | The fan is swinging both horizontal and vertical. |

### Swing horizontal modes

The device fan can have different horizontal swing modes that it wants the user to know about/control.

:::note

This should only be implemented if the integration has independent control of vertical and horizontal swing. In such case the `swing_modes` property will provide vertical support and `swing_horizontal_modes` will provide horizontal support.

:::

| Name | Description |
| ------------------ | ------------------------------------------------- |
| `SWING_OFF` | The fan is not swinging. |
| `SWING_ON` | The fan is swinging. |

## Supported features

Supported features are defined by using values in the `ClimateEntityFeature` enum
Expand All @@ -123,6 +146,7 @@ and are combined using the bitwise or (`|`) operator.
| `FAN_MODE` | The device supports fan modes. |
| `PRESET_MODE` | The device supports presets. |
| `SWING_MODE` | The device supports swing modes. |
| `SWING_HORIZONTAL_MODE` | The device supports horizontal swing modes. |
| `TURN_ON` | The device supports turn on. |
| `TURN_OFF` | The device supports turn off. |

Expand Down Expand Up @@ -243,6 +267,19 @@ class MyClimateEntity(ClimateEntity):
"""Set new target swing operation."""
```

### Set horizontal swing mode

```python
class MyClimateEntity(ClimateEntity):
# Implement one of these methods.

def set_swing_horizontal_mode(self, swing_mode):
"""Set new target horizontal swing operation."""

async def async_set_swing_horizontal_mode(self, swing_mode):
"""Set new target horizontal swing operation."""
```

### Set temperature

```python
Expand Down