mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 13:13:54 +01:00
fixed lint errors
This commit is contained in:
parent
7a89fbc1c3
commit
06e4eaf139
@ -19,6 +19,8 @@ MULTI_CONF = False
|
||||
CONF_DEVICE_INFO = "device_info"
|
||||
|
||||
optolink_ns = cg.esphome_ns.namespace("optolink")
|
||||
CONF_OPTOLINK_ID = "optolink_id"
|
||||
|
||||
OptolinkComponent = optolink_ns.class_("Optolink", cg.Component)
|
||||
StateSensor = optolink_ns.class_(
|
||||
"OptolinkStateSensor", ts.TextSensor, cg.PollingComponent
|
||||
|
@ -3,12 +3,11 @@ import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_ID, CONF_ADDRESS, CONF_UPDATE_INTERVAL
|
||||
from . import optolink_ns, OptolinkComponent
|
||||
from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID
|
||||
|
||||
OptolinkBinarySensor = optolink_ns.class_(
|
||||
"OptolinkBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent
|
||||
)
|
||||
CONF_OPTOLINK_ID = "optolink_id"
|
||||
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(OptolinkBinarySensor).extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OPTOLINK_ID): cv.use_id(OptolinkComponent),
|
||||
|
@ -2,7 +2,6 @@ from esphome import core
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import number
|
||||
from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA
|
||||
from esphome.const import (
|
||||
CONF_ADDRESS,
|
||||
CONF_BYTES,
|
||||
@ -13,13 +12,13 @@ from esphome.const import (
|
||||
CONF_STEP,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
)
|
||||
from . import OptolinkComponent, optolink_ns
|
||||
from .sensor import SENSOR_BASE_SCHEMA
|
||||
from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID
|
||||
|
||||
OptolinkNumber = optolink_ns.class_(
|
||||
"OptolinkNumber", number.Number, cg.PollingComponent
|
||||
)
|
||||
|
||||
CONF_OPTOLINK_ID = "optolink_id"
|
||||
CONFIG_SCHEMA = (
|
||||
number.NUMBER_SCHEMA.extend(
|
||||
{
|
||||
|
@ -1,13 +1,19 @@
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/components/optolink/optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
VitoWiFiClass<VITOWIFI_PROTOCOL> VitoWiFi;
|
||||
#if defined(VITOWIFI_PROTOCOL)
|
||||
// NOLINTNEXTLINE
|
||||
VitoWiFiClass<VITOWIFI_PROTOCOL> VitoWiFi; // VITOWIFI_PROTOCOL always is set
|
||||
#else
|
||||
// NOLINTNEXTLINE
|
||||
VitoWiFiClass<P300> VitoWiFi; // this is not really a fallback but dedicated to clang-lint
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
void Optolink::_comm() {
|
||||
void Optolink::comm_() {
|
||||
ESP_LOGD("Optolink", "enter _comm");
|
||||
VitoWiFi.readAll();
|
||||
ESP_LOGD("Optolink", "exit _comm");
|
||||
@ -32,11 +38,11 @@ void Optolink::setup() {
|
||||
|
||||
void Optolink::loop() { VitoWiFi.loop(); }
|
||||
|
||||
void Optolink::set_error(const std::string &format, ...) {
|
||||
void Optolink::set_error(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char buffer[128];
|
||||
size_t n = std::vsnprintf(buffer, sizeof(buffer), format.c_str(), args);
|
||||
std::vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
error_ = buffer;
|
||||
@ -49,12 +55,12 @@ void Optolink::read_value(IDatapoint *datapoint) {
|
||||
}
|
||||
}
|
||||
|
||||
void Optolink::write_value(IDatapoint *datapoint, DPValue dpValue) {
|
||||
void Optolink::write_value(IDatapoint *datapoint, DPValue dp_value) {
|
||||
if (datapoint != nullptr) {
|
||||
char buffer[64];
|
||||
dpValue.getString(buffer, sizeof(buffer));
|
||||
dp_value.getString(buffer, sizeof(buffer));
|
||||
ESP_LOGI("Optolink", " write value %s of datapoint %s", buffer, datapoint->getName());
|
||||
VitoWiFi.writeDatapoint(*datapoint, dpValue);
|
||||
VitoWiFi.writeDatapoint(*datapoint, dp_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
16
esphome/components/optolink/optolink.h
Executable file → Normal file
16
esphome/components/optolink/optolink.h
Executable file → Normal file
@ -4,19 +4,11 @@
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include <VitoWiFi.h>
|
||||
|
||||
using namespace esphome;
|
||||
using namespace sensor;
|
||||
using namespace binary_sensor;
|
||||
using namespace text_sensor;
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
// '00' ='WW' '01' ='RED' '02' ='NORM' '03' ='H+WW' '04' ='H+WW FS' '05' ='ABSCHALT'
|
||||
|
||||
//=====================================================================================================================
|
||||
class Optolink : public esphome::Component, public Print {
|
||||
protected:
|
||||
std::string error_ = "OK";
|
||||
@ -25,7 +17,7 @@ class Optolink : public esphome::Component, public Print {
|
||||
int rx_pin_;
|
||||
int tx_pin_;
|
||||
|
||||
void _comm();
|
||||
void comm_();
|
||||
|
||||
public:
|
||||
void setup() override;
|
||||
@ -38,10 +30,10 @@ class Optolink : public esphome::Component, public Print {
|
||||
void set_rx_pin(int rx_pin) { rx_pin_ = rx_pin; }
|
||||
void set_tx_pin(int tx_pin) { tx_pin_ = tx_pin; }
|
||||
|
||||
void write_value(IDatapoint *datapoint, DPValue dpValue);
|
||||
void write_value(IDatapoint *datapoint, DPValue dp_value);
|
||||
void read_value(IDatapoint *datapoint);
|
||||
|
||||
void set_error(const std::string &format, ...);
|
||||
void set_error(const char *format, ...);
|
||||
std::string get_error() { return error_; }
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -18,7 +18,7 @@ class OptolinkBinarySensor : public OptolinkSensorBase,
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override { setup_datapoint(); }
|
||||
void setup() override { setup_datapoint_(); }
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
const std::string &get_sensor_name() override { return get_name(); }
|
||||
|
22
esphome/components/optolink/optolink_device_info_sensor.cpp
Normal file
22
esphome/components/optolink/optolink_device_info_sensor.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "optolink_device_info_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
void OptolinkDeviceInfoSensor::setup() {
|
||||
datapoint_ = new Datapoint<conv4_1_UL>(get_name().c_str(), "optolink", 0x00f8, false);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
uint32_t value = dp_value.getU32();
|
||||
ESP_LOGD("OptolinkTextSensor", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), value);
|
||||
uint8_t *bytes = (uint8_t *) &value;
|
||||
uint16_t tmp = esphome::byteswap(*((uint16_t *) bytes));
|
||||
std::string geraetekennung = esphome::format_hex_pretty(&tmp, 1);
|
||||
std::string hardware_revision = esphome::format_hex_pretty((uint8_t *) bytes + 2, 1);
|
||||
std::string software_index = esphome::format_hex_pretty((uint8_t *) bytes + 3, 1);
|
||||
publish_state("Device ID: " + geraetekennung + "|Hardware Revision: " + hardware_revision +
|
||||
"|Software Index: " + software_index);
|
||||
});
|
||||
}
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
@ -3,14 +3,14 @@
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent {
|
||||
public:
|
||||
OptolinkDeviceInfoSensor(std::string name, Optolink *optolink) {
|
||||
OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) {
|
||||
optolink_ = optolink;
|
||||
set_name(name);
|
||||
set_update_interval(1800000);
|
||||
@ -18,20 +18,7 @@ class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override {
|
||||
datapoint_ = new Datapoint<conv4_1_UL>(get_name().c_str(), "optolink", 0x00f8, false);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
uint32_t value = dpValue.getU32();
|
||||
ESP_LOGD("OptolinkTextSensor", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), value);
|
||||
uint8_t *bytes = (uint8_t *) &value;
|
||||
uint16_t tmp = esphome::byteswap(*((uint16_t *) bytes));
|
||||
std::string geraetekennung = esphome::format_hex_pretty(&tmp, 1);
|
||||
std::string hardware_revision = esphome::format_hex_pretty((uint8_t *) bytes + 2, 1);
|
||||
std::string software_index = esphome::format_hex_pretty((uint8_t *) bytes + 3, 1);
|
||||
publish_state("Device ID: " + geraetekennung + "|Hardware Revision: " + hardware_revision +
|
||||
"|Software Index: " + software_index);
|
||||
});
|
||||
}
|
||||
void setup() override;
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "optolink_number.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -11,7 +11,7 @@ void OptolinkNumber::control(float value) {
|
||||
ESP_LOGE("OptolinkNumber", "datapoint value of number %s not in allowed range", get_sensor_name().c_str());
|
||||
} else {
|
||||
ESP_LOGI("OptolinkNumber", "control of number %s to value %f", get_sensor_name().c_str(), value);
|
||||
update_datapoint(value);
|
||||
update_datapoint_(value);
|
||||
publish_state(value);
|
||||
}
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -13,7 +13,7 @@ class OptolinkNumber : public OptolinkSensorBase, public esphome::number::Number
|
||||
OptolinkNumber(Optolink *optolink) : OptolinkSensorBase(optolink, true) {}
|
||||
|
||||
protected:
|
||||
void setup() override { setup_datapoint(); }
|
||||
void setup() override { setup_datapoint_(); }
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
const std::string &get_sensor_name() override { return get_name(); }
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "optolink_select.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -9,7 +9,7 @@ void OptolinkSelect::control(const std::string &value) {
|
||||
for (auto it = mapping_->begin(); it != mapping_->end(); ++it) {
|
||||
if (it->second == value) {
|
||||
ESP_LOGI("OptolinkSelect", "control of select %s to value %s", get_sensor_name().c_str(), it->first.c_str());
|
||||
update_datapoint(std::stof(it->first));
|
||||
update_datapoint_(std::stof(it->first));
|
||||
publish_state(it->second);
|
||||
break;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -16,14 +16,14 @@ class OptolinkSelect : public OptolinkSensorBase, public esphome::select::Select
|
||||
void set_map(std::map<std::string, std::string> *mapping) {
|
||||
mapping_ = mapping;
|
||||
std::vector<std::string> values;
|
||||
for (auto it = mapping->begin(); it != mapping->end(); ++it) {
|
||||
values.push_back(it->second);
|
||||
for (auto &it : *mapping) {
|
||||
values.push_back(it.second);
|
||||
}
|
||||
traits.set_options(values);
|
||||
};
|
||||
|
||||
protected:
|
||||
void setup() override { setup_datapoint(); }
|
||||
void setup() override { setup_datapoint_(); }
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
const std::string &get_sensor_name() override { return get_name(); }
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -15,7 +15,7 @@ class OptolinkSensor : public OptolinkSensorBase, public esphome::sensor::Sensor
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() { setup_datapoint(); }
|
||||
void setup() { setup_datapoint_(); }
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
const std::string &get_sensor_name() override { return get_name(); }
|
||||
|
@ -4,7 +4,7 @@
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
void OptolinkSensorBase::update_datapoint(float value) {
|
||||
void OptolinkSensorBase::update_datapoint_(float value) {
|
||||
if (!writeable_) {
|
||||
optolink_->set_error("try to control not writable number %s", get_sensor_name().c_str());
|
||||
ESP_LOGE("OptolinkSensorBase", "try to control not writable number %s", get_sensor_name().c_str());
|
||||
@ -31,8 +31,6 @@ void OptolinkSensorBase::update_datapoint(float value) {
|
||||
optolink_->write_value(datapoint_, DPValue((uint16_t) value));
|
||||
break;
|
||||
case 10:
|
||||
optolink_->write_value(datapoint_, DPValue((float) value));
|
||||
break;
|
||||
case 100:
|
||||
optolink_->write_value(datapoint_, DPValue((float) value));
|
||||
break;
|
||||
@ -66,22 +64,22 @@ void OptolinkSensorBase::update_datapoint(float value) {
|
||||
}
|
||||
}
|
||||
|
||||
void OptolinkSensorBase::setup_datapoint() {
|
||||
void OptolinkSensorBase::setup_datapoint_() {
|
||||
switch (bytes_) {
|
||||
case 1:
|
||||
switch (div_ratio_) {
|
||||
case 1:
|
||||
datapoint_ = new Datapoint<conv1_1_US>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU8());
|
||||
value_changed(dpValue.getU8());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU8());
|
||||
value_changed(dp_value.getU8());
|
||||
});
|
||||
break;
|
||||
case 10:
|
||||
datapoint_ = new Datapoint<conv1_10_F>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat());
|
||||
value_changed(dpValue.getFloat());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat());
|
||||
value_changed(dp_value.getFloat());
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@ -94,23 +92,23 @@ void OptolinkSensorBase::setup_datapoint() {
|
||||
switch (div_ratio_) {
|
||||
case 1:
|
||||
datapoint_ = new Datapoint<conv2_1_US>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU16());
|
||||
value_changed(dpValue.getU16());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU16());
|
||||
value_changed(dp_value.getU16());
|
||||
});
|
||||
break;
|
||||
case 10:
|
||||
datapoint_ = new Datapoint<conv2_10_F>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat());
|
||||
value_changed(dpValue.getFloat());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat());
|
||||
value_changed(dp_value.getFloat());
|
||||
});
|
||||
break;
|
||||
case 100:
|
||||
datapoint_ = new Datapoint<conv2_100_F>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat());
|
||||
value_changed(dpValue.getFloat());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat());
|
||||
value_changed(dp_value.getFloat());
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@ -123,16 +121,16 @@ void OptolinkSensorBase::setup_datapoint() {
|
||||
switch (div_ratio_) {
|
||||
case 1:
|
||||
datapoint_ = new Datapoint<conv4_1_UL>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU32());
|
||||
value_changed(dpValue.getU32());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU32());
|
||||
value_changed(dp_value.getU32());
|
||||
});
|
||||
break;
|
||||
case 3600:
|
||||
datapoint_ = new Datapoint<conv4_3600_F>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat());
|
||||
value_changed(dpValue.getFloat());
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat());
|
||||
value_changed(dp_value.getFloat());
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@ -153,6 +151,7 @@ void conv2_100_F::encode(uint8_t *out, DPValue in) {
|
||||
out[1] = tmp >> 8;
|
||||
out[0] = tmp & 0xFF;
|
||||
}
|
||||
|
||||
DPValue conv2_100_F::decode(const uint8_t *in) {
|
||||
int16_t tmp = in[1] << 8 | in[0];
|
||||
DPValue out(tmp / 100.0f);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -18,8 +18,8 @@ class OptolinkSensorBase {
|
||||
int bytes_;
|
||||
int div_ratio_ = 1;
|
||||
|
||||
void setup_datapoint();
|
||||
void update_datapoint(float value);
|
||||
void setup_datapoint_();
|
||||
void update_datapoint_(float value);
|
||||
|
||||
public:
|
||||
OptolinkSensorBase(Optolink *optolink, bool writeable = false) {
|
||||
@ -36,11 +36,12 @@ class OptolinkSensorBase {
|
||||
virtual void value_changed(float state) = 0;
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE
|
||||
class conv2_100_F : public DPType {
|
||||
public:
|
||||
void encode(uint8_t *out, DPValue in);
|
||||
DPValue decode(const uint8_t *in);
|
||||
const size_t getLength() const { return 2; }
|
||||
size_t get_length() const { return 2; }
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "optolink_switch.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -11,7 +11,7 @@ void OptolinkSwitch::write_state(bool value) {
|
||||
ESP_LOGE("OptolinkSwitch", "datapoint value of switch %s not 0 or 1", get_sensor_name().c_str());
|
||||
} else {
|
||||
ESP_LOGI("OptolinkSwitch", "control of switch %s to value %d", get_sensor_name().c_str(), value);
|
||||
update_datapoint(value);
|
||||
update_datapoint_(value);
|
||||
publish_state(value);
|
||||
}
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -16,13 +16,13 @@ class OptolinkSwitch : public OptolinkSensorBase, public esphome::switch_::Switc
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override { setup_datapoint(); }
|
||||
void setup() override { setup_datapoint_(); }
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
const std::string &get_sensor_name() override { return get_name(); }
|
||||
void value_changed(float state) override { publish_state(state); };
|
||||
|
||||
void write_state(bool state) override;
|
||||
void write_state(bool value) override;
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include "optolink_text_sensor.h"
|
||||
#include "optolink.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
void OptolinkTextSensor::setup() {
|
||||
if (!raw_) {
|
||||
setup_datapoint();
|
||||
setup_datapoint_();
|
||||
} else {
|
||||
datapoint_ = new Datapoint<convRaw>(get_sensor_name().c_str(), "optolink", address_, writeable_);
|
||||
datapoint_->setLength(bytes_);
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) {
|
||||
datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) {
|
||||
ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: <raw>", dp.getGroup(), dp.getName());
|
||||
uint8_t buffer[bytes_ + 1];
|
||||
dpValue.getRaw(buffer);
|
||||
dp_value.getRaw(buffer);
|
||||
buffer[bytes_] = 0x0;
|
||||
publish_state((char *) buffer);
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "optolink.h"
|
||||
#include "optolink_sensor_base.h"
|
||||
#include <VitoWiFi.h>
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
@ -2,7 +2,6 @@ from esphome import core
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import select
|
||||
from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA
|
||||
from esphome.const import (
|
||||
CONF_ADDRESS,
|
||||
CONF_BYTES,
|
||||
@ -12,7 +11,8 @@ from esphome.const import (
|
||||
CONF_TO,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
)
|
||||
from . import OptolinkComponent, optolink_ns
|
||||
from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID
|
||||
from .sensor import SENSOR_BASE_SCHEMA
|
||||
|
||||
OptolinkSelect = optolink_ns.class_(
|
||||
"OptolinkSelect", select.Select, cg.PollingComponent
|
||||
@ -32,7 +32,6 @@ def validate_mapping(value):
|
||||
)(value)
|
||||
|
||||
|
||||
CONF_OPTOLINK_ID = "optolink_id"
|
||||
CONF_MAP = "map"
|
||||
MAP_ID = "mappings"
|
||||
CONFIG_SCHEMA = (
|
||||
|
@ -1,6 +1,5 @@
|
||||
from esphome import core
|
||||
import esphome.codegen as cg
|
||||
from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import (
|
||||
@ -11,13 +10,13 @@ from esphome.const import (
|
||||
CONF_RAW,
|
||||
CONF_UPDATE_INTERVAL,
|
||||
)
|
||||
from . import optolink_ns, OptolinkComponent
|
||||
from . import optolink_ns, OptolinkComponent, CONF_OPTOLINK_ID
|
||||
from .sensor import SENSOR_BASE_SCHEMA
|
||||
|
||||
OptolinkTextSensor = optolink_ns.class_(
|
||||
"OptolinkTextSensor", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
|
||||
CONF_OPTOLINK_ID = "optolink_id"
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
text_sensor.text_sensor_schema(OptolinkTextSensor)
|
||||
.extend(
|
||||
|
@ -65,6 +65,7 @@ lib_deps =
|
||||
rweather/Crypto@0.4.0 ; dsmr
|
||||
dudanov/MideaUART@1.1.8 ; midea
|
||||
tonia/HeatpumpIR@1.0.20 ; heatpumpir
|
||||
bertmelis/VitoWiFi@1.0.2 ; optolink
|
||||
build_flags =
|
||||
${common.build_flags}
|
||||
-DUSE_ARDUINO
|
||||
|
Loading…
Reference in New Issue
Block a user