mirror of
https://github.com/esphome/esphome.git
synced 2025-11-16 23:05:46 +00:00
Merge branch 'binary_sensor_namespace_cleanup' into integration
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
#include "automation.h"
|
#include "automation.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
static const char *const TAG = "binary_sensor.automation";
|
static const char *const TAG = "binary_sensor.automation";
|
||||||
|
|
||||||
void binary_sensor::MultiClickTrigger::on_state_(bool state) {
|
void MultiClickTrigger::on_state_(bool state) {
|
||||||
// Handle duplicate events
|
// Handle duplicate events
|
||||||
if (state == this->last_state_) {
|
if (state == this->last_state_) {
|
||||||
return;
|
return;
|
||||||
@@ -67,7 +66,7 @@ void binary_sensor::MultiClickTrigger::on_state_(bool state) {
|
|||||||
|
|
||||||
*this->at_index_ = *this->at_index_ + 1;
|
*this->at_index_ = *this->at_index_ + 1;
|
||||||
}
|
}
|
||||||
void binary_sensor::MultiClickTrigger::schedule_cooldown_() {
|
void MultiClickTrigger::schedule_cooldown_() {
|
||||||
ESP_LOGV(TAG, "Multi Click: Invalid length of press, starting cooldown of %" PRIu32 " ms", this->invalid_cooldown_);
|
ESP_LOGV(TAG, "Multi Click: Invalid length of press, starting cooldown of %" PRIu32 " ms", this->invalid_cooldown_);
|
||||||
this->is_in_cooldown_ = true;
|
this->is_in_cooldown_ = true;
|
||||||
this->set_timeout("cooldown", this->invalid_cooldown_, [this]() {
|
this->set_timeout("cooldown", this->invalid_cooldown_, [this]() {
|
||||||
@@ -79,7 +78,7 @@ void binary_sensor::MultiClickTrigger::schedule_cooldown_() {
|
|||||||
this->cancel_timeout("is_valid");
|
this->cancel_timeout("is_valid");
|
||||||
this->cancel_timeout("is_not_valid");
|
this->cancel_timeout("is_not_valid");
|
||||||
}
|
}
|
||||||
void binary_sensor::MultiClickTrigger::schedule_is_valid_(uint32_t min_length) {
|
void MultiClickTrigger::schedule_is_valid_(uint32_t min_length) {
|
||||||
if (min_length == 0) {
|
if (min_length == 0) {
|
||||||
this->is_valid_ = true;
|
this->is_valid_ = true;
|
||||||
return;
|
return;
|
||||||
@@ -90,19 +89,19 @@ void binary_sensor::MultiClickTrigger::schedule_is_valid_(uint32_t min_length) {
|
|||||||
this->is_valid_ = true;
|
this->is_valid_ = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void binary_sensor::MultiClickTrigger::schedule_is_not_valid_(uint32_t max_length) {
|
void MultiClickTrigger::schedule_is_not_valid_(uint32_t max_length) {
|
||||||
this->set_timeout("is_not_valid", max_length, [this]() {
|
this->set_timeout("is_not_valid", max_length, [this]() {
|
||||||
ESP_LOGV(TAG, "Multi Click: You waited too long to %s.", this->parent_->state ? "RELEASE" : "PRESS");
|
ESP_LOGV(TAG, "Multi Click: You waited too long to %s.", this->parent_->state ? "RELEASE" : "PRESS");
|
||||||
this->is_valid_ = false;
|
this->is_valid_ = false;
|
||||||
this->schedule_cooldown_();
|
this->schedule_cooldown_();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
void binary_sensor::MultiClickTrigger::cancel() {
|
void MultiClickTrigger::cancel() {
|
||||||
ESP_LOGV(TAG, "Multi Click: Sequence explicitly cancelled.");
|
ESP_LOGV(TAG, "Multi Click: Sequence explicitly cancelled.");
|
||||||
this->is_valid_ = false;
|
this->is_valid_ = false;
|
||||||
this->schedule_cooldown_();
|
this->schedule_cooldown_();
|
||||||
}
|
}
|
||||||
void binary_sensor::MultiClickTrigger::trigger_() {
|
void MultiClickTrigger::trigger_() {
|
||||||
ESP_LOGV(TAG, "Multi Click: Hooray, multi click is valid. Triggering!");
|
ESP_LOGV(TAG, "Multi Click: Hooray, multi click is valid. Triggering!");
|
||||||
this->at_index_.reset();
|
this->at_index_.reset();
|
||||||
this->cancel_timeout("trigger");
|
this->cancel_timeout("trigger");
|
||||||
@@ -118,5 +117,4 @@ bool match_interval(uint32_t min_length, uint32_t max_length, uint32_t length) {
|
|||||||
return length >= min_length && length <= max_length;
|
return length >= min_length && length <= max_length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
struct MultiClickTriggerEvent {
|
struct MultiClickTriggerEvent {
|
||||||
bool state;
|
bool state;
|
||||||
@@ -172,5 +171,4 @@ template<typename... Ts> class BinarySensorInvalidateAction : public Action<Ts..
|
|||||||
BinarySensor *sensor_;
|
BinarySensor *sensor_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
#include "esphome/core/controller_registry.h"
|
#include "esphome/core/controller_registry.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
|
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
static const char *const TAG = "binary_sensor";
|
static const char *const TAG = "binary_sensor";
|
||||||
|
|
||||||
@@ -63,6 +61,4 @@ void BinarySensor::add_filters(std::initializer_list<Filter *> filters) {
|
|||||||
}
|
}
|
||||||
bool BinarySensor::is_status_binary_sensor() const { return false; }
|
bool BinarySensor::is_status_binary_sensor() const { return false; }
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
|
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
|
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
class BinarySensor;
|
class BinarySensor;
|
||||||
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj);
|
void log_binary_sensor(const char *tag, const char *prefix, const char *type, BinarySensor *obj);
|
||||||
@@ -70,5 +68,4 @@ class BinarySensorInitiallyOff : public BinarySensor {
|
|||||||
bool has_state() const override { return true; }
|
bool has_state() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
#include "binary_sensor.h"
|
#include "binary_sensor.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
|
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
static const char *const TAG = "sensor.filter";
|
static const char *const TAG = "sensor.filter";
|
||||||
|
|
||||||
@@ -132,6 +130,4 @@ optional<bool> SettleFilter::new_value(bool value) {
|
|||||||
|
|
||||||
float SettleFilter::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float SettleFilter::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
|
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::binary_sensor {
|
||||||
|
|
||||||
namespace binary_sensor {
|
|
||||||
|
|
||||||
class BinarySensor;
|
class BinarySensor;
|
||||||
|
|
||||||
@@ -139,6 +137,4 @@ class SettleFilter : public Filter, public Component {
|
|||||||
bool steady_{true};
|
bool steady_{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace esphome::binary_sensor
|
||||||
|
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
Reference in New Issue
Block a user