mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Allow accept/reject delta to be specified. (#5060)
This commit is contained in:
parent
7d9fc3ceaa
commit
b95a7f6438
3 changed files with 9 additions and 2 deletions
|
@ -32,6 +32,7 @@ from esphome.const import (
|
|||
CONF_MAGNITUDE,
|
||||
CONF_WAND_ID,
|
||||
CONF_LEVEL,
|
||||
CONF_DELTA,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
|
||||
|
@ -792,6 +793,7 @@ async def pioneer_action(var, config, args):
|
|||
PRONTO_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_DATA): cv.string,
|
||||
cv.Optional(CONF_DELTA, default=-1): cv.int_,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -803,6 +805,7 @@ def pronto_binary_sensor(var, config):
|
|||
cg.StructInitializer(
|
||||
ProntoData,
|
||||
("data", config[CONF_DATA]),
|
||||
("delta", config[CONF_DELTA]),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -49,13 +49,13 @@ bool ProntoData::operator==(const ProntoData &rhs) const {
|
|||
for (std::vector<uint16_t>::size_type i = 0; i < data1.size() - 1; ++i) {
|
||||
int diff = data2[i] - data1[i];
|
||||
diff *= diff;
|
||||
if (diff > 9)
|
||||
if (rhs.delta == -1 && diff > 9)
|
||||
return false;
|
||||
|
||||
total_diff += diff;
|
||||
}
|
||||
|
||||
return total_diff <= data1.size() * 3;
|
||||
return total_diff <= (rhs.delta == -1 ? data1.size() * 3 : rhs.delta);
|
||||
}
|
||||
|
||||
// DO NOT EXPORT from this file
|
||||
|
@ -222,6 +222,7 @@ optional<ProntoData> ProntoProtocol::decode(RemoteReceiveData src) {
|
|||
prontodata += compensate_and_dump_sequence_(data, timebase);
|
||||
|
||||
out.data = prontodata;
|
||||
out.delta = -1;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ std::vector<uint16_t> encode_pronto(const std::string &str);
|
|||
|
||||
struct ProntoData {
|
||||
std::string data;
|
||||
int delta;
|
||||
|
||||
bool operator==(const ProntoData &rhs) const;
|
||||
};
|
||||
|
@ -40,10 +41,12 @@ DECLARE_REMOTE_PROTOCOL(Pronto)
|
|||
template<typename... Ts> class ProntoAction : public RemoteTransmitterActionBase<Ts...> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(std::string, data)
|
||||
TEMPLATABLE_VALUE(int, delta)
|
||||
|
||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
||||
ProntoData data{};
|
||||
data.data = this->data_.value(x...);
|
||||
data.delta = this->delta_.value(x...);
|
||||
ProntoProtocol().encode(dst, data);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue