Skip to content

Commit

Permalink
Display and health mode switches for haier platform added
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldn committed Aug 19, 2024
1 parent 1a959f1 commit e4d5c14
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 5 deletions.
14 changes: 14 additions & 0 deletions components/haier/haier_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ void HaierClimateBase::control(const ClimateCall &call) {
}
}

void HaierClimateBase::set_display_switch(switch_::Switch *sw) {
this->display_switch_ = sw;
if ((this->display_switch_ != nullptr) && (this->valid_connection())) {
this->display_switch_->publish_state(this->display_status_);
}
}

void HaierClimateBase::set_health_mode_switch(switch_::Switch *sw) {
this->health_mode_switch_ = sw;
if ((this->health_mode_switch_ != nullptr) && (this->valid_connection())) {
this->health_mode_switch_->publish_state(this->health_mode_);
}
}

void HaierClimateBase::HvacSettings::reset() {
this->valid = false;
this->mode.reset();
Expand Down
13 changes: 13 additions & 0 deletions components/haier/haier_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
// HaierProtocol
#include <protocol/haier_protocol.h>

#ifdef USE_SWITCH
#include "esphome/components/switch/switch.h"
#endif

namespace esphome {
namespace haier {

Expand All @@ -24,6 +28,15 @@ class HaierClimateBase : public esphome::Component,
public esphome::climate::Climate,
public esphome::uart::UARTDevice,
public haier_protocol::ProtocolStream {
#ifdef USE_SWITCH
public:
void set_display_switch(switch_::Switch *sw);
void set_health_mode_switch(switch_::Switch *sw);

protected:
switch_::Switch *display_switch_{nullptr};
switch_::Switch *health_mode_switch_{nullptr};
#endif
public:
HaierClimateBase();
HaierClimateBase(const HaierClimateBase &) = delete;
Expand Down
11 changes: 6 additions & 5 deletions components/haier/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
async def to_code(config):
full_id, parent = await cg.get_variable_with_full_id(config[CONF_HAIER_ID])

# for switch_type in [CONF_DISPLAY, CONF_HEALTH_MODE]:
# if conf := config.get(switch_type):
# sw_var = await switch.new_switch(conf)
# await cg.register_parented(sw_var, parent)
for switch_type in [CONF_DISPLAY, CONF_HEALTH_MODE]:
if conf := config.get(switch_type):
sw_var = await switch.new_switch(conf)
await cg.register_parented(sw_var, parent)
cg.add(getattr(parent, f"set_{switch_type}_switch")(sw_var))
if conf := config.get(CONF_BEEPER):
if full_id.type is HonClimate:
sw_var = await switch.new_switch(conf)
await cg.register_parented(sw_var, parent)
cg.add(getattr(parent, f"set_beeper_switch")(sw_var))
cg.add(getattr(parent, "set_beeper_switch")(sw_var))
else:
raise ValueError("Beeper switch is only supported for hon climate")

11 changes: 11 additions & 0 deletions components/haier/switch/display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "display.h"

namespace esphome {
namespace haier {

void DisplaySwitch::write_state(bool state) {
this->publish_state(state);
}

} // namespace haier
} // namespace esphome
18 changes: 18 additions & 0 deletions components/haier/switch/display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "esphome/components/switch/switch.h"
#include "../haier_base.h"

namespace esphome {
namespace haier {

class DisplaySwitch : public switch_::Switch, public Parented<HaierClimateBase> {
public:
DisplaySwitch() = default;

protected:
void write_state(bool state) override;
};

} // namespace haier
} // namespace esphome
11 changes: 11 additions & 0 deletions components/haier/switch/health_mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "health_mode.h"

namespace esphome {
namespace haier {

void HealthModeSwitch::write_state(bool state) {
this->publish_state(state);
}

} // namespace haier
} // namespace esphome
18 changes: 18 additions & 0 deletions components/haier/switch/health_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "esphome/components/switch/switch.h"
#include "../haier_base.h"

namespace esphome {
namespace haier {

class HealthModeSwitch : public switch_::Switch, public Parented<HaierClimateBase> {
public:
HealthModeSwitch() = default;

protected:
void write_state(bool state) override;
};

} // namespace haier
} // namespace esphome

0 comments on commit e4d5c14

Please sign in to comment.