sleevezipper / hass-workstation-service

Provide useful sensors and services from your workstation to Home Assistant.
Apache License 2.0
617 stars 53 forks source link

Camera Process + Mic Process sensor payloads exceed HA state limit #195

Open amaisano opened 2 years ago

amaisano commented 2 years ago

We need to refactor them to be an attribute, because HA limits state values to 255 characters and it's preventing us from getting all the apps using the mic. Attributes do not have that limit.

Suggestion:

main state: on/off (if count > 0) processes (attribute): "string,of,processes,like,before"

I have many virtual mics enabled, so the payload looks like this:

C:#Program Files (x86)#Creative#Shared Files#CTAudSvc.exe,C:#Program Files (x86)#VB#Voicemeeter#voicemeeterpro.exe,C:#Program Files#NVIDIA Corporation#NVIDIA Broadcast#NvVirtualCamera#NVIDIA Broadcast.exe

None of the above actually count as me being in a meeting - those items are on all the time.

When I enter a Discord call, the MQTT payload has Discord, but HA never changes state due to the max 255 character error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 661, in _mqtt_handle_message
    self._mqtt_data.state_write_requests.process_write_state_requests()
  File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 251, in process_write_state_requests
    entity.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 647, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1463, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1124, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.bebop_mic_process. State max length is 255 characters.
jordandrako commented 1 year ago

Nvidia broadcast being on all the time was what convinced me to try my hand at creating this sensor and submitting the PR. I'm not well versed in C#, but I'll try to adjust it, or adding the processes to attributes on the original mic sensor.