Add AV Mute switch

This commit is contained in:
sqozz 2024-09-17 02:14:41 +02:00
parent f72e0ea591
commit 5d39f2979c
4 changed files with 19 additions and 1 deletions

View file

@ -19,6 +19,9 @@ CONFIG_SCHEMA = cv.Schema(
cv.Optional("BTAUDIO"): switch.switch_schema( cv.Optional("BTAUDIO"): switch.switch_schema(
tw7100Switch tw7100Switch
), ),
cv.Optional("MUTE"): switch.switch_schema(
tw7100Switch
),
} }
) )
@ -37,3 +40,9 @@ async def to_code(config):
cg.add(switch_.set_cmd("BTAUDIO")) cg.add(switch_.set_cmd("BTAUDIO"))
cg.add(switch_.set_tw7100_parent(parent)) cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_btaudio(switch_)) cg.add(parent.set_set_btaudio(switch_))
if "MUTE" in config:
switch_ = await switch.new_switch(config["MUTE"])
cg.add(switch_.set_cmd("MUTE"))
cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_mute(switch_))

View file

@ -26,6 +26,10 @@ void tw7100Switch::write_state(bool state) {
sprintf(param, "%02d", state); sprintf(param, "%02d", state);
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param); ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param);
parent_->push_cmd(cmd_, param); parent_->push_cmd(cmd_, param);
} else if (cmd_ == "MUTE") {
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);
} }
} }

View file

@ -69,7 +69,7 @@ std::vector<std::string> pwr_on_query_cmds{
"AUDIOOUT?", "AUDIOOUT?",
*/ */
// //
// "MUTE?", // TODO: implement parser "MUTE?",
// Environment settings // Environment settings
/* /*
"HREVERSE?", "HREVERSE?",
@ -246,6 +246,9 @@ void tw7100Component::update_sensor(std::pair<std::string, std::string> data) {
auto call = source_select_->make_call(); auto call = source_select_->make_call();
call.set_option(source_select_->sources[value_string]); call.set_option(source_select_->sources[value_string]);
call.perform(); call.perform();
} else if (cmd == "MUTE") {
ESP_LOGV(TAG, "updating mute switch with value %s", value_string);
mute_switch_->publish_state(value_string == "ON");
} 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());
} }

View file

@ -41,6 +41,7 @@ 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; }
void set_set_power(switch_::Switch *switch_) { this->power_switch_ = switch_; } void set_set_power(switch_::Switch *switch_) { this->power_switch_ = switch_; }
void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; } void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; }
void set_set_mute(switch_::Switch *switch_) { this->mute_switch_ = switch_; }
void set_set_source(tw7100::tw7100Select *source_) { this->source_select_ = source_; } void set_set_source(tw7100::tw7100Select *source_) { this->source_select_ = source_; }
void set_set_luminance(tw7100::tw7100Select *luminance_) { this->luminance_select_ = luminance_; } void set_set_luminance(tw7100::tw7100Select *luminance_) { this->luminance_select_ = luminance_; }
@ -54,6 +55,7 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
text_sensor::TextSensor *serial_{nullptr}; text_sensor::TextSensor *serial_{nullptr};
switch_::Switch *power_switch_{nullptr}; switch_::Switch *power_switch_{nullptr};
switch_::Switch *btaudio_switch_{nullptr}; switch_::Switch *btaudio_switch_{nullptr};
switch_::Switch *mute_switch_{nullptr};
tw7100::tw7100Select *source_select_{nullptr}; tw7100::tw7100Select *source_select_{nullptr};
tw7100::tw7100Select *luminance_select_{nullptr}; tw7100::tw7100Select *luminance_select_{nullptr};
}; };