Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT statestream errors - Object of type ServiceEventData is not JSON serializable #639

Open
sjonez opened this issue Feb 28, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@sjonez
Copy link

sjonez commented Feb 28, 2025

With MQTT statestream (https://www.home-assistant.io/integrations/mqtt_statestream/) configured in Home Assistant with all entities and attributes included, the following error gets logged many times with the myskoda integration installed, causing missed MQTT messages:

Logger: homeassistant
Source: helpers/json.py:67
First occurred: 25 February 2025 at 11:06:18 (289 occurrences)
Last logged: 08:22:08

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt_statestream/__init__.py", line 88, in _state_publisher
    encoded_val = json.dumps(val, cls=JSONEncoder)
  File "/usr/local/lib/python3.13/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ~~~~~~^^^^^
  File "/usr/local/lib/python3.13/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.13/json/encoder.py", line 261, in iterencode
    return _iterencode(o, 0)
  File "/usr/src/homeassistant/homeassistant/helpers/json.py", line 67, in default
    return json.JSONEncoder.default(self, o)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/local/lib/python3.13/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
                    f'is not JSON serializable')
TypeError: Object of type ServiceEventData is not JSON serializable

I've narrowed the issue down to the data and history attributes on the last_service_event entity, which I assume makes use of this ServiceEventData type. I've excluded that item from statestream for now, but is it possible to make it JSON serializable to prevent this from happening?

@sjonez sjonez added the bug Something isn't working label Feb 28, 2025
@WebSpider
Copy link
Contributor

The MQTT integration is a prerequisite for MQTT Statestream to work.

We dont use the mqtt integration, we use MQTT as a method to receive our own push messages from MySkoda, but we do not use the HA MQTT integration.

Unless I offcourse misunderstand the problem

@sjonez
Copy link
Author

sjonez commented Mar 1, 2025

Yes this has nothing to do with myskoda using MQTT.

Statestream is a core HA integration that mirrors changes to entities and attributes over MQTT. One of the entities that myskoda creates breaks this integration because the data it stores is not serializable. I first raised this issue with statestream but was then asked to raise it here as this problem has not been seen with any other entity across many integrations.

@dvx76
Copy link
Member

dvx76 commented Mar 2, 2025

Right, so this would be because the service_event entity returns the actual ServiceEventData objects in extra attributes (ServiceEvent.extra_state_attributes()). Likely the same issue with the last_operation entity.

Options:

@WebSpider WebSpider added enhancement New feature or request and removed bug Something isn't working labels Mar 2, 2025
@WebSpider
Copy link
Contributor

Yes this has nothing to do with myskoda using MQTT.

Statestream is a core HA integration that mirrors changes to entities and attributes over MQTT. One of the entities that myskoda creates breaks this integration because the data it stores is not serializable.

We will treats this as an enhancement request, not as a bug, since we aim to be compliant with HA, not all it's components, we're simply too young for that.

Thanks for the additional information👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants