Remove SOURCELIST parser

This commit is contained in:
sqozz 2024-09-19 00:47:37 +02:00
parent b36e0aa9bf
commit d4103ee755

View file

@ -98,7 +98,7 @@ std::vector<std::string> pwr_on_query_cmds{
// Information
"SIGNAL?",
// "SOURCELIST?" // Pushed on demand if sensor value is empty (e.g. after boot-up)
// "SOURCELIST?" // Parser present in git history but removed until esphome can update selects after api connections are established
// "SOURCELISTA?", // same as SOURCELIST
"LOGTO?", // produces ERR
// "SNO?" // Pushed on demand if sensor value is empty (e.g. after boot-up)
@ -121,9 +121,6 @@ void tw7100Component::update() {
if (this->serial_->state.length() < 1) {
cmd_queue.push_back("SNO?");
}
if (sourcelist.empty()) {
cmd_queue.push_back("SOURCELIST?");
}
for (auto &cmd : pwr_on_query_cmds) {
cmd_queue.push_back(cmd);
}
@ -236,29 +233,6 @@ void tw7100Component::update_sensor(std::pair<std::string, std::string> data) {
auto call = luminance_select_->make_call();
call.set_option(luminance_select_->luminance[value_string]);
call.perform();
} else if (cmd == "SOURCELIST") {
std::string unparsed_result = value_string;
int first_token_end;
int second_token_end;
uint8_t parse_rounds = 0; // safety fallback if data contains unexpected content
do {
first_token_end = unparsed_result.find(" ");
second_token_end = unparsed_result.find(" ", first_token_end+1);
ESP_LOGV(TAG, "first_token_end: %i, second_token_end: %i, unparsed_result.length(): %li", first_token_end, second_token_end, unparsed_result.length() );
std::string key_string = unparsed_result.substr(0, first_token_end);
std::string value = unparsed_result.substr(first_token_end+1, second_token_end-first_token_end-1);
int key = std::stoi(key_string, nullptr, 16);
sourcelist[key] = value;
ESP_LOGV(TAG, "Added %s with key %i(0x%02x) to sourcelist", value.c_str(), key, key);
unparsed_result.erase(0, second_token_end+1);
ESP_LOGV(TAG, "rest string: %s", unparsed_result.c_str());
parse_rounds+=1;
} while (second_token_end > 0 && parse_rounds <= 50);
// TODO: if we exceed parse_rounds we most likely encountered a critical issue, inform user somehow
} else if (cmd == "SNO") {
serial_->publish_state(value_string);
} else if (cmd == "BTAUDIO") {