mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
add extra option to specify if we want to send a poll message, also rename destination to target
This commit is contained in:
parent
3c885383c1
commit
6fe6776d38
3 changed files with 24 additions and 27 deletions
|
@ -19,7 +19,8 @@ AUTO_LOAD = ["ebus"]
|
|||
EbusSensor = ebus_ns.class_("EbusSensor", sensor.Sensor, cg.Component)
|
||||
|
||||
CONF_TELEGRAM = "telegram"
|
||||
CONF_DESTINATION = "destination"
|
||||
CONF_SEND_POLL = "send_poll"
|
||||
CONF_ADDRESS = "address"
|
||||
CONF_DECODE = "decode"
|
||||
CONF_DIVIDER = "divider"
|
||||
|
||||
|
@ -28,12 +29,12 @@ SYN = 0xAA
|
|||
ESC = 0xA9
|
||||
|
||||
|
||||
def validate_address(destination):
|
||||
if destination == SYN:
|
||||
def validate_address(address):
|
||||
if address == SYN:
|
||||
raise vol.Invalid("SYN symbol (0xAA) is not a valid address")
|
||||
if destination == ESC:
|
||||
if address == ESC:
|
||||
raise vol.Invalid("ESC symbol (0xA9) is not a valid address")
|
||||
return cv.hex_uint8_t(destination)
|
||||
return cv.hex_uint8_t(address)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
|
@ -46,8 +47,8 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.GenerateID(): cv.declare_id(EbusSensor),
|
||||
cv.Required(CONF_TELEGRAM): cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_SOURCE): validate_address,
|
||||
cv.Optional(CONF_DESTINATION): validate_address,
|
||||
cv.Optional(CONF_SEND_POLL, default=False): cv.boolean,
|
||||
cv.Optional(CONF_ADDRESS): validate_address,
|
||||
cv.Required(CONF_COMMAND): cv.hex_uint16_t,
|
||||
cv.Required(CONF_PAYLOAD): cv.Schema([cv.hex_uint8_t]),
|
||||
cv.Optional(CONF_DECODE): cv.Schema(
|
||||
|
@ -77,8 +78,8 @@ async def to_code(config):
|
|||
if CONF_SOURCE in conf[CONF_TELEGRAM]:
|
||||
cg.add(sens.set_source(conf[CONF_TELEGRAM][CONF_SOURCE]))
|
||||
|
||||
if CONF_DESTINATION in conf[CONF_TELEGRAM]:
|
||||
cg.add(sens.set_destination(conf[CONF_TELEGRAM][CONF_DESTINATION]))
|
||||
if CONF_ADDRESS in conf[CONF_TELEGRAM]:
|
||||
cg.add(sens.set_address(conf[CONF_TELEGRAM][CONF_ADDRESS]))
|
||||
cg.add(sens.set_command(conf[CONF_TELEGRAM][CONF_COMMAND]))
|
||||
cg.add(sens.set_payload(conf[CONF_TELEGRAM][CONF_PAYLOAD]))
|
||||
cg.add(
|
||||
|
|
|
@ -10,22 +10,18 @@ namespace ebus {
|
|||
void EbusSensor::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "EbusSensor");
|
||||
ESP_LOGCONFIG(TAG, " message:");
|
||||
if (this->source_ == SYN) {
|
||||
ESP_LOGCONFIG(TAG, " source: N/A");
|
||||
ESP_LOGCONFIG(TAG, " send_poll: %s", this->send_poll_ ? "true" : "false");
|
||||
if (this->address_ == SYN) {
|
||||
ESP_LOGCONFIG(TAG, " address: N/A");
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " source: 0x%02x", this->source_);
|
||||
}
|
||||
if (this->destination_ == SYN) {
|
||||
ESP_LOGCONFIG(TAG, " destination: N/A");
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " destination: 0x%02x", this->destination_);
|
||||
ESP_LOGCONFIG(TAG, " address: 0x%02x", this->address_);
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " command: 0x%04x", this->command_);
|
||||
};
|
||||
|
||||
void EbusSensor::set_primary_address(uint8_t primary_address) { this->primary_address_ = primary_address; }
|
||||
void EbusSensor::set_source(uint8_t source) { this->source_ = source; }
|
||||
void EbusSensor::set_destination(uint8_t destination) { this->destination_ = destination; }
|
||||
void EbusSensor::set_send_poll(bool send_poll) { this->send_poll_ = send_poll; }
|
||||
void EbusSensor::set_address(uint8_t address) { this->address_ = Elf::to_secondary(address); }
|
||||
void EbusSensor::set_command(uint16_t command) { this->command_ = command; }
|
||||
void EbusSensor::set_payload(const std::vector<uint8_t> &payload) { this->payload_ = payload; }
|
||||
void EbusSensor::set_response_read_position(uint8_t response_position) { this->response_position_ = response_position; }
|
||||
|
@ -34,10 +30,10 @@ void EbusSensor::set_response_read_divider(float response_divider) { this->respo
|
|||
|
||||
optional<SendCommand> EbusSensor::prepare_command() {
|
||||
optional<SendCommand> command;
|
||||
if (this->destination_ != SYN) {
|
||||
if (this->send_poll_) {
|
||||
command = SendCommand( //
|
||||
this->primary_address_, Elf::to_secondary(this->destination_), GET_BYTE(this->command_, 1),
|
||||
GET_BYTE(this->command_, 0), this->payload_.size(), &this->payload_[0]);
|
||||
this->primary_address_, this->address_, GET_BYTE(this->command_, 1), GET_BYTE(this->command_, 0),
|
||||
this->payload_.size(), &this->payload_[0]);
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
@ -62,7 +58,7 @@ float EbusSensor::to_float(Telegram &telegram, uint8_t start, uint8_t length, fl
|
|||
}
|
||||
|
||||
bool EbusSensor::is_mine(Telegram &telegram) {
|
||||
if (this->source_ != SYN && this->source_ != telegram.get_zz()) {
|
||||
if (this->address_ != SYN && this->address_ != telegram.get_zz()) {
|
||||
return false;
|
||||
}
|
||||
if (telegram.get_command() != this->command_) {
|
||||
|
|
|
@ -13,8 +13,8 @@ class EbusSensor : public EbusReceiver, public EbusSender, public sensor::Sensor
|
|||
void dump_config() override;
|
||||
|
||||
void set_primary_address(uint8_t /*primary_address*/) override;
|
||||
void set_source(uint8_t /*source*/);
|
||||
void set_destination(uint8_t /*destination*/);
|
||||
void set_send_poll(bool /*send_poll*/);
|
||||
void set_address(uint8_t /*address*/);
|
||||
void set_command(uint16_t /*command*/);
|
||||
void set_payload(const std::vector<uint8_t> & /*payload*/);
|
||||
|
||||
|
@ -32,8 +32,8 @@ class EbusSensor : public EbusReceiver, public EbusSender, public sensor::Sensor
|
|||
|
||||
protected:
|
||||
uint8_t primary_address_;
|
||||
uint8_t source_ = SYN;
|
||||
uint8_t destination_ = SYN;
|
||||
bool send_poll_;
|
||||
uint8_t address_ = SYN;
|
||||
uint16_t command_;
|
||||
std::vector<uint8_t> payload_{};
|
||||
uint8_t response_position_;
|
||||
|
|
Loading…
Reference in a new issue