2024-09-15 18:44:45 +02:00
|
|
|
#include "tw7100_switch.h"
|
2024-09-16 21:45:39 +02:00
|
|
|
#include "../tw7100.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()";
|
2024-09-16 02:25:05 +02:00
|
|
|
ESP_LOGV(TAG, "write switch state for cmd: %s, new state: %i", this->cmd_.c_str(), state);
|
|
|
|
if (cmd_ == "PWR") {
|
|
|
|
std::string param = state ? "ON" : "OFF";
|
|
|
|
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param.c_str());
|
|
|
|
parent_->push_cmd(cmd_, param);
|
|
|
|
} else if (cmd_ == "BTAUDIO") {
|
|
|
|
char param [3];
|
|
|
|
sprintf(param, "%02d", state);
|
|
|
|
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param);
|
|
|
|
parent_->push_cmd(cmd_, param);
|
|
|
|
}
|
2024-09-15 18:44:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace tw7100
|
|
|
|
} // namespace esphome
|