mirror of
https://github.com/esphome/esphome.git
synced 2024-11-12 18:27:46 +01:00
[modbus_text_sensor] new default ANSI encoding type (#6975)
This commit is contained in:
parent
decf50ed49
commit
9a26cdb336
3 changed files with 7 additions and 3 deletions
|
@ -37,6 +37,7 @@ RAW_ENCODING = {
|
||||||
"NONE": RawEncoding.NONE,
|
"NONE": RawEncoding.NONE,
|
||||||
"HEXBYTES": RawEncoding.HEXBYTES,
|
"HEXBYTES": RawEncoding.HEXBYTES,
|
||||||
"COMMA": RawEncoding.COMMA,
|
"COMMA": RawEncoding.COMMA,
|
||||||
|
"ANSI": RawEncoding.ANSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
|
@ -49,7 +50,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Optional(CONF_REGISTER_TYPE): cv.enum(MODBUS_REGISTER_TYPE),
|
cv.Optional(CONF_REGISTER_TYPE): cv.enum(MODBUS_REGISTER_TYPE),
|
||||||
cv.Optional(CONF_REGISTER_COUNT, default=0): cv.positive_int,
|
cv.Optional(CONF_REGISTER_COUNT, default=0): cv.positive_int,
|
||||||
cv.Optional(CONF_RESPONSE_SIZE, default=2): cv.positive_int,
|
cv.Optional(CONF_RESPONSE_SIZE, default=2): cv.positive_int,
|
||||||
cv.Optional(CONF_RAW_ENCODE, default="NONE"): cv.enum(RAW_ENCODING),
|
cv.Optional(CONF_RAW_ENCODE, default="ANSI"): cv.enum(RAW_ENCODING),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
validate_modbus_register,
|
validate_modbus_register,
|
||||||
|
|
|
@ -27,8 +27,11 @@ void ModbusTextSensor::parse_and_publish(const std::vector<uint8_t> &data) {
|
||||||
sprintf(buffer, index != this->offset ? ",%d" : "%d", b);
|
sprintf(buffer, index != this->offset ? ",%d" : "%d", b);
|
||||||
output << buffer;
|
output << buffer;
|
||||||
break;
|
break;
|
||||||
|
case RawEncoding::ANSI:
|
||||||
|
if (b < 0x20)
|
||||||
|
break;
|
||||||
|
// FALLTHROUGH
|
||||||
// Anything else no encoding
|
// Anything else no encoding
|
||||||
case RawEncoding::NONE:
|
|
||||||
default:
|
default:
|
||||||
output << (char) b;
|
output << (char) b;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace modbus_controller {
|
namespace modbus_controller {
|
||||||
|
|
||||||
enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2 };
|
enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2, ANSI = 3 };
|
||||||
|
|
||||||
class ModbusTextSensor : public Component, public text_sensor::TextSensor, public SensorItem {
|
class ModbusTextSensor : public Component, public text_sensor::TextSensor, public SensorItem {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue