This commit is contained in:
Paul Wieland 2024-08-01 12:22:50 -04:00
parent 751053c64f
commit e9f43d81a3
3 changed files with 11 additions and 4 deletions

View File

@ -60,15 +60,22 @@ namespace ratgdo {
this->update_state(value);
});
std::string mname = "rolling_code_counter2";
// A second subscription, which seem to overwrite the first subscription
this->parent_->subscribe_rolling_code_counter([=](uint32_t value) {
this->parent_->subscribe_rolling_code_counter([=](uint32_t value, std::string mname) {
ESP_LOGD("XXX","A second rolling code counter subscription");
});
} else if (this->number_type_ == RATGDO_OPENING_DURATION) {
this->parent_->subscribe_opening_duration([=](float value) {
ESP_LOGD("ZZZ","The first opening duration subscription");
this->update_state(value);
});
this->parent_->subscribe_opening_duration([=](float value) {
ESP_LOGD("ZZZ","The second opening duration subscription");
});
} else if (this->number_type_ == RATGDO_CLOSING_DURATION) {
this->parent_->subscribe_closing_duration([=](float value) {
this->update_state(value);

View File

@ -597,13 +597,13 @@ namespace ratgdo {
this->protocol_->call(InactivateLearn {});
}
void RATGDOComponent::subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f)
void RATGDOComponent::subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f, const std::string &name = "rolling_code_counter");
{
// change update to children is defered until after component loop
// if multiple changes occur during component loop, only the last one is notified
auto counter = this->protocol_->call(GetRollingCodeCounter {});
if (counter.tag == Result::Tag::rolling_code_counter) {
counter.value.rolling_code_counter.value->subscribe([=](uint32_t state) { defer("rolling_code_counter", [=] { f(state); }); });
counter.value.rolling_code_counter.value->subscribe([=](uint32_t state) { defer(name, [=] { f(state); }); });
}
}
void RATGDOComponent::subscribe_opening_duration(std::function<void(float)>&& f)

View File

@ -155,7 +155,7 @@ namespace ratgdo {
void sync();
// children subscriptions
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f);
void subscribe_rolling_code_counter(std::function<void(uint32_t)>&& f, const std::string &name = "rolling_code_counter");
void subscribe_opening_duration(std::function<void(float)>&& f);
void subscribe_closing_duration(std::function<void(float)>&& f);
void subscribe_openings(std::function<void(uint16_t)>&& f);