How to encode device class in MQTT auto discovery config payload

When sending the config for a device to MQTT, if I include a unit of measurment that is UTF-8 encoded it causes the mqtt host to drop the connection with the error:

mqtt                        | 1697055412: New connection from 192.168.1.62:50046 on port 1883.
mqtt                        | 1697055413: New client connected from 192.168.1.62:50046 as enviro_plus (p2, c1, k0, u'ha').
mqtt                        | 1697055413: Client enviro_plus disconnected due to protocol error.

I’ve tried encoding the string using “µg/m³”.encode() but no good.

How do I set the device class properly via MQTT auto-discovery?

I don’t know if this will help, but I use an HA script that publishes auto-discovery MQTT topics for my devices that don’t have auto-discovery. I seem to be able to copy-paste various units of measure symbols directly into the UI and when I publish it, the MQTT Broker/Client works without any problem.

Here are a couple of examples:

"unit_of_measurement": "ft³",
"unit_of_measurement": "°C",

If you simply copy-n-paste the “µg/m³” w/o using the encode(), does that work?

No, that’s where I was getting my units from, the sensors page in the docs, Sensor - Home Assistant

I’d also like to see it as a graph in the history if possible