using TAG for ESP_LOG

This commit is contained in:
j0ta29 2023-12-17 21:10:26 +00:00
parent c6caf84377
commit 50821fd22b
4 changed files with 14 additions and 8 deletions

View file

@ -26,7 +26,7 @@ CONFIG_SCHEMA = (
{
cv.GenerateID(): cv.declare_id(OptolinkNumber),
cv.Required(CONF_MAX_VALUE): cv.float_,
cv.Required(CONF_MIN_VALUE): cv.float_range(min=0.0),
cv.Required(CONF_MIN_VALUE): cv.float_range(),
cv.Required(CONF_STEP): cv.float_,
cv.Required(CONF_ADDRESS): cv.hex_uint32_t,
cv.Required(CONF_BYTES): cv.one_of(1, 2, 4, int=True),

View file

@ -7,12 +7,14 @@
namespace esphome {
namespace optolink {
static const char *const TAG = "optolink.number";
void OptolinkNumber::control(float value) {
if (value > traits.get_max_value() || value < traits.get_min_value()) {
set_optolink_state("datapoint value of number %s not in allowed range", get_component_name().c_str());
ESP_LOGE("OptolinkNumber", "datapoint value of number %s not in allowed range", get_component_name().c_str());
ESP_LOGE(TAG, "datapoint value of number %s not in allowed range", get_component_name().c_str());
} else {
ESP_LOGI("OptolinkNumber", "control of number %s to value %f", get_component_name().c_str(), value);
ESP_LOGI(TAG, "control of number %s to value %f", get_component_name().c_str(), value);
write_datapoint_value(value);
publish_state(value);
}

View file

@ -7,17 +7,19 @@
namespace esphome {
namespace optolink {
static const char *const TAG = "optolink.select";
void OptolinkSelect::control(const std::string &value) {
for (auto it = mapping_->begin(); it != mapping_->end(); ++it) {
if (it->second == value) {
ESP_LOGI("OptolinkSelect", "control of select %s to value %s", get_component_name().c_str(), it->first.c_str());
ESP_LOGI(TAG, "control of select %s to value %s", get_component_name().c_str(), it->first.c_str());
write_datapoint_value(std::stof(it->first));
publish_state(it->second);
break;
}
if (it == mapping_->end()) {
set_optolink_state("unknown value %s of select %s", value.c_str(), get_component_name().c_str());
ESP_LOGE("OptolinkSelect", "unknown value %s of select %s", value.c_str(), get_component_name().c_str());
ESP_LOGE(TAG, "unknown value %s of select %s", value.c_str(), get_component_name().c_str());
}
}
};
@ -26,7 +28,7 @@ void OptolinkSelect::datapoint_value_changed(std::string key) {
auto pos = mapping_->find(key);
if (pos == mapping_->end()) {
set_optolink_state("value %s not found in select %s", key.c_str(), get_component_name().c_str());
ESP_LOGE("OptolinkSelect", "value %s not found in select %s", key.c_str(), get_component_name().c_str());
ESP_LOGE(TAG, "value %s not found in select %s", key.c_str(), get_component_name().c_str());
} else {
publish_state(pos->second);
}

View file

@ -7,12 +7,14 @@
namespace esphome {
namespace optolink {
static const char *const TAG = "optolink.switch";
void OptolinkSwitch::write_state(bool value) {
if (value != 0 && value != 1) {
set_optolink_state("datapoint value of switch %s not 0 or 1", get_component_name().c_str());
ESP_LOGE("OptolinkSwitch", "datapoint value of switch %s not 0 or 1", get_component_name().c_str());
ESP_LOGE(TAG, "datapoint value of switch %s not 0 or 1", get_component_name().c_str());
} else {
ESP_LOGI("OptolinkSwitch", "control of switch %s to value %d", get_component_name().c_str(), value);
ESP_LOGI(TAG, "control of switch %s to value %d", get_component_name().c_str(), value);
write_datapoint_value((uint8_t) value);
publish_state(value);
}