Modbus controller text sensor has a response_size attribute, but it seems to be unused. With response_size set to 2 and raw_encode to HEXBYTES, I expect a four character string, but I receive 8 characters, such as "00000000". If appreciated, I don't mind to create a pull request to fix this; see proposed change below.
[09:01:59][D][text_sensor:064]: 'Omnia current HVAC mode': Sending state '00000000'
Additional information
Looking at the source code, it seems that the value for response_size is never used. The relevant snippet seems to be this:
uint8_t max_items = this->response_bytes;
uint8_t index = this->offset;
char buffer[4];
while ((max_items != 0) && index < data.size()) {
uint8_t b = data[index];
switch (this->encode_) {
case RawEncoding::HEXBYTES:
sprintf(buffer, "%02x", b);
output << buffer;
break;
case RawEncoding::COMMA:
sprintf(buffer, index != this->offset ? ",%d" : "%d", b);
output << buffer;
break;
// Anything else no encoding
case RawEncoding::NONE:
default:
output << (char) b;
break;
}
index++;
}
I expect the value max_items to be decreased, but in fact it never changes. If this is correct, I don't mind to create a pull request, to add a max_items--; at the end of the loop.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
The problem
Modbus controller text sensor has a
response_size
attribute, but it seems to be unused. Withresponse_size
set to2
andraw_encode
toHEXBYTES
, I expect a four character string, but I receive 8 characters, such as "00000000". If appreciated, I don't mind to create a pull request to fix this; see proposed change below.Which version of ESPHome has the issue?
2023.12.9
What type of installation are you using?
Home Assistant Add-on
Which version of Home Assistant has the issue?
2024.1.6
What platform are you using?
ESP32
Board
esp-wrover-kit
Component causing the issue
modbus controller
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
Looking at the source code, it seems that the value for
response_size
is never used. The relevant snippet seems to be this:I expect the value
max_items
to be decreased, but in fact it never changes. If this is correct, I don't mind to create a pull request, to add amax_items--;
at the end of the loop.