DIY gateway integration causes "Failed to serialize to JSON" error

I have a few nodes that use RFM69 radio to transmit the data to a gateway (ESP32 with ethernet). To integrate all this into HA, a custom integration was created.

It works fine, I see the gateway and nodes in HA as expected, but also I see such errors in the logs:

ERROR (MainThread) [homeassistant.helpers.storage] Error writing config for core.config_entries: Failed to serialize to JSON: /config/.storage/core.config_entries. Bad data at $.data.entries[13].data.store.94:3C:C6:3C:27:43_2_rssi=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_2_vcc=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_2_temperature=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_2_humidity=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_2_presssure=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_10_rssi=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_10_vcc=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_10_temperature=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_10_humidity=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>, $.data.entries[13].data.store.94:3C:C6:3C:27:43_10_presssure=(<class ‘custom_components.rfm_gateway.sensor.NodeSensor’>

I suppose it’s due to incorrect usage of hass.data. Each time when the gateway receives a message, it composes the sensor entity and checks whether it already exists in hass.data[DOMAIN][config_entry.entry_id]['store']. If yes, it uses an existing instance to update the value, if no - stores the instance. This approach was borrowed from existing integrations, but I’m not sure it is correct.

Is this normal to store instances in hass.data or should I use a different approach (please suggest one)?

I think the issue is using the mac address in your data key. I dont think you can have colons in a key name. I would remove these and just use the mac address without them.

Edit: sorry missed your code link. The issue is in your unique_id definition on your sensor device. Strip the colons from the gateway_id there.

Thank you for the response, @msp1974.

It was my first guess, that the semicolon in the MAC causes the issue, so I tried to replace it with an underscore, but it changed nothing (the error was the same with id like this 94_3C_C6_3C_27_43_10_rssi).

For now, I switched from storing sensor instances in the hass.data to a global variable and it works (at least I see no issues for now).