Compare commits

..

4 commits

4 changed files with 263 additions and 225 deletions

View file

@ -140,6 +140,24 @@ void tw7100Select::control(const std::string &value) {
for (auto element : luminance) { if (element.second == value) { param = element.first; break; } } for (auto element : luminance) { if (element.second == value) { param = element.first; break; } }
} else if (cmd_ == "ASPECT") { } else if (cmd_ == "ASPECT") {
for (auto element : aspect) { if (element.second == value) { param = element.first; break; } } for (auto element : aspect) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "OVSCAN") {
for (auto element : aspect) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "CMODE") {
for (auto element : cmode) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "GAMMA") {
for (auto element : gamma) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "IMGPRESET") {
for (auto element : imgpreset) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "MCFI") {
for (auto element : mcfi) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "CLRSPACE") {
for (auto element : clrspace) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "DYNRANGE") {
for (auto element : dynrange) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "MSEL") {
for (auto element : msel) { if (element.second == value) { param = element.first; break; } }
} else if ( cmd_ == "SPEED") {
//for (auto element : speed) { if (element.second == value) { param = element.first; break; } }
} }
if (param.length() > 0) { if (param.length() > 0) {
@ -153,5 +171,102 @@ void tw7100Select::control(const std::string &value) {
ESP_LOGV(TAG, "control done"); ESP_LOGV(TAG, "control done");
}; };
void tw7100Select::set_option_by_key(std::string key) {
static const char *const TAG = "tw7100Select::set_option_by_key()";
std::string value_found = "";
if ( cmd_ == "LUMINANCE") {
ESP_LOGV(TAG, "updating luminance select");
if(tw7100Select::luminance.find(key) != tw7100Select::luminance.end()) {
value_found = tw7100Select::luminance[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "SOURCE") {
ESP_LOGV(TAG, "updating source select");
if(tw7100Select::sources.find(key) != tw7100Select::sources.end()) {
value_found = tw7100Select::sources[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "ASPECT") {
ESP_LOGV(TAG, "updating aspect select");
if(tw7100Select::aspect.find(key) != tw7100Select::aspect.end()) {
value_found = tw7100Select::aspect[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "OVSCAN") {
ESP_LOGV(TAG, "updating ovscan select");
if(tw7100Select::ovscan.find(key) != tw7100Select::ovscan.end()) {
value_found = tw7100Select::ovscan[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "CMODE") {
ESP_LOGV(TAG, "updating cmode select");
if(tw7100Select::cmode.find(key) != tw7100Select::cmode.end()) {
value_found = tw7100Select::cmode[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "GAMMA") {
ESP_LOGV(TAG, "updating gamma select");
if(tw7100Select::gamma.find(key) != tw7100Select::gamma.end()) {
value_found = tw7100Select::gamma[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "IMGPRESET") {
ESP_LOGV(TAG, "updating imgpreset select");
if(tw7100Select::imgpreset.find(key) != tw7100Select::imgpreset.end()) {
value_found = tw7100Select::imgpreset[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "MCFI") {
ESP_LOGV(TAG, "updating mcfi select");
if(tw7100Select::mcfi.find(key) != tw7100Select::mcfi.end()) {
value_found = tw7100Select::mcfi[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "CLRSPACE") {
ESP_LOGV(TAG, "updating clrspace select");
if(tw7100Select::clrspace.find(key) != tw7100Select::clrspace.end()) {
value_found = tw7100Select::clrspace[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "DYNRANGE") {
ESP_LOGV(TAG, "updating dynrange select");
if(tw7100Select::dynrange.find(key) != tw7100Select::dynrange.end()) {
value_found = tw7100Select::dynrange[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "MSEL") {
ESP_LOGV(TAG, "updating msel select");
if(tw7100Select::msel.find(key) != tw7100Select::msel.end()) {
value_found = tw7100Select::msel[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
} else if ( cmd_ == "SPEED") {
ESP_LOGV(TAG, "updating speed select");
if(tw7100Select::speed.find(key) != tw7100Select::speed.end()) {
value_found = tw7100Select::speed[key];
} else {
ESP_LOGE(TAG, "Result %s not present in options", key);
}
}
if (value_found.length() > 0) {
auto call = make_call();
call.set_option(value_found);
call.perform();
}
};
} // namespace tw7100 } // namespace tw7100
} // namespace esphome } // namespace esphome

View file

@ -15,6 +15,7 @@ class tw7100Select : public select::Select, public Component {
void dump_config() override; void dump_config() override;
void set_tw7100_parent(tw7100Component *parent) { this->parent_ = parent; } void set_tw7100_parent(tw7100Component *parent) { this->parent_ = parent; }
void set_cmd(std::string cmd) { this->cmd_ = cmd; } void set_cmd(std::string cmd) { this->cmd_ = cmd; }
void set_option_by_key(std::string key);
static std::map<std::string, std::string> sources; static std::map<std::string, std::string> sources;
static std::map<std::string, std::string> luminance; static std::map<std::string, std::string> luminance;
static std::map<std::string, std::string> aspect; static std::map<std::string, std::string> aspect;

View file

@ -1,4 +1,5 @@
#include "tw7100.h" #include "tw7100.h"
#include <deque>
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
@ -220,284 +221,203 @@ void tw7100Component::update_sensor(std::pair<std::string, std::string> data) {
int value = std::stoi(value_string); int value = std::stoi(value_string);
powered = (value > 0); powered = (value > 0);
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
//if (powered_) powered_->publish_state(value > 0); powered_->publish_state(value > 0);
#endif #endif
#ifdef USE_SWITCH #ifdef USE_SWITCH
if (power_switch_) power_switch_->publish_state(value > 0); // ack previous cmd or update switch power_switch_->publish_state(value > 0); // ack previous cmd or update switch
#endif #endif
#ifdef USE_SENSOR #ifdef USE_SENSOR
if (power_status_) power_status_->publish_state(value); power_status_->publish_state(value);
#endif
} else if (cmd == "LAMP") { } else if (cmd == "LAMP") {
ESP_LOGV(TAG, "updating lamp sensors"); ESP_LOGV(TAG, "updating lamp sensors");
#ifdef USE_SENSOR
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (lamp_hours_) lamp_hours_->publish_state(value); lamp_hours_->publish_state(value);
#endif
} else if (cmd == "SIGNAL") { } else if (cmd == "SIGNAL") {
ESP_LOGV(TAG, "updating signal sensors"); ESP_LOGV(TAG, "updating signal sensors");
int value = std::stoi(value_string); int value = std::stoi(value_string);
#endif
#ifdef USE_BINARY_SENSOR
has_signal_->publish_state(value > 0); has_signal_->publish_state(value > 0);
if (signal_status_) signal_status_->publish_state(value); #endif
#ifdef USE_SENSOR
signal_status_->publish_state(value);
#endif
#ifdef USE_SELECT
} else if (cmd == "LUMINANCE") { } else if (cmd == "LUMINANCE") {
ESP_LOGV(TAG, "updating luminance sensors"); ESP_LOGV(TAG, "updating luminance sensors");
#ifdef USE_SENSOR
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (luminance_level_) luminance_level_->publish_state(value); luminance_level_->publish_state(value);
#endif luminance_select_->set_option_by_key(value_string);
#ifdef USE_SELECT
if (luminance_select_) {
if(tw7100Select::luminance.find(value_string) != tw7100Select::luminance.end()) {
auto call = luminance_select_->make_call();
call.set_option(tw7100Select::luminance[value_string]);
call.perform();
} else {
ESP_LOGE(TAG, "Result %s not present in options", value_string);
}
}
#endif
} else if (cmd == "SOURCE") { } else if (cmd == "SOURCE") {
ESP_LOGV(TAG, "updating source select"); ESP_LOGV(TAG, "updating source select");
#ifdef USE_SELECT source_select_->set_option_by_key(value_string);
if (source_select_) {
if(tw7100Select::sources.find(value_string) != tw7100Select::sources.end()) {
auto call = source_select_->make_call();
call.set_option(tw7100Select::sources[value_string]);
call.perform();
} else {
ESP_LOGE(TAG, "Result %s not present in options", value_string);
}
}
#endif
} else if (cmd == "ASPECT") { } else if (cmd == "ASPECT") {
ESP_LOGV(TAG, "updating aspect select"); ESP_LOGV(TAG, "updating aspect select");
#ifdef USE_SELECT aspect_select_->set_option_by_key(value_string);
if (aspect_select_) {
if(tw7100Select::aspect.find(value_string) != tw7100Select::aspect.end()) {
auto call = aspect_select_->make_call();
call.set_option(tw7100Select::aspect[value_string]);
call.perform();
} else {
ESP_LOGE(TAG, "Result %s not present in options", value_string);
}
}
#endif
} else if (cmd == "OVSCAN") { } else if (cmd == "OVSCAN") {
ESP_LOGV(TAG, "updating ovscan select"); ESP_LOGV(TAG, "updating ovscan select");
ovscan_select_->set_option_by_key(value_string);
} else if (cmd == "CMODE") { } else if (cmd == "CMODE") {
ESP_LOGV(TAG, "updating cmode select"); ESP_LOGV(TAG, "updating cmode select");
cmode_select_->set_option_by_key(value_string);
} else if (cmd == "GAMMA") { } else if (cmd == "GAMMA") {
ESP_LOGV(TAG, "updating gamma select"); ESP_LOGV(TAG, "updating gamma select");
gamma_select_->set_option_by_key(value_string);
} else if (cmd == "IMGPRESET") { } else if (cmd == "IMGPRESET") {
ESP_LOGV(TAG, "updating imgpreset select"); ESP_LOGV(TAG, "updating imgpreset select");
imgpreset_select_->set_option_by_key(value_string);
} else if (cmd == "MCFI") { } else if (cmd == "MCFI") {
ESP_LOGV(TAG, "updating mcfi select"); ESP_LOGV(TAG, "updating mcfi select");
mcfi_select_->set_option_by_key(value_string);
} else if (cmd == "CLRSPACE") { } else if (cmd == "CLRSPACE") {
ESP_LOGV(TAG, "updating clrspace select"); ESP_LOGV(TAG, "updating clrspace select");
clrspace_select_->set_option_by_key(value_string);
} else if (cmd == "DYNRANGE") { } else if (cmd == "DYNRANGE") {
ESP_LOGV(TAG, "updating dynrange select"); ESP_LOGV(TAG, "updating dynrange select");
dynrange_select_->set_option_by_key(value_string);
} else if (cmd == "MSEL") { } else if (cmd == "MSEL") {
ESP_LOGV(TAG, "updating msel select"); ESP_LOGV(TAG, "updating msel select");
msel_select_->set_option_by_key(value_string);
} else if (cmd == "SPEED") { } else if (cmd == "SPEED") {
ESP_LOGV(TAG, "updating speed select"); ESP_LOGV(TAG, "updating speed select");
speed_select_->set_option_by_key(value_string);
#endif
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR
} else if (cmd == "SNO") { } else if (cmd == "SNO") {
if (serial_ != nullptr) serial_->publish_state(value_string); serial_->publish_state(value_string);
#endif #endif
#ifdef USE_SWITCH
} else if (cmd == "BTAUDIO") { } else if (cmd == "BTAUDIO") {
ESP_LOGV(TAG, "updating btaudio switch"); ESP_LOGV(TAG, "updating btaudio switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (btaudio_switch_) btaudio_switch_->publish_state(value > 0); btaudio_switch_->publish_state(value > 0);
#endif
} else if (cmd == "4KENHANCE") { } else if (cmd == "4KENHANCE") {
ESP_LOGV(TAG, "updating 4kenhance switch"); ESP_LOGV(TAG, "updating 4kenhance switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (_4kenhance_switch_) _4kenhance_switch_->publish_state(value > 0); _4kenhance_switch_->publish_state(value > 0);
#endif
} else if (cmd == "IMGPROC") { } else if (cmd == "IMGPROC") {
ESP_LOGV(TAG, "updating imgproc switch"); ESP_LOGV(TAG, "updating imgproc switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (img_processing_switch_) img_processing_switch_->publish_state(value > 1); img_processing_switch_->publish_state(value > 1);
#endif
} else if (cmd == "AUDIOOUT") { } else if (cmd == "AUDIOOUT") {
ESP_LOGV(TAG, "updating audioout switch"); ESP_LOGV(TAG, "updating audioout switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (audioout_switch_) audioout_switch_->publish_state(value == 11); audioout_switch_->publish_state(value == 11);
#endif
} else if (cmd == "HREVERSE") { } else if (cmd == "HREVERSE") {
ESP_LOGV(TAG, "updating hflip switch"); ESP_LOGV(TAG, "updating hflip switch");
#ifdef USE_SWITCH hflip_switch_->publish_state(value_string == "ON");
if (hflip_switch_) hflip_switch_->publish_state(value_string == "ON");
#endif
} else if (cmd == "VREVERSE") { } else if (cmd == "VREVERSE") {
ESP_LOGV(TAG, "updating vflip switch"); ESP_LOGV(TAG, "updating vflip switch");
#ifdef USE_SWITCH vflip_switch_->publish_state(value_string == "ON");
if (vflip_switch_) vflip_switch_->publish_state(value_string == "ON");
#endif
} else if (cmd == "ILLUM") { } else if (cmd == "ILLUM") {
ESP_LOGV(TAG, "updating illumination switch"); ESP_LOGV(TAG, "updating illumination switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (illumination_switch_) illumination_switch_->publish_state(value == 1); illumination_switch_->publish_state(value == 1);
#endif
} else if (cmd == "STANDBYCONF") { } else if (cmd == "STANDBYCONF") {
ESP_LOGV(TAG, "updating standbyconf switch"); ESP_LOGV(TAG, "updating standbyconf switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (standbyconf_switch_) standbyconf_switch_->publish_state(value == 1); standbyconf_switch_->publish_state(value == 1);
#endif
} else if (cmd == "AUTOHOME") { } else if (cmd == "AUTOHOME") {
ESP_LOGV(TAG, "updating autohome switch"); ESP_LOGV(TAG, "updating autohome switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (autohome_switch_) autohome_switch_->publish_state(value == 1); autohome_switch_->publish_state(value == 1);
#endif
} else if (cmd == "WLPWR") { } else if (cmd == "WLPWR") {
ESP_LOGV(TAG, "updating wlan power switch"); ESP_LOGV(TAG, "updating wlan power switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (wlan_power_switch_) wlan_power_switch_->publish_state(value == 1); wlan_power_switch_->publish_state(value == 1);
#endif
} else if (cmd == "LOGTO") { } else if (cmd == "LOGTO") {
ESP_LOGV(TAG, "updating logto switch"); ESP_LOGV(TAG, "updating logto switch");
#ifdef USE_SWITCH
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (logto_switch_) logto_switch_->publish_state(value == 1); logto_switch_->publish_state(value == 1);
#endif
} else if (cmd == "MUTE") { } else if (cmd == "MUTE") {
ESP_LOGV(TAG, "updating mute switch with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating mute switch with value %s", value_string.c_str());
#ifdef USE_SWITCH mute_switch_->publish_state(value_string == "ON");
if (mute_switch_) mute_switch_->publish_state(value_string == "ON");
#endif #endif
#ifdef USE_NUMBER
} else if (cmd == "VOL") { } else if (cmd == "VOL") {
ESP_LOGV(TAG, "updating volume number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating volume number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (volume_number_) volume_number_->publish_state(value); volume_number_->publish_state(value);
#endif
} else if (cmd == "VKEYSTONE") { } else if (cmd == "VKEYSTONE") {
ESP_LOGV(TAG, "updating vkeystone number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating vkeystone number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (vkeystone_number_) vkeystone_number_->publish_state(value); vkeystone_number_->publish_state(value);
#endif
} else if (cmd == "HKEYSTONE") { } else if (cmd == "HKEYSTONE") {
ESP_LOGV(TAG, "updating hkeystone number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating hkeystone number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (hkeystone_number_) hkeystone_number_->publish_state(value); hkeystone_number_->publish_state(value);
#endif
} else if (cmd == "BRIGHT") { } else if (cmd == "BRIGHT") {
ESP_LOGV(TAG, "updating brightness number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating brightness number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (brightness_number_) brightness_number_->publish_state(value); brightness_number_->publish_state(value);
#endif
} else if (cmd == "CONTRAST") { } else if (cmd == "CONTRAST") {
ESP_LOGV(TAG, "updating contrast number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating contrast number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (contrast_number_) contrast_number_->publish_state(value); contrast_number_->publish_state(value);
#endif
} else if (cmd == "DENSITY") { } else if (cmd == "DENSITY") {
ESP_LOGV(TAG, "updating density number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating density number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (density_number_) density_number_->publish_state(value); density_number_->publish_state(value);
#endif
} else if (cmd == "TINT") { } else if (cmd == "TINT") {
ESP_LOGV(TAG, "updating tint number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating tint number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (tint_number_) tint_number_->publish_state(value); tint_number_->publish_state(value);
#endif
} else if (cmd == "CTEMP") { } else if (cmd == "CTEMP") {
ESP_LOGV(TAG, "updating ctemp number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating ctemp number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (ctemp_number_) ctemp_number_->publish_state(value); ctemp_number_->publish_state(value);
#endif
} else if (cmd == "FCOLOR") { } else if (cmd == "FCOLOR") {
ESP_LOGV(TAG, "updating fcolor number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating fcolor number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (fcolor_number_) fcolor_number_->publish_state(value); fcolor_number_->publish_state(value);
#endif
} else if (cmd == "NRS") { } else if (cmd == "NRS") {
ESP_LOGV(TAG, "updating nrs number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating nrs number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (nrs_number_) nrs_number_->publish_state(value); nrs_number_->publish_state(value);
#endif
} else if (cmd == "MPEGNRS") { } else if (cmd == "MPEGNRS") {
ESP_LOGV(TAG, "updating mpegngs number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating mpegngs number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (mpegnrs_number_) mpegnrs_number_->publish_state(value); mpegnrs_number_->publish_state(value);
#endif
} else if (cmd == "OFFSETR") { } else if (cmd == "OFFSETR") {
ESP_LOGV(TAG, "updating offsetr number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating offsetr number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (offsetr_number_) offsetr_number_->publish_state(value); offsetr_number_->publish_state(value);
#endif
} else if (cmd == "OFFSETG") { } else if (cmd == "OFFSETG") {
ESP_LOGV(TAG, "updating offsetg number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating offsetg number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (offsetg_number_) offsetg_number_->publish_state(value); offsetg_number_->publish_state(value);
#endif
} else if (cmd == "OFFSETB") { } else if (cmd == "OFFSETB") {
ESP_LOGV(TAG, "updating offsetb number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating offsetb number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (offsetb_number_) offsetb_number_->publish_state(value); offsetb_number_->publish_state(value);
#endif
} else if (cmd == "GAINR") { } else if (cmd == "GAINR") {
ESP_LOGV(TAG, "updating gainr number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating gainr number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (gainr_number_) gainr_number_->publish_state(value); gainr_number_->publish_state(value);
#endif
} else if (cmd == "GAING") { } else if (cmd == "GAING") {
ESP_LOGV(TAG, "updating gaing number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating gaing number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (gaing_number_) gaing_number_->publish_state(value); gaing_number_->publish_state(value);
#endif
} else if (cmd == "GAINB") { } else if (cmd == "GAINB") {
ESP_LOGV(TAG, "updating gainb number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating gainb number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (gainb_number_) gainb_number_->publish_state(value); gainb_number_->publish_state(value);
#endif
} else if (cmd == "SHRF") { } else if (cmd == "SHRF") {
ESP_LOGV(TAG, "updating shrf number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating shrf number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (shrf_number_) shrf_number_->publish_state(value); shrf_number_->publish_state(value);
#endif
} else if (cmd == "SHRS") { } else if (cmd == "SHRS") {
ESP_LOGV(TAG, "updating shrs number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating shrs number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (shrs_number_) shrs_number_->publish_state(value); shrs_number_->publish_state(value);
#endif
} else if (cmd == "DERANGE") { } else if (cmd == "DERANGE") {
ESP_LOGV(TAG, "updating derange number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating derange number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (derange_number_) derange_number_->publish_state(value); derange_number_->publish_state(value);
#endif
} else if (cmd == "DESTRENGTH") { } else if (cmd == "DESTRENGTH") {
ESP_LOGV(TAG, "updating destrength number with value %s", value_string.c_str()); ESP_LOGV(TAG, "updating destrength number with value %s", value_string.c_str());
#ifdef USE_NUMBER
int value = std::stoi(value_string); int value = std::stoi(value_string);
if (destrength_number_) destrength_number_->publish_state(value); destrength_number_->publish_state(value);
#endif #endif
} else { } else {
ESP_LOGW(TAG, "Command %s unknown, skipping updating sensor with value", cmd.c_str()); ESP_LOGW(TAG, "Command %s unknown, skipping updating sensor with value", cmd.c_str());

168
tw7100.h
View file

@ -1,8 +1,10 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/core/entity_base.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/components/uart/uart.h" #include "esphome/components/uart/uart.h"
#include <map>
#ifdef USE_SENSOR #ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
@ -18,6 +20,7 @@
#ifdef USE_SWITCH #ifdef USE_SWITCH
#include "esphome/components/switch/switch.h" #include "esphome/components/switch/switch.h"
#include "switch/tw7100_switch.h"
#endif #endif
#ifdef USE_SELECT #ifdef USE_SELECT
@ -30,27 +33,6 @@
#include "number/tw7100_number.h" #include "number/tw7100_number.h"
#endif #endif
namespace esphome {
#ifndef USE_SENSOR
namespace sensor {
class Sensor : public Component {
public:
void publish_state(float state) { ESP_LOGW("dummy_sensor", "skipping updating value for this unconfigured sensor"); };
};
}
#endif
#ifndef USE_BINARY_SENSOR
namespace binary_sensor {
class BinarySensor : public Component {
public:
void publish_state(bool state) { ESP_LOGW("dummy_binary_sensor", "skipping updating value for this unconfigured sensor"); };
};
}
#endif
}
namespace esphome { namespace esphome {
namespace tw7100 { namespace tw7100 {
@ -87,20 +69,20 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
void set_serial(text_sensor::TextSensor *serial) { this->serial_ = serial; } void set_serial(text_sensor::TextSensor *serial) { this->serial_ = serial; }
#endif #endif
#ifdef USE_SWITCH #ifdef USE_SWITCH
void set_set_pwr(switch_::Switch *switch_) { this->power_switch_ = switch_; } void set_set_pwr(tw7100::tw7100Switch *switch_) { this->power_switch_ = switch_; }
void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; } void set_set_btaudio(tw7100::tw7100Switch *switch_) { this->btaudio_switch_ = switch_; }
void set_set_mute(switch_::Switch *switch_) { this->mute_switch_ = switch_; } void set_set_mute(tw7100::tw7100Switch *switch_) { this->mute_switch_ = switch_; }
void set_set_wlpwr(switch_::Switch *switch_) { this->wlan_power_switch_ = switch_; } void set_set_wlpwr(tw7100::tw7100Switch *switch_) { this->wlan_power_switch_ = switch_; }
void set_set_autohome(switch_::Switch *switch_) { this->autohome_switch_ = switch_; } void set_set_autohome(tw7100::tw7100Switch *switch_) { this->autohome_switch_ = switch_; }
void set_set_product(switch_::Switch *switch_) { this->product_switch_ = switch_; } void set_set_product(tw7100::tw7100Switch *switch_) { this->product_switch_ = switch_; }
void set_set_standbyconf(switch_::Switch *switch_) { this->standbyconf_switch_ = switch_; } void set_set_standbyconf(tw7100::tw7100Switch *switch_) { this->standbyconf_switch_ = switch_; }
void set_set_illum(switch_::Switch *switch_) { this->illumination_switch_ = switch_; } void set_set_illum(tw7100::tw7100Switch *switch_) { this->illumination_switch_ = switch_; }
void set_set_vreverse(switch_::Switch *switch_) { this->vflip_switch_ = switch_; } void set_set_vreverse(tw7100::tw7100Switch *switch_) { this->vflip_switch_ = switch_; }
void set_set_hreverse(switch_::Switch *switch_) { this->hflip_switch_ = switch_; } void set_set_hreverse(tw7100::tw7100Switch *switch_) { this->hflip_switch_ = switch_; }
void set_set_audioout(switch_::Switch *switch_) { this->audioout_switch_ = switch_; } void set_set_audioout(tw7100::tw7100Switch *switch_) { this->audioout_switch_ = switch_; }
void set_set_imgproc(switch_::Switch *switch_) { this->img_processing_switch_ = switch_; } void set_set_imgproc(tw7100::tw7100Switch *switch_) { this->img_processing_switch_ = switch_; }
void set_set_4kenhance(switch_::Switch *switch_) { this->_4kenhance_switch_ = switch_; } void set_set_4kenhance(tw7100::tw7100Switch *switch_) { this->_4kenhance_switch_ = switch_; }
void set_set_logto(switch_::Switch *switch_) { this->logto_switch_ = switch_; } void set_set_logto(tw7100::tw7100Switch *switch_) { this->logto_switch_ = switch_; }
#endif #endif
#ifdef USE_SELECT #ifdef USE_SELECT
void set_set_source(tw7100::tw7100Select *select_) { this->source_select_ = select_; } void set_set_source(tw7100::tw7100Select *select_) { this->source_select_ = select_; }
@ -141,71 +123,91 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
#endif #endif
private: private:
#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *dummy_binary_sensor = new binary_sensor::BinarySensor(); binary_sensor::BinarySensor *dummy_binary_sensor = new binary_sensor::BinarySensor();
#endif
#ifdef USE_SENSOR
sensor::Sensor *dummy_sensor = new sensor::Sensor(); sensor::Sensor *dummy_sensor = new sensor::Sensor();
#endif
#ifdef USE_TEXT_SENSOR
text_sensor::TextSensor *dummy_text_sensor = new text_sensor::TextSensor();
#endif
#ifdef USE_SWITCH
tw7100::tw7100Switch *dummy_switch = new tw7100::tw7100Switch();
#endif
#ifdef USE_SELECT
tw7100::tw7100Select *dummy_select = new tw7100::tw7100Select();
#endif
#ifdef USE_NUMBER
tw7100::tw7100Number *dummy_number = new tw7100::tw7100Number();
#endif
protected: protected:
#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *powered_ = dummy_binary_sensor; binary_sensor::BinarySensor *powered_ = dummy_binary_sensor;
binary_sensor::BinarySensor *has_signal_ = dummy_binary_sensor; binary_sensor::BinarySensor *has_signal_ = dummy_binary_sensor;
#endif
#ifdef USE_SENSOR
sensor::Sensor *lamp_hours_ = dummy_sensor; sensor::Sensor *lamp_hours_ = dummy_sensor;
sensor::Sensor *power_status_ = dummy_sensor; sensor::Sensor *power_status_ = dummy_sensor;
sensor::Sensor *signal_status_ = dummy_sensor; sensor::Sensor *signal_status_ = dummy_sensor;
sensor::Sensor *luminance_level_ = dummy_sensor; sensor::Sensor *luminance_level_ = dummy_sensor;
#endif
#ifdef USE_TEXT_SENSOR #ifdef USE_TEXT_SENSOR
text_sensor::TextSensor *serial_{nullptr}; text_sensor::TextSensor *serial_ = dummy_text_sensor;
#endif #endif
#ifdef USE_SWITCH #ifdef USE_SWITCH
switch_::Switch *power_switch_{nullptr}; tw7100::tw7100Switch *power_switch_ = dummy_switch;
switch_::Switch *btaudio_switch_{nullptr}; tw7100::tw7100Switch *btaudio_switch_ = dummy_switch;
switch_::Switch *mute_switch_{nullptr}; tw7100::tw7100Switch *mute_switch_ = dummy_switch;
switch_::Switch *wlan_power_switch_{nullptr}; tw7100::tw7100Switch *wlan_power_switch_ = dummy_switch;
switch_::Switch *autohome_switch_{nullptr}; tw7100::tw7100Switch *autohome_switch_ = dummy_switch;
switch_::Switch *product_switch_{nullptr}; tw7100::tw7100Switch *product_switch_ = dummy_switch;
switch_::Switch *standbyconf_switch_{nullptr}; tw7100::tw7100Switch *standbyconf_switch_ = dummy_switch;
switch_::Switch *illumination_switch_{nullptr}; tw7100::tw7100Switch *illumination_switch_ = dummy_switch;
switch_::Switch *vflip_switch_{nullptr}; tw7100::tw7100Switch *vflip_switch_ = dummy_switch;
switch_::Switch *hflip_switch_{nullptr}; tw7100::tw7100Switch *hflip_switch_ = dummy_switch;
switch_::Switch *audioout_switch_{nullptr}; tw7100::tw7100Switch *audioout_switch_ = dummy_switch;
switch_::Switch *img_processing_switch_{nullptr}; tw7100::tw7100Switch *img_processing_switch_ = dummy_switch;
switch_::Switch *_4kenhance_switch_{nullptr}; tw7100::tw7100Switch *_4kenhance_switch_ = dummy_switch;
switch_::Switch *logto_switch_{nullptr}; tw7100::tw7100Switch *logto_switch_ = dummy_switch;
#endif #endif
#ifdef USE_SELECT #ifdef USE_SELECT
tw7100::tw7100Select *source_select_{nullptr}; tw7100::tw7100Select *source_select_ = dummy_select;;
tw7100::tw7100Select *luminance_select_{nullptr}; tw7100::tw7100Select *luminance_select_ = dummy_select;
tw7100::tw7100Select *aspect_select_{nullptr}; tw7100::tw7100Select *aspect_select_ = dummy_select;
tw7100::tw7100Select *ovscan_select_{nullptr}; tw7100::tw7100Select *ovscan_select_ = dummy_select;
tw7100::tw7100Select *cmode_select_{nullptr}; tw7100::tw7100Select *cmode_select_ = dummy_select;
tw7100::tw7100Select *gamma_select_{nullptr}; tw7100::tw7100Select *gamma_select_ = dummy_select;
tw7100::tw7100Select *imgpreset_select_{nullptr}; tw7100::tw7100Select *imgpreset_select_ = dummy_select;
tw7100::tw7100Select *mcfi_select_{nullptr}; tw7100::tw7100Select *mcfi_select_ = dummy_select;
tw7100::tw7100Select *clrspace_select_{nullptr}; tw7100::tw7100Select *clrspace_select_ = dummy_select;
tw7100::tw7100Select *dynrange_select_{nullptr}; tw7100::tw7100Select *dynrange_select_ = dummy_select;
tw7100::tw7100Select *msel_select_{nullptr}; tw7100::tw7100Select *msel_select_ = dummy_select;
tw7100::tw7100Select *speed_select_{nullptr}; tw7100::tw7100Select *speed_select_ = dummy_select;
#endif #endif
#ifdef USE_NUMBER #ifdef USE_NUMBER
tw7100::tw7100Number *volume_number_{nullptr}; tw7100::tw7100Number *volume_number_ = dummy_number;
tw7100::tw7100Number *vkeystone_number_{nullptr}; tw7100::tw7100Number *vkeystone_number_ = dummy_number;
tw7100::tw7100Number *hkeystone_number_{nullptr}; tw7100::tw7100Number *hkeystone_number_ = dummy_number;
tw7100::tw7100Number *brightness_number_{nullptr}; tw7100::tw7100Number *brightness_number_ = dummy_number;
tw7100::tw7100Number *contrast_number_{nullptr}; tw7100::tw7100Number *contrast_number_ = dummy_number;
tw7100::tw7100Number *density_number_{nullptr}; tw7100::tw7100Number *density_number_ = dummy_number;
tw7100::tw7100Number *tint_number_{nullptr}; tw7100::tw7100Number *tint_number_ = dummy_number;
tw7100::tw7100Number *ctemp_number_{nullptr}; tw7100::tw7100Number *ctemp_number_ = dummy_number;
tw7100::tw7100Number *fcolor_number_{nullptr}; tw7100::tw7100Number *fcolor_number_ = dummy_number;
tw7100::tw7100Number *nrs_number_{nullptr}; tw7100::tw7100Number *nrs_number_ = dummy_number;
tw7100::tw7100Number *mpegnrs_number_{nullptr}; tw7100::tw7100Number *mpegnrs_number_ = dummy_number;
tw7100::tw7100Number *offsetr_number_{nullptr}; tw7100::tw7100Number *offsetr_number_ = dummy_number;
tw7100::tw7100Number *offsetg_number_{nullptr}; tw7100::tw7100Number *offsetg_number_ = dummy_number;
tw7100::tw7100Number *offsetb_number_{nullptr}; tw7100::tw7100Number *offsetb_number_ = dummy_number;
tw7100::tw7100Number *gainr_number_{nullptr}; tw7100::tw7100Number *gainr_number_ = dummy_number;
tw7100::tw7100Number *gaing_number_{nullptr}; tw7100::tw7100Number *gaing_number_ = dummy_number;
tw7100::tw7100Number *gainb_number_{nullptr}; tw7100::tw7100Number *gainb_number_ = dummy_number;
tw7100::tw7100Number *shrf_number_{nullptr}; tw7100::tw7100Number *shrf_number_ = dummy_number;
tw7100::tw7100Number *shrs_number_{nullptr}; tw7100::tw7100Number *shrs_number_ = dummy_number;
tw7100::tw7100Number *derange_number_{nullptr}; tw7100::tw7100Number *derange_number_ = dummy_number;
tw7100::tw7100Number *destrength_number_{nullptr}; tw7100::tw7100Number *destrength_number_ = dummy_number;
#endif #endif
}; };