mirror of
https://github.com/esphome/esphome.git
synced 2025-02-07 00:11:59 +01:00
fixed issue with div_ratio=100
This commit is contained in:
parent
5496238831
commit
73b7090a7b
@ -2,9 +2,6 @@
|
||||
|
||||
#include "datapoint_component.h"
|
||||
#include "optolink.h"
|
||||
#ifdef USE_API
|
||||
#include "esphome/components/api/api_server.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
@ -139,12 +136,13 @@ void DatapointComponent::datapoint_read_request_() {
|
||||
} else {
|
||||
if (!optolink_->communication_suspended()) {
|
||||
if ((read_retries_ == 0 || read_retries_ >= max_retries_until_reset_) || get_update_interval() > 10000) {
|
||||
if (optolink_->read_value(datapoint_)) {
|
||||
if (optolink_->read_datapoint(datapoint_)) {
|
||||
read_retries_ = 1;
|
||||
}
|
||||
} else {
|
||||
read_retries_++;
|
||||
ESP_LOGW(TAG, "%d. read request for %s rejected due to outstanding running request - increase update_interval!",
|
||||
ESP_LOGW(TAG,
|
||||
"%d. read request for %s rejected due to outstanding running request - check datapoint configuration!",
|
||||
read_retries_, get_component_name().c_str());
|
||||
}
|
||||
} else {
|
||||
@ -188,7 +186,7 @@ void DatapointComponent::datapoint_write_request_(DPValue dp_value) {
|
||||
#endif
|
||||
|
||||
dp_value_outstanding_ = dp_value;
|
||||
if (optolink_->write_value(datapoint_, dp_value_outstanding_)) {
|
||||
if (optolink_->write_datapoint(datapoint_, dp_value_outstanding_)) {
|
||||
is_dp_value_writing_outstanding_ = false;
|
||||
} else {
|
||||
ESP_LOGW(TAG, "write request for %s rejected due to outstanding running request - increase update_interval!",
|
||||
|
@ -69,7 +69,7 @@ class conv2_100_F : public DPType {
|
||||
public:
|
||||
void encode(uint8_t *out, DPValue in);
|
||||
DPValue decode(const uint8_t *in);
|
||||
virtual const size_t get_length() const { return 2; }
|
||||
virtual const size_t getLength() const { return 2; }
|
||||
};
|
||||
|
||||
class conv4_1000_F : public DPType {
|
||||
|
@ -65,7 +65,9 @@ void Optolink::communication_check_() {
|
||||
ESP_LOGI(TAG, "timestamp rollover");
|
||||
timestamp_send_ = 0;
|
||||
timestamp_receive_ = 0;
|
||||
} else if (timestamp_send_ > 0 && (timestamp_loop_ - timestamp_receive_) > COMMUNICATION_CHECK_WINDOW) {
|
||||
} else if (timestamp_send_ == 0 || timestamp_receive_ == 0) {
|
||||
// too less data to analyze communication statistics
|
||||
} else if ((timestamp_loop_ - timestamp_receive_) > COMMUNICATION_CHECK_WINDOW) {
|
||||
// last response older than 10 sec - check if there was no request in same time window except last two seconds
|
||||
if (timestamp_send_ > timestamp_loop_ - MAX_RESPONSE_DELAY) {
|
||||
// request too fresh -> possiblly still waiting for response
|
||||
@ -98,14 +100,13 @@ void Optolink::resume_communication_() {
|
||||
|
||||
bool Optolink::communication_suspended() { return (timestamp_disruption_ != 0); }
|
||||
|
||||
bool Optolink::read_value(IDatapoint *datapoint) {
|
||||
bool Optolink::read_datapoint(IDatapoint *datapoint) {
|
||||
if (datapoint != nullptr && !communication_suspended()) {
|
||||
ESP_LOGI(TAG, "requesting value of datapoint %s", datapoint->getName());
|
||||
ESP_LOGI(TAG, "requesting value (%d bytes) from datapoint %s", datapoint->getLength(), datapoint->getName());
|
||||
if (VitoWiFi.readDatapoint(*datapoint)) {
|
||||
notify_send();
|
||||
} else {
|
||||
ESP_LOGE(TAG, "read request rejected due to queue overload - queue size: %d", VitoWiFi.queueSize());
|
||||
suspend_communication_();
|
||||
for (auto *dp : IDatapoint::getCollection()) {
|
||||
ESP_LOGD(TAG, "queued datapoint: %s", dp->getName());
|
||||
}
|
||||
@ -115,11 +116,11 @@ bool Optolink::read_value(IDatapoint *datapoint) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Optolink::write_value(IDatapoint *datapoint, DPValue dp_value) {
|
||||
bool Optolink::write_datapoint(IDatapoint *datapoint, DPValue dp_value) {
|
||||
if (datapoint != nullptr && !communication_suspended()) {
|
||||
char buffer[64];
|
||||
dp_value.getString(buffer, sizeof(buffer));
|
||||
ESP_LOGI(TAG, "sending value %s of datapoint %s", buffer, datapoint->getName());
|
||||
ESP_LOGI(TAG, "sending value %s (%d bytes) to datapoint %s", buffer, datapoint->getLength(), datapoint->getName());
|
||||
if (VitoWiFi.writeDatapoint(*datapoint, dp_value)) {
|
||||
notify_send();
|
||||
} else {
|
||||
|
@ -36,8 +36,8 @@ 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; }
|
||||
|
||||
bool write_value(IDatapoint *datapoint, DPValue dp_value);
|
||||
bool read_value(IDatapoint *datapoint);
|
||||
bool write_datapoint(IDatapoint *datapoint, DPValue dp_value);
|
||||
bool read_datapoint(IDatapoint *datapoint);
|
||||
|
||||
std::string get_state() { return state_; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user