esphome-tw7100/switch/tw7100_switch.cpp

46 lines
1.6 KiB
C++
Raw Permalink Normal View History

2024-09-16 21:45:39 +02:00
#include "../tw7100.h"
2024-09-20 00:29:52 +02:00
#include "tw7100_switch.h"
2024-09-15 18:44:45 +02:00
#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);
2024-09-18 23:14:13 +02:00
std::string param = "";
char param_char[3];
param_char[0] = 0;
if ((cmd_ == "PWR")||(cmd_ == "MUTE")||(cmd_ == "HREVERSE")||(cmd_ == "VREVERSE")) {
2024-09-18 23:33:04 +02:00
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
2024-09-18 23:14:13 +02:00
} else if (cmd_ == "IMGPROC") {
2024-09-18 23:33:04 +02:00
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
2024-09-18 23:14:13 +02:00
} else if (cmd_ == "AUDIOOUT") {
2024-09-18 23:33:04 +02:00
sprintf(param_char, "%02d", 10 + state); // maybe the first "bit" does something else on other models. TW7100 only supports 10/11 per documentation
2024-09-18 23:14:13 +02:00
}
if(strlen(param_char) > 0) {
param = param_char;
}
if (param.length() > 0) {
2024-09-17 02:14:41 +02:00
parent_->push_cmd(cmd_, param);
2024-09-18 23:14:13 +02:00
ESP_LOGV("", "CMD: %s, PARAM: %s", cmd_.c_str(), param.c_str());
}
2024-09-15 18:44:45 +02:00
}
} // namespace tw7100
} // namespace esphome