HASS.Agent icon indicating copy to clipboard operation
HASS.Agent copied to clipboard

Bug: Audio sessions state length > 255 chars

Open tankdeer opened this issue 2 years ago • 1 comments

Describe the bug Audio session state can easily be over 255 characters in length, which is the max allowed by HA

To Reproduce Steps to reproduce the behavior:

  1. Configure Audio Session state sensor
  2. Play some music. (I personally use Music Bee)
  3. Depending on what is playing, you may or may not see errors in the log.

Expected behavior No errors for sure. I would assume the value is just truncated.

Screenshots N/A

Misc info (please complete the following information):

  • Windows build (ideally screenshot/info of winver.exe output): image
  • Windows' UI language: English
  • HASS.Agent version: 2022.11.4

Please check what's applicable (multiple answers possible):

  • [x] Installed via installer
  • [ ] Installed manually
  • [x] Problem occurs in HASS.Agent
  • [ ] Problem occurs in Satellite Service

Additional context HA Logs:

2022-06-10 18:24:12 ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on 'homeassistant/sensor/Pats_Desktop/pats_desktop_audio/pats_desktop_audio_audio_sessions/state': '[
  {
    "Application": "MusicBee",
    "Muted": false,
    "MasterVolume": 34.0,
    "PeakVolume": 78.56528
  },
  {
    "Application": "@%SystemRoot%\\System32\\AudioSr..",
    "Muted": false,
    "MasterVolume": 8.529529,
    "PeakVolume": 37.723503
  }
]'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 47, in wrapper
    msg_callback(msg)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/sensor.py", line 306, in message_received
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 680, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1429, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1097, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.pats_desktop_audio_audio_sessions. State max length is 255 characters.

2022-06-10 18:24:29 ERROR (MainThread) [homeassistant.util.logging] Exception in availability_message_received when handling msg on 'homeassistant/sensor/Pats_Desktop/availability': 'online'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py", line 47, in wrapper
    msg_callback(msg)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 533, in availability_message_received
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 680, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1429, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1097, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.pats_desktop_audio_audio_sessions. State max length is 255 characters.

Logs

2022-06-13 07:10:22.490 -07:00 [INF] [SYSTEMSTATE] Session resuming
2022-06-13 07:10:27.713 -07:00 [INF] [MQTT] Connected
2022-06-13 07:10:33.620 -07:00 [INF] [HASS_API] Server recovered from failed state

tankdeer avatar Jun 13 '22 23:06 tankdeer

Hi @tankdeer, thanks for the extensive bugreport. You're right, and I've planned implementing 'attributes' to circumvent this. That way, all the data gets sent in a seperate topic, on which there is no real max.

[hassagent-72]

LAB02-Admin avatar Jun 14 '22 07:06 LAB02-Admin

Implemented in the latest beta: https://github.com/LAB02-Research/HASS.Agent/releases/tag/2022.13.0-beta2

LAB02-Admin avatar Aug 14 '22 07:08 LAB02-Admin