#include "tw7100_switch.h" #include "../tw7100.h" #include "esphome/core/log.h" #include "esphome/core/defines.h" #include "esphome/core/helpers.h" namespace esphome { namespace tw7100 { void tw7100Switch::dump_config() { static const char *const TAG = "dump_config()"; ESP_LOGCONFIG(TAG, "TW7100:"); LOG_SWITCH(TAG, "tw7100Switch", this); publish_state(state); } void tw7100Switch::write_state(bool state) { static const char *const TAG = "write_state()"; ESP_LOGV(TAG, "write switch state for cmd: %s, new state: %i", this->cmd_.c_str(), state); std::string param = ""; char param_char[3]; param_char[0] = 0; if ((cmd_ == "PWR")||(cmd_ == "MUTE")||(cmd_ == "HREVERSE")||(cmd_ == "VREVERSE")) { param = state ? "ON" : "OFF"; // these commands require on/off strings } else if ((cmd_ == "4KENHANCE")||(cmd_ == "BTAUDIO")||(cmd_ == "ILLUM")||(cmd_ == "STANDBYCONF")||(cmd_ == "AUTOHOME")||(cmd_ == "WLPWR")||(cmd_ == "LOGTO")) { sprintf(param_char, "%02d", state); // all these are 00/01 } else if (cmd_ == "IMGPROC") { sprintf(param_char, "%02d", ((uint8_t)state) + 1); // only 01 and 02 are documented, "off" seems to relate to 01. Maybe 00 ("disabled") is undocumented } else if (cmd_ == "AUDIOOUT") { sprintf(param_char, "%02d", 10 + state); // maybe the first "bit" does something else on other models. TW7100 only supports 10/11 per documentation } if(strlen(param_char) > 0) { param = param_char; } if (param.length() > 0) { parent_->push_cmd(cmd_, param); ESP_LOGV("", "CMD: %s, PARAM: %s", cmd_.c_str(), param.c_str()); } } } // namespace tw7100 } // namespace esphome