1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 20:02:22 +01:00

Add support for controlling fan direction (#1051)

* Fix fan oscillation trait not being used

* Add fan direction support to SpeedFan

* Add fan direction to API

* Add fan direction support to BinaryFan

* Fix CI errors

* Fix python format

* Change some ordering to trigger CI

* Add test for the configuration
This commit is contained in:
Jim Persson
2020-06-14 21:54:31 +02:00
committed by GitHub
parent 35a2258f12
commit 0bb81e5b2d
16 changed files with 156 additions and 17 deletions

View File

@@ -248,6 +248,8 @@ bool APIConnection::send_fan_state(fan::FanState *fan) {
resp.oscillating = fan->oscillating;
if (traits.supports_speed())
resp.speed = static_cast<enums::FanSpeed>(fan->speed);
if (traits.supports_direction())
resp.direction = static_cast<enums::FanDirection>(fan->direction);
return this->send_fan_state_response(resp);
}
bool APIConnection::send_fan_info(fan::FanState *fan) {
@@ -259,6 +261,7 @@ bool APIConnection::send_fan_info(fan::FanState *fan) {
msg.unique_id = get_default_unique_id("fan", fan);
msg.supports_oscillation = traits.supports_oscillation();
msg.supports_speed = traits.supports_speed();
msg.supports_direction = traits.supports_direction();
return this->send_list_entities_fan_response(msg);
}
void APIConnection::fan_command(const FanCommandRequest &msg) {
@@ -273,6 +276,8 @@ void APIConnection::fan_command(const FanCommandRequest &msg) {
call.set_oscillating(msg.oscillating);
if (msg.has_speed)
call.set_speed(static_cast<fan::FanSpeed>(msg.speed));
if (msg.has_direction)
call.set_direction(static_cast<fan::FanDirection>(msg.direction));
call.perform();
}
#endif