home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.03k stars 28.27k forks source link

snmp: Sensor Errors of "ValueError: negative count" Since Upgrading to core-2024.4.0 #114789

Closed BigThunderSR closed 1 month ago

BigThunderSR commented 1 month ago

The problem

Getting the following errors since upgrading to core-2024.4.0:

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:951
First occurred: 6:17:45 PM (107 occurrences)
Last logged: 6:35:15 PM

Update for sensor.ups1_output_efficiency fails
Update for sensor.ups2_output_efficiency fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1268, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 218, in async_update
    await self.data.async_update()
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 264, in async_update
    self.value = self._decode_value(resrow[-1])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 273, in _decode_value
    bytes(value),
    ^^^^^^^^^^^^
ValueError: negative count

The value of this sensor can be positive or negative and has never been an issue prior to this.

What version of Home Assistant Core has the issue?

core-2024.4.0

What was the last working version of Home Assistant Core?

core-2024.3.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

SNMP

Link to integration documentation on our website

https://www.home-assistant.io/integrations/snmp/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:951
First occurred: 6:17:45 PM (107 occurrences)
Last logged: 6:35:15 PM

Update for sensor.ups1_output_efficiency fails
Update for sensor.ups2_output_efficiency fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1268, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 218, in async_update
    await self.data.async_update()
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 264, in async_update
    self.value = self._decode_value(resrow[-1])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/snmp/sensor.py", line 273, in _decode_value
    bytes(value),
    ^^^^^^^^^^^^
ValueError: negative count

Additional information

No response

home-assistant[bot] commented 1 month ago

snmp documentation snmp source

BigThunderSR commented 1 month ago

/cc @lextm, possibly another one for you like #114619. Thanks.

lextm commented 1 month ago

We are able to reproduce and resolve this. Will send a pull request soon.

lextm commented 1 month ago

The initial change was made by @ChristianKuehnel a few years ago, and it seems that no need to cast the value to bytes in that log entry (as many input values are not Opaque).

Sent #114795 with a new test case and we are sure it will resolve this issue.

BigThunderSR commented 1 month ago

@lextm , thanks a lot for the quick turnaround!