#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);
  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);
  }
}

}  // namespace tw7100
}  // namespace esphome