esphome-tw7100/number/tw7100_number.cpp

44 lines
1 KiB
C++
Raw Normal View History

2024-09-17 23:06:18 +02:00
#include "../tw7100.h"
#include "tw7100_number.h"
#include "esphome/core/log.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace tw7100 {
void tw7100Number::setup() {
static const char *const TAG = "tw7100Number::setup()";
if (cmd_ == "VOL") {
ESP_LOGV(TAG, "setup VOL");
}
ESP_LOGV(TAG, "setup done");
}
void tw7100Number::dump_config() {
static const char *const TAG = "dump_config()";
ESP_LOGCONFIG(TAG, "TW7100:");
LOG_NUMBER(TAG, "tw7100Number", this);
}
void tw7100Number::control(float value) {
static const char *const TAG = "tw7100Number::control()";
std::string param;
if (cmd_ == "VOL") {
2024-09-17 23:30:02 +02:00
param = std::to_string((int)value);
ESP_LOGV(TAG, "VOL: %s (from %i)", param, (int)value);
2024-09-17 23:06:18 +02:00
}
if (param.length() > 0 && state != value) {
parent_->push_cmd(cmd_, param);
ESP_LOGV("", "CMD: %s, PARAM: %s", cmd_.c_str(), param.c_str());
}
publish_state(value);
ESP_LOGV(TAG, "control done");
};
} // namespace tw7100
} // namespace esphome