Refactored DucoSensor into DucoSerial

This commit is contained in:
Pieter Kokx 2024-11-16 16:05:39 +01:00
parent 23d1d24a87
commit dfbd5eabc2
No known key found for this signature in database
GPG Key ID: BD73BAB527D54451
4 changed files with 10 additions and 11 deletions

View File

@ -1,5 +1,4 @@
#include "duco.h"
#include "text_sensor/sensor.h"
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"
#include <vector>

View File

@ -9,14 +9,14 @@ DEPENDENCIES = ["duco"]
CODEOWNERS = ["@kokx"]
duco_ns = cg.esphome_ns.namespace("duco")
DucoSensor = duco_ns.class_("DucoSensor", cg.PollingComponent, text_sensor.TextSensor)
DucoSerial = duco_ns.class_("DucoSerial", cg.PollingComponent, text_sensor.TextSensor)
CONFIG_SCHEMA = cv.All(
text_sensor.text_sensor_schema(DucoSensor)
text_sensor.text_sensor_schema(DucoSerial)
.extend(cv.COMPONENT_SCHEMA)
.extend(cv.polling_component_schema("60s"))
.extend(cv.polling_component_schema("300s"))
.extend(DUCO_COMPONENT_SCHEMA)
.extend({cv.GenerateID(): cv.declare_id(DucoSensor)})
.extend({cv.GenerateID(): cv.declare_id(DucoSerial)})
)

View File

@ -1,4 +1,4 @@
#include "sensor.h"
#include "serial.h"
#include "../duco.h"
#include <vector>
@ -7,20 +7,20 @@ namespace duco {
static const char *const TAG = "duco sensor";
void DucoSensor::setup() {}
void DucoSerial::setup() {}
void DucoSensor::update() {
void DucoSerial::update() {
// ask for serial
std::vector<uint8_t> message = {0x01, 0x01, 0x00, 0x1a, 0x10};
this->parent_->send(0x10, message, this);
}
float DucoSensor::get_setup_priority() const {
float DucoSerial::get_setup_priority() const {
// After DUCO
return setup_priority::BUS - 2.0f;
}
void DucoSensor::receive_response(std::vector<uint8_t> message) {
void DucoSerial::receive_response(std::vector<uint8_t> message) {
if (message[1] == 0x12) {
// Serial response received, parse it
std::string serial(message.begin() + 5, message.end());

View File

@ -8,7 +8,7 @@
namespace esphome {
namespace duco {
class DucoSensor : public DucoDevice, public PollingComponent, public text_sensor::TextSensor {
class DucoSerial : public DucoDevice, public PollingComponent, public text_sensor::TextSensor {
public:
void setup() override;
void update() override;