@@ -90,6 +90,19 @@ class MhiPower : public Sensor {
9090
9191#ifdef USE_SWITCH
9292class MhiActiveMode : public switch_ ::Switch {
93+ public:
94+ void setup () {
95+ ESP_LOGCONFIG (TAG, " Setting up MHI Active Mode Switch '%s'..." , this ->name_ .c_str ());
96+
97+ bool initial_state = this ->get_initial_state_with_restore_mode ().value_or (false );
98+
99+ if (initial_state) {
100+ this ->turn_on ();
101+ } else {
102+ this ->turn_off ();
103+ }
104+ }
105+
93106protected:
94107 virtual void write_state (bool state) {
95108 mhi_ac::active_mode_set (state);
@@ -256,6 +269,11 @@ class MhiAcCtrl : public climate::Climate,
256269 opdatas->energy_used_ .enabled = this ->energy_used_sensor_ ;
257270#ifdef USE_BINARY_SENSOR
258271 opdatas->defrosting_ .enabled = this ->defrosting_binary_sensor_ ;
272+ #endif
273+ #ifdef USE_SWITCH
274+ if (this ->active_mode_switch_ ) {
275+ this ->active_mode_switch_ ->setup ();
276+ }
259277#endif
260278 }
261279
@@ -595,6 +613,9 @@ class MhiAcCtrl : public climate::Climate,
595613 MhiIntegratedTotalEnergy *integrated_total_energy_sensor_ = nullptr ;
596614 MhiPower *power_sensor_ = nullptr ;
597615 mhi_ac::Config ac_config_;
616+ #ifdef USE_SWITCH
617+ MhiActiveMode *active_mode_switch_ = nullptr ;
618+ #endif
598619
599620public:
600621#ifdef USE_SELECT
@@ -618,6 +639,11 @@ class MhiAcCtrl : public climate::Climate,
618639 void set_power_sensor (MhiPower *sensor) {
619640 this ->power_sensor_ = sensor;
620641 }
642+ #ifdef USE_SWITCH
643+ void set_active_mode_switch (MhiActiveMode *swi) {
644+ this ->active_mode_switch_ = swi;
645+ }
646+ #endif
621647
622648
623649};
0 commit comments