rename EbusSensorBase to EbusItem

This commit is contained in:
Guido Schreuder 2024-02-25 14:24:06 +01:00
parent ce44dd9b1b
commit 42d62c3124
7 changed files with 22 additions and 22 deletions

View File

@ -125,16 +125,16 @@ async def to_code(config):
cg.add(var.set_update_interval(config[CONF_POLL_INTERVAL].total_milliseconds)) cg.add(var.set_update_interval(config[CONF_POLL_INTERVAL].total_milliseconds))
def sensor_base_config(ebus, sensor_base, config): def item_config(ebus, item, config):
cg.add(sensor_base.set_parent(ebus)) cg.add(item.set_parent(ebus))
cg.add(ebus.add_sensor(sensor_base)), cg.add(ebus.add_item(item)),
cg.add(sensor_base.set_send_poll(config[CONF_TELEGRAM][CONF_SEND_POLL])) cg.add(item.set_send_poll(config[CONF_TELEGRAM][CONF_SEND_POLL]))
if CONF_ADDRESS in config[CONF_TELEGRAM]: if CONF_ADDRESS in config[CONF_TELEGRAM]:
cg.add(sensor_base.set_address(config[CONF_TELEGRAM][CONF_ADDRESS])) cg.add(item.set_address(config[CONF_TELEGRAM][CONF_ADDRESS]))
cg.add(sensor_base.set_command(config[CONF_TELEGRAM][CONF_COMMAND])) cg.add(item.set_command(config[CONF_TELEGRAM][CONF_COMMAND]))
cg.add(sensor_base.set_payload(config[CONF_TELEGRAM][CONF_PAYLOAD])) cg.add(item.set_payload(config[CONF_TELEGRAM][CONF_PAYLOAD]))
cg.add( cg.add(
sensor_base.set_response_read_position( item.set_response_read_position(
config[CONF_TELEGRAM][CONF_DECODE][CONF_POSITION] config[CONF_TELEGRAM][CONF_DECODE][CONF_POSITION]
) )
) )

View File

@ -8,7 +8,7 @@ from .. import (
CONF_DECODE, CONF_DECODE,
ebus_ns, ebus_ns,
create_telegram_schema, create_telegram_schema,
sensor_base_config, item_config,
) )
AUTO_LOAD = ["ebus"] AUTO_LOAD = ["ebus"]
@ -32,5 +32,5 @@ async def to_code(config):
ebus = await cg.get_variable(config[CONF_EBUS_ID]) ebus = await cg.get_variable(config[CONF_EBUS_ID])
sens = await binary_sensor.new_binary_sensor(config) sens = await binary_sensor.new_binary_sensor(config)
sensor_base_config(ebus, sens, config) item_config(ebus, sens, config)
cg.add(sens.set_response_read_mask(config[CONF_TELEGRAM][CONF_DECODE][CONF_MASK])) cg.add(sens.set_response_read_mask(config[CONF_TELEGRAM][CONF_DECODE][CONF_MASK]))

View File

@ -6,7 +6,7 @@
namespace esphome { namespace esphome {
namespace ebus { namespace ebus {
class EbusBinarySensor : public EbusSensorBase, public binary_sensor::BinarySensor { class EbusBinarySensor : public EbusItem, public binary_sensor::BinarySensor {
public: public:
EbusBinarySensor() {} EbusBinarySensor() {}

View File

@ -180,7 +180,7 @@ void EbusComponent::update() {
} }
} }
void EbusSensorBase::dump_config() { void EbusItem::dump_config() {
ESP_LOGCONFIG(TAG, "EbusSensor"); ESP_LOGCONFIG(TAG, "EbusSensor");
ESP_LOGCONFIG(TAG, " message:"); ESP_LOGCONFIG(TAG, " message:");
ESP_LOGCONFIG(TAG, " send_poll: %s", this->send_poll_ ? "true" : "false"); ESP_LOGCONFIG(TAG, " send_poll: %s", this->send_poll_ ? "true" : "false");
@ -192,7 +192,7 @@ void EbusSensorBase::dump_config() {
ESP_LOGCONFIG(TAG, " command: 0x%04x", this->command_); ESP_LOGCONFIG(TAG, " command: 0x%04x", this->command_);
}; };
optional<SendCommand> EbusSensorBase::prepare_command() { optional<SendCommand> EbusItem::prepare_command() {
optional<SendCommand> command; optional<SendCommand> command;
if (this->send_poll_) { if (this->send_poll_) {
@ -202,7 +202,7 @@ optional<SendCommand> EbusSensorBase::prepare_command() {
return command; return command;
} }
uint32_t EbusSensorBase::get_response_bytes(Telegram &telegram, uint8_t start, uint8_t length) { uint32_t EbusItem::get_response_bytes(Telegram &telegram, uint8_t start, uint8_t length) {
uint32_t result = 0; uint32_t result = 0;
for (uint8_t i = 0; i < 4 && i < length; i++) { for (uint8_t i = 0; i < 4 && i < length; i++) {
result = result | (telegram.get_response_byte(start + i) << (i * 8)); result = result | (telegram.get_response_byte(start + i) << (i * 8));
@ -210,7 +210,7 @@ uint32_t EbusSensorBase::get_response_bytes(Telegram &telegram, uint8_t start, u
return result; return result;
} }
bool EbusSensorBase::is_mine(Telegram &telegram) { bool EbusItem::is_mine(Telegram &telegram) {
if (this->address_ != SYN && this->address_ != telegram.get_zz()) { if (this->address_ != SYN && this->address_ != telegram.get_zz()) {
return false; return false;
} }

View File

@ -34,7 +34,7 @@ class EbusSender {
virtual optional<SendCommand> prepare_command() = 0; virtual optional<SendCommand> prepare_command() = 0;
}; };
class EbusSensorBase : public EbusReceiver, public EbusSender, public Component { class EbusItem : public EbusReceiver, public EbusSender, public Component {
public: public:
void dump_config() override; void dump_config() override;
@ -79,9 +79,9 @@ class EbusComponent : public PollingComponent {
void add_sender(EbusSender * /*sender*/); void add_sender(EbusSender * /*sender*/);
void add_receiver(EbusReceiver * /*receiver*/); void add_receiver(EbusReceiver * /*receiver*/);
void add_sensor(EbusSensorBase *sensor) { void add_item(EbusItem *item) {
this->add_sender(sensor); this->add_sender(item);
this->add_receiver(sensor); this->add_receiver(item);
}; };
void update() override; void update() override;

View File

@ -12,7 +12,7 @@ from .. import (
CONF_DECODE, CONF_DECODE,
ebus_ns, ebus_ns,
create_telegram_schema, create_telegram_schema,
sensor_base_config, item_config,
) )
AUTO_LOAD = ["ebus"] AUTO_LOAD = ["ebus"]
@ -37,7 +37,7 @@ async def to_code(config):
ebus = await cg.get_variable(config[CONF_EBUS_ID]) ebus = await cg.get_variable(config[CONF_EBUS_ID])
sens = await sensor.new_sensor(config) sens = await sensor.new_sensor(config)
sensor_base_config(ebus, sens, config) item_config(ebus, sens, config)
cg.add(sens.set_response_read_bytes(config[CONF_TELEGRAM][CONF_DECODE][CONF_BYTES])) cg.add(sens.set_response_read_bytes(config[CONF_TELEGRAM][CONF_DECODE][CONF_BYTES]))
cg.add( cg.add(

View File

@ -6,7 +6,7 @@
namespace esphome { namespace esphome {
namespace ebus { namespace ebus {
class EbusSensor : public EbusSensorBase, public sensor::Sensor { class EbusSensor : public EbusItem, public sensor::Sensor {
public: public:
EbusSensor() {} EbusSensor() {}