Closed jerome-labidurie closed 1 year ago
Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (sensor
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
sensor documentation sensor source (message by IssueLinks)
Hey there @emontnemery, @jbouwh, mind taking a look at this issue as it has been labeled with an integration (mqtt
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
mqtt documentation mqtt source (message by IssueLinks)
"None"
is not a valid device class. Just leave the device_class
config setting away if it is not meant to be set.
@emontnemery Should we add None
to the MQTT device_class
validation so that it allows a JSON null
assignment?
None
as device_class. Through discovery and in YAML you should use null
in stead of "None"
, because else it will be treated a string, and "None"
is not a valid device_class
.Wow, that was a quick fix !
I've just done some tests on the merged branch (BTW, very nice developer doc&tooling :star_struck:)
And everything works ok for me. either by sending the discovery json
mosquitto_pub -r -h 192.168.1.20 -p 1883 -t "homeassistant/sensor/GenericSensor/config" -m '{"name": "Generic Sensor", "state_topic": "homeassistant/sensor/GenericSensor/state", "availability_topic": "homeassistant/sensor/GenericSensor/available", "unique_id": "GenericSensor", "device_class": null, "unit_of_measurement": ""}'
Or via python
client.publish("homeassistant/sensor/GenericSensor/config", json.dumps({"name": "Generic Sensor", "state_topic": "homeassistant/sensor/GenericSensor/state", "availability_topic": "homeassistant/sensor/GenericSensor/available", "unique_id": "GenericSensor", "device_class":None}),retain=True)
Thank you very much for the fix and the speed ;)
Best regards
The problem
Hello,
I'm trying to create a generic sensor via mqtt. In the documentation (mqtt & sensor), it's stated that the
device_class: None
is the way (but can be omitted).However, if I try to create a sensor with
device_class
set toNone
,the sensor is not created and I have an error in the logs :
In the other end, if I just remove the optional
None
device classthe sensor is created![image](https://user-images.githubusercontent.com/3443155/210430335-c49ce696-2ba8-409d-82de-90e60a260998.png)
In my opinion, if the device_class can be set to
None
, the validation should not fail. If it's not allowed, the documentation should be corrected. Maybe something like :I'm not sure which one is he solution.
Best regards
PS: for the record, I ran into this issue by using the mqtt-binding python lib, and also created an issue there
What version of Home Assistant Core has the issue?
2022.12.7
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
mqtt
Link to integration documentation on our website
https://www.home-assistant.io/integrations/mqtt
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Additional information
No response