mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
fix to support negative values for 1-byte datapoints
This commit is contained in:
parent
50821fd22b
commit
0e30e119a0
13 changed files with 84 additions and 21 deletions
|
@ -5,7 +5,6 @@
|
|||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "optolink_number.h"
|
||||
#include "../optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
@ -20,6 +19,30 @@ void OptolinkNumber::control(float value) {
|
|||
}
|
||||
};
|
||||
|
||||
void OptolinkNumber::datapoint_value_changed(uint8_t state) {
|
||||
if (traits.get_min_value() >= 0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((sint8_t) state);
|
||||
}
|
||||
};
|
||||
|
||||
void OptolinkNumber::datapoint_value_changed(uint16_t state) {
|
||||
if (traits.get_min_value() >= 0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((sint16_t) state);
|
||||
}
|
||||
};
|
||||
|
||||
void OptolinkNumber::datapoint_value_changed(uint32_t state) {
|
||||
if (traits.get_min_value() >= 0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((sint32_t) state);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "esphome/components/number/number.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "../optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
#include "../datapoint_component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
@ -21,9 +20,9 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number
|
|||
|
||||
const StringRef &get_component_name() override { return get_name(); }
|
||||
void datapoint_value_changed(float state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint8_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint16_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint32_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint8_t state) override;
|
||||
void datapoint_value_changed(uint16_t state) override;
|
||||
void datapoint_value_changed(uint32_t state) override;
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
#if defined(VITOWIFI_PROTOCOL)
|
||||
// NOLINTNEXTLINE
|
||||
|
@ -40,7 +39,7 @@ void Optolink::setup() {
|
|||
}
|
||||
|
||||
void Optolink::loop() {
|
||||
ESP_LOGD(TAG, "queue size: %d", VitoWiFi.queueSize());
|
||||
// ESP_LOGD(TAG, "queue size: %d", VitoWiFi.queueSize());
|
||||
VitoWiFi.loop();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "optolink_select.h"
|
||||
#include "../optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
#ifdef USE_ARDUINO
|
||||
|
||||
#include <map>
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "../optolink.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "VitoWiFi.h"
|
||||
#include <map>
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -6,6 +6,7 @@ from esphome.const import (
|
|||
CONF_BYTES,
|
||||
CONF_DIV_RATIO,
|
||||
CONF_ID,
|
||||
CONF_MIN_VALUE,
|
||||
)
|
||||
from .. import CONF_OPTOLINK_ID, SENSOR_BASE_SCHEMA, optolink_ns
|
||||
|
||||
|
@ -22,6 +23,7 @@ CONFIG_SCHEMA = (
|
|||
cv.GenerateID(): cv.declare_id(OptolinkSensor),
|
||||
cv.Required(CONF_ADDRESS): cv.hex_uint32_t,
|
||||
cv.Required(CONF_BYTES): cv.one_of(1, 2, 4, int=True),
|
||||
cv.Optional(CONF_MIN_VALUE): cv.float_,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
|
@ -39,3 +41,5 @@ async def to_code(config):
|
|||
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||
cg.add(var.set_bytes(config[CONF_BYTES]))
|
||||
cg.add(var.set_div_ratio(config[CONF_DIV_RATIO]))
|
||||
if CONF_MIN_VALUE in config:
|
||||
cg.add(var.set_min_value(config[CONF_MIN_VALUE]))
|
||||
|
|
40
esphome/components/optolink/sensor/optolink_sensor.cpp
Normal file
40
esphome/components/optolink/sensor/optolink_sensor.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "optolink_sensor.h"
|
||||
#include "../optolink.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
||||
static const char *const TAG = "optolink.sensor";
|
||||
|
||||
void OptolinkSensor::set_min_value(float min_value) { min_value_ = -29.3; }
|
||||
|
||||
void OptolinkSensor::datapoint_value_changed(uint8_t state) {
|
||||
if (min_value_ >= 0.0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((int8_t) state);
|
||||
}
|
||||
};
|
||||
|
||||
void OptolinkSensor::datapoint_value_changed(uint16_t state) {
|
||||
if (min_value_ >= 0.0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((int16_t) state);
|
||||
}
|
||||
}
|
||||
|
||||
void OptolinkSensor::datapoint_value_changed(uint32_t state) {
|
||||
if (min_value_ >= 0.0) {
|
||||
publish_state(state);
|
||||
} else {
|
||||
publish_state((int32_t) state);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "VitoWiFi.h"
|
||||
#include <cfloat>
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
@ -16,15 +16,20 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor
|
|||
set_state_class(esphome::sensor::STATE_CLASS_MEASUREMENT);
|
||||
}
|
||||
|
||||
void set_min_value(float min_value);
|
||||
|
||||
protected:
|
||||
void setup() { setup_datapoint(); }
|
||||
void update() override { datapoint_read_request(); }
|
||||
|
||||
const StringRef &get_component_name() override { return get_name(); }
|
||||
void datapoint_value_changed(float state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint8_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint16_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint32_t state) override { publish_state(state); };
|
||||
void datapoint_value_changed(uint8_t state) override;
|
||||
void datapoint_value_changed(uint16_t state) override;
|
||||
void datapoint_value_changed(uint32_t state) override;
|
||||
|
||||
private:
|
||||
float min_value_ = -FLT_MAX;
|
||||
};
|
||||
} // namespace optolink
|
||||
} // namespace esphome
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "optolink_switch.h"
|
||||
#include "../optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
#ifdef USE_ARDUINO
|
||||
|
||||
#include "esphome/components/switch/switch.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "../optolink.h"
|
||||
#include "VitoWiFi.h"
|
||||
#include "../datapoint_component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "optolink_text_sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "../optolink.h"
|
||||
#include "../datapoint_component.h"
|
||||
#include "VitoWiFi.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace optolink {
|
||||
|
|
Loading…
Reference in a new issue