Skip to content

Commit

Permalink
Merge branch 'switch_implementation' of https://github.com/paveldn/ha…
Browse files Browse the repository at this point in the history
…ier-esphome into switch_implementation
  • Loading branch information
paveldn committed Aug 22, 2024
2 parents a69e7b1 + eff750e commit ecefe89
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 126 deletions.
34 changes: 32 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,39 @@ Configuration variables:

- **haier_id** (**Required**, `ID <https://esphome.io/guides/configuration-types.html#config-id>`_): The id of Haier climate component
- **self_cleaning** (*Optional*): A button that starts Haier climate self cleaning.
All options from `Text Sensor <https://esphome.io/components/button/index.html#base-button-configuration>`_.
All options from `Button <https://esphome.io/components/button/index.html#base-button-configuration>`_.
- **steri_cleaning** (*Optional*): A button that starts Haier climate 56°C Steri-Clean.
All options from `Text Sensor <https://esphome.io/components/button/index.html#base-button-configuration>`_.
All options from `Button <https://esphome.io/components/button/index.html#base-button-configuration>`_.

.. Generated from esphome-docs/switch/haier.rst
Haier Climate Switches
======================

Additional switches to support additional features for Haier AC.

.. code-block:: yaml
# Example configuration entry
switch:
- platform: haier
beeper:
name: Haier beeper
health_mode:
name: Haier health mode
display:
name: Haier display
Configuration variables:
------------------------

- **haier_id** (**Required**, `ID <https://esphome.io/guides/configuration-types.html#config-id>`_): The id of Haier climate component
- **beeper** (*Optional*): (supported only by hOn) A switch that enables or disables Haier climate sound feedback.
All options from `Switch <https://esphome.io/components/switch/index.html#base-switch-configuration>`_.
- **health_mode** (*Optional*): A switch that enables or disables Haier climate health mode (`UV light sterilization <https://www.haierhvac.eu/en/node/1809>`__).
All options from `Switch <https://esphome.io/components/switch/index.html#base-switch-configuration>`_.
- **display** (*Optional*): A switch that enables or disables Haier climate led display.
All options from `Switch <https://esphome.io/components/switch/index.html#base-switch-configuration>`_.

.. Generated from esp32_backup.rst
Expand Down
10 changes: 10 additions & 0 deletions components/haier/haier_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ void HaierClimateBase::loop() {
}
this->process_phase(now);
this->haier_protocol_.loop();
#ifdef USE_SWITCH
if ((this->display_switch_ != nullptr) && (this->display_switch_->state != this->get_display_state())) {
this->display_switch_->publish_state(this->get_display_state());
}
if ((this->health_mode_switch_ != nullptr) && (this->health_mode_switch_->state != this->get_health_mode())) {
this->health_mode_switch_->publish_state(this->get_health_mode());
}
#endif // USE_SWITCH
}

void HaierClimateBase::process_protocol_reset() {
Expand Down Expand Up @@ -355,6 +363,7 @@ void HaierClimateBase::control(const ClimateCall &call) {
}
}

#ifdef USE_SWITCH
void HaierClimateBase::set_display_switch(switch_::Switch *sw) {
this->display_switch_ = sw;
if ((this->display_switch_ != nullptr) && (this->valid_connection())) {
Expand All @@ -368,6 +377,7 @@ void HaierClimateBase::set_health_mode_switch(switch_::Switch *sw) {
this->health_mode_switch_->publish_state(this->get_health_mode());
}
}
#endif

void HaierClimateBase::HvacSettings::reset() {
this->valid = false;
Expand Down
2 changes: 2 additions & 0 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ HonClimate::~HonClimate() {}
void HonClimate::set_beeper_state(bool state) {
if (state != this->settings_.beeper_state) {
this->settings_.beeper_state = state;
#ifdef USE_SWITCH
this->beeper_switch_->publish_state(state);
#endif
this->rtc_.save(&this->settings_);
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/esphome-docs/climate/haier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ See Also
- :doc:`Haier Climate Binary Sensors </components/binary_sensor/haier>`
- :doc:`Haier Climate Text Sensors </components/text_sensor/haier>`
- :doc:`Haier Climate Buttons </components/button/haier>`
- :doc:`Haier Climate Switches </components/switch/haier>`
- :doc:`/components/climate/index`
- :apiref:`haier/climate/haier.h`
- :ghedit:`Edit`
37 changes: 37 additions & 0 deletions docs/esphome-docs/switch/haier.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Haier Climate Switches
======================

.. seo::
:description: Instructions for setting up additional switches for Haier climate devices.
:image: haier.svg

Additional switches to support additional features for Haier AC.

.. code-block:: yaml
# Example configuration entry
switch:
- platform: haier
beeper:
name: Haier beeper
health_mode:
name: Haier health mode
display:
name: Haier display
Configuration variables:
------------------------

- **haier_id** (**Required**, :ref:`config-id`): The id of Haier climate component
- **beeper** (*Optional*): (supported only by hOn) A switch that enables or disables Haier climate sound feedback.
All options from :ref:`Switch <config-switch>`.
- **health_mode** (*Optional*): A switch that enables or disables Haier climate health mode (`UV light sterilization <https://www.haierhvac.eu/en/node/1809>`__).
All options from :ref:`Switch <config-switch>`.
- **display** (*Optional*): A switch that enables or disables Haier climate led display.
All options from :ref:`Switch <config-switch>`.

See Also
--------

- :doc:`Haier Climate </components/climate/haier>`
- :ghedit:`Edit`
11 changes: 7 additions & 4 deletions docs/examples/.base.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
substitutions:
file_name: none

esphome:
esphome:
name: esp32-haier-example

esp32:
Expand All @@ -14,3 +11,9 @@ wifi:
ssid: test_ssid
password: test_pass

external_components:
source:
type: local
path: ./components
components: [ haier ]

42 changes: 7 additions & 35 deletions docs/examples/max-hon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,13 @@ text_sensor:
name: Haier hOn Climate protocol version

switch:
- platform: template
id: haier_ac_beeper_switch
entity_category: config
name: Haier hOn Climate beeper
icon: mdi:volume-high
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_beeper_state();
turn_on_action:
climate.haier.beeper_on: haier_ac
turn_off_action:
climate.haier.beeper_off: haier_ac
- platform: template
id: haier_ac_health_mode
name: Haier hOn Climate health mode
icon: mdi:leaf
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
return id(haier_ac).get_health_mode();
turn_on_action:
climate.haier.health_on: haier_ac
turn_off_action:
climate.haier.health_off: haier_ac
- platform: template
id: haier_ac_display_switch
name: Haier hOn Climate display
icon: mdi:led-on
entity_category: config
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_display_state();
turn_on_action:
climate.haier.display_on: haier_ac
turn_off_action:
climate.haier.display_off: haier_ac
- platform: haier
beeper:
name: Haier hOn Climate beeper
health_mode:
name: Haier hOn Climate health mode
display:
name: Haier hOn Climate display

select:
- platform: template
Expand Down
28 changes: 5 additions & 23 deletions docs/examples/max-smartair2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,8 @@ climate:
- AWAY

switch:
- platform: template
id: haier_ac_health_mode
name: Haier SmartAir2 Climate health mode
icon: mdi:leaf
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
return id(haier_ac).get_health_mode();
turn_on_action:
climate.haier.health_on: haier_ac
turn_off_action:
climate.haier.health_off: haier_ac
- platform: template
id: haier_ac_display_switch
name: Haier SmartAir2 Climate display
icon: mdi:led-on
entity_category: config
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_display_state();
turn_on_action:
climate.haier.display_on: haier_ac
turn_off_action:
climate.haier.display_off: haier_ac
- platform: haier
health_mode:
name: Haier SmartAir2 Climate health mode
display:
name: Haier SmartAir2 Climate display
44 changes: 8 additions & 36 deletions docs/hon_example.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. This file is automatically generated by ./docs/script/make_doc.py Python script.
.. This file is automatically generated by ./docs/script/process_examples.py Python script.
Please, don't change. In case you need to make corrections or changes change
source documentation in ./doc folder or script.
Expand Down Expand Up @@ -121,41 +121,13 @@ Maximum configuration witch will use all possible options will look like this:
name: Haier hOn Climate protocol version
switch:
- platform: template
id: haier_ac_beeper_switch
entity_category: config
name: Haier hOn Climate beeper
icon: mdi:volume-high
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_beeper_state();
turn_on_action:
climate.haier.beeper_on: haier_ac
turn_off_action:
climate.haier.beeper_off: haier_ac
- platform: template
id: haier_ac_health_mode
name: Haier hOn Climate health mode
icon: mdi:leaf
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
return id(haier_ac).get_health_mode();
turn_on_action:
climate.haier.health_on: haier_ac
turn_off_action:
climate.haier.health_off: haier_ac
- platform: template
id: haier_ac_display_switch
name: Haier hOn Climate display
icon: mdi:led-on
entity_category: config
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_display_state();
turn_on_action:
climate.haier.display_on: haier_ac
turn_off_action:
climate.haier.display_off: haier_ac
- platform: haier
beeper:
name: Haier hOn Climate beeper
health_mode:
name: Haier hOn Climate health mode
display:
name: Haier hOn Climate display
select:
- platform: template
Expand Down
4 changes: 3 additions & 1 deletion docs/script/make_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"/".join(["esphome-docs", "binary_sensor", "haier.rst"]),
"/".join(["esphome-docs", "text_sensor", "haier.rst"]),
"/".join(["esphome-docs", "button", "haier.rst"]),
"/".join(["esphome-docs", "switch", "haier.rst"]),
"esp32_backup.rst",
"additional_information.rst",
]
Expand All @@ -26,7 +27,8 @@ def process_esphome_refs(line, l_num):
(":ref:`Sensor <config-sensor>`", "`Sensor <https://esphome.io/components/sensor/index.html#config-sensor>`_"),
(":ref:`Binary Sensor <config-binary_sensor>`", "`Binary Sensor <https://esphome.io/components/binary_sensor/index.html#base-binary-sensor-configuration>`_"),
(":ref:`Text Sensor <config-text_sensor>`", "`Text Sensor <https://esphome.io/components/text_sensor/index.html#base-text-sensor-configuration>`_"),
(":ref:`Button <config-button>`", "`Text Sensor <https://esphome.io/components/button/index.html#base-button-configuration>`_"),
(":ref:`Button <config-button>`", "`Button <https://esphome.io/components/button/index.html#base-button-configuration>`_"),
(":ref:`Switch <config-switch>`", "`Switch <https://esphome.io/components/switch/index.html#base-switch-configuration>`_"),

]
res = line
Expand Down
2 changes: 1 addition & 1 deletion docs/script/process_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

document_header = [
".. This file is automatically generated by ./docs/script/make_doc.py Python script.\n",
".. This file is automatically generated by ./docs/script/process_examples.py Python script.\n",
" Please, don't change. In case you need to make corrections or changes change\n",
" source documentation in ./doc folder or script.\n\n"
]
Expand Down
30 changes: 6 additions & 24 deletions docs/smartair2_example.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. This file is automatically generated by ./docs/script/make_doc.py Python script.
.. This file is automatically generated by ./docs/script/process_examples.py Python script.
Please, don't change. In case you need to make corrections or changes change
source documentation in ./doc folder or script.
Expand Down Expand Up @@ -70,27 +70,9 @@ Maximum configuration witch will use all possible options will look like this:
- AWAY
switch:
- platform: template
id: haier_ac_health_mode
name: Haier SmartAir2 Climate health mode
icon: mdi:leaf
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
return id(haier_ac).get_health_mode();
turn_on_action:
climate.haier.health_on: haier_ac
turn_off_action:
climate.haier.health_off: haier_ac
- platform: template
id: haier_ac_display_switch
name: Haier SmartAir2 Climate display
icon: mdi:led-on
entity_category: config
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(haier_ac).get_display_state();
turn_on_action:
climate.haier.display_on: haier_ac
turn_off_action:
climate.haier.display_off: haier_ac
- platform: haier
health_mode:
name: Haier SmartAir2 Climate health mode
display:
name: Haier SmartAir2 Climate display

0 comments on commit ecefe89

Please sign in to comment.