HASS.Agent
HASS.Agent copied to clipboard
Bug: Audio sessions state length > 255 chars
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:
- Configure Audio Session state sensor
- Play some music. (I personally use Music Bee)
- 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): - 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
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.
Implemented in the latest beta: https://github.com/LAB02-Research/HASS.Agent/releases/tag/2022.13.0-beta2