mirror of
https://github.com/esphome/esphome.git
synced 2024-12-26 23:41:45 +01:00
fixed lint errors
This commit is contained in:
parent
357eb19945
commit
2318199825
7 changed files with 58 additions and 107 deletions
|
@ -78,6 +78,21 @@ size_t Optolink::write(uint8_t ch) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
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_LOGI(TAG, "recieved data for datapoint %s: %d", 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
|
||||
|
||||
|
|
|
@ -39,6 +39,41 @@ class Optolink : public esphome::Component, public Print {
|
|||
std::string get_error() { return error_; }
|
||||
};
|
||||
|
||||
class OptolinkStateSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent {
|
||||
public:
|
||||
OptolinkStateSensor(std::string name, Optolink *optolink) {
|
||||
optolink_ = optolink;
|
||||
set_name(name.c_str());
|
||||
set_update_interval(1000);
|
||||
set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override{};
|
||||
void update() override { publish_state(optolink_->get_error()); }
|
||||
|
||||
private:
|
||||
Optolink *optolink_;
|
||||
};
|
||||
|
||||
class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent {
|
||||
public:
|
||||
OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) {
|
||||
optolink_ = optolink;
|
||||
set_name(name.c_str());
|
||||
set_update_interval(1800000);
|
||||
set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override;
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
private:
|
||||
Optolink *optolink_;
|
||||
IDatapoint *datapoint_;
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ DAY_OF_WEEK = {
|
|||
"SATURDAY": 5,
|
||||
"SUNDAY": 6,
|
||||
}
|
||||
CONF_DOW = "day_of_week"
|
||||
CONF_DAY_OF_WEEK = "day_of_week"
|
||||
|
||||
OptolinkTextSensor = optolink_ns.class_(
|
||||
"OptolinkTextSensor", text_sensor.TextSensor, cg.PollingComponent
|
||||
|
@ -55,15 +55,15 @@ def check_dow():
|
|||
def validator_(config):
|
||||
if (
|
||||
config[CONF_MODE] in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
and CONF_DOW not in config
|
||||
and CONF_DAY_OF_WEEK not in config
|
||||
):
|
||||
raise cv.Invalid(f"{CONF_DOW} is required in mode DAY_SCHEDULE")
|
||||
raise cv.Invalid(f"{CONF_DAY_OF_WEEK} is required in mode DAY_SCHEDULE")
|
||||
if (
|
||||
config[CONF_MODE] not in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"]
|
||||
and CONF_DOW in config
|
||||
and CONF_DAY_OF_WEEK in config
|
||||
):
|
||||
raise cv.Invalid(
|
||||
f"{CONF_DOW} is only allowed in mode DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED"
|
||||
f"{CONF_DAY_OF_WEEK} is only allowed in mode DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED"
|
||||
)
|
||||
return config
|
||||
|
||||
|
@ -97,7 +97,7 @@ CONFIG_SCHEMA = cv.All(
|
|||
{
|
||||
cv.Optional(CONF_MODE, default="MAP"): cv.enum(MODE, upper=True),
|
||||
cv.Optional(CONF_BYTES): cv.int_range(min=1, max=9),
|
||||
cv.Optional(CONF_DOW): cv.enum(DAY_OF_WEEK, upper=True),
|
||||
cv.Optional(CONF_DAY_OF_WEEK): cv.enum(DAY_OF_WEEK, upper=True),
|
||||
cv.Optional(CONF_ENTITY_ID): cv.entity_id,
|
||||
}
|
||||
)
|
||||
|
@ -120,7 +120,7 @@ async def to_code(config):
|
|||
cg.add(var.set_div_ratio(config[CONF_DIV_RATIO]))
|
||||
if CONF_BYTES in config:
|
||||
cg.add(var.set_bytes(config[CONF_BYTES]))
|
||||
if CONF_DOW in config:
|
||||
cg.add(var.set_day_of_week(config[CONF_DOW]))
|
||||
if CONF_DAY_OF_WEEK in config:
|
||||
cg.add(var.set_day_of_week(config[CONF_DAY_OF_WEEK]))
|
||||
if CONF_ENTITY_ID in config:
|
||||
cg.add(var.set_entity_id(config[CONF_ENTITY_ID]))
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "optolink_device_info_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
static const char *const TAG = "optolink.text_sensor";
|
||||
|
||||
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_LOGI(TAG, "recieved data for datapoint %s: %d", 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
|
||||
|
||||
#endif
|
|
@ -1,34 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../optolink_sensor_base.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent {
|
||||
public:
|
||||
OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) {
|
||||
optolink_ = optolink;
|
||||
set_name(name.c_str());
|
||||
set_update_interval(1800000);
|
||||
set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override;
|
||||
void update() override { optolink_->read_value(datapoint_); }
|
||||
|
||||
private:
|
||||
Optolink *optolink_;
|
||||
IDatapoint *datapoint_;
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../optolink_sensor_base.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
class OptolinkStateSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent {
|
||||
public:
|
||||
OptolinkStateSensor(std::string name, Optolink *optolink) {
|
||||
optolink_ = optolink;
|
||||
set_name(name.c_str());
|
||||
set_update_interval(1000);
|
||||
set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setup() override{};
|
||||
void update() override { publish_state(optolink_->get_error()); }
|
||||
|
||||
private:
|
||||
Optolink *optolink_;
|
||||
};
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -3395,11 +3395,6 @@ text_sensor:
|
|||
tag_name: OPTARIF
|
||||
name: optarif
|
||||
teleinfo_id: myteleinfo
|
||||
- platform: optolink
|
||||
name: Error history 1
|
||||
address: 0x7590
|
||||
bytes: 9
|
||||
raw: true
|
||||
- platform: ld2410
|
||||
version:
|
||||
name: "presenece sensor version"
|
||||
|
|
Loading…
Reference in a new issue