home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.75k stars 30k forks source link

[MQTT] sensors with "options" errors out if "device_class" not set to "enum" --> Doc says SHOULD #126360

Open MajorTwip opened 4 days ago

MajorTwip commented 4 days ago

The problem

A MQTT-Discovery without "device_class" but "options" gives following Error. Documentation says "should be set to enum".

''' options list (Optional) List of allowed sensor state value. An empty list is not allowed. The sensor’s device_class should be set to enum. Cannot be used together with state_class or unit_of_measurement. '''

May be modified in Doc.

What version of Home Assistant Core has the issue?

core-2024.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

MQTT

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sensor.mqtt/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.mqtt.mixins
Source: components/mqtt/mixins.py:166
integration: MQTT (documentation, issues)
First occurred: 18 September 2024 at 22:41:07 (8 occurrences)
Last logged: 22:00:49

Error 'The option `options` can only be used together with device class `enum`, got `device_class` 'None'' when processing MQTT discovery message topic: 'homeassistant/sensor/4_0_btn_plus_button_scene_kids_tactile/config', message: '{'object_id': '4_0_btn_plus_button_scene_kids_tactile', 'unique_id': '4_0_btn_plus_button_scene_kids_tactile', 'state_topic': 'buttonplus/4_0_btn_plus/button/scene_kids/tactile', 'options': ['click', 'release', 'longpress'], 'icon': 'mdi:electric-switch', 'device': {'identifiers': '4_0_btn_plus.button.scene_kids', 'manufacturer': 'Button+', 'model': 'BAR Module Left Side, Connector: 3, Page: 1, Uid: scene_kids', 'via_device': '4_0_btn_plus', 'name': 'BAR Module Left Side 3L/1'}, 'name': 'Tactile Switch', 'platform': 'mqtt'}'
Error 'The option `options` can only be used together with device class `enum`, got `device_class` 'None'' when processing MQTT discovery message topic: 'homeassistant/sensor/4_0_btn_plus_button_but1_tactile/config', message: '{'object_id': '4_0_btn_plus_button_but1_tactile', 'unique_id': '4_0_btn_plus_button_but1_tactile', 'state_topic': 'buttonplus/4_0_btn_plus/button/but1/tactile', 'options': ['click', 'release', 'longpress'], 'icon': 'mdi:electric-switch', 'device': {'identifiers': '4_0_btn_plus.button.but1', 'manufacturer': 'Button+', 'model': 'BAR Module Right Side, Connector: 3, Page: 1, Uid: but1', 'via_device': '4_0_btn_plus', 'name': 'BAR Module Right Side 3R/1'}, 'name': 'Tactile Switch', 'platform': 'mqtt'}'
Error 'The option `options` can only be used together with device class `enum`, got `device_class` 'None'' when processing MQTT discovery message topic: 'homeassistant/sensor/4_0_btn_plus_button_temp_test_tactile/config', message: '{'object_id': '4_0_btn_plus_button_temp_test_tactile', 'unique_id': '4_0_btn_plus_button_temp_test_tactile', 'state_topic': 'buttonplus/4_0_btn_plus/button/temp_test/tactile', 'options': ['click', 'release', 'longpress'], 'icon': 'mdi:electric-switch', 'device': {'identifiers': '4_0_btn_plus.button.temp_test', 'manufacturer': 'Button+', 'model': 'BAR Module Right Side, Connector: 3, Page: 1, Uid: temp_test', 'via_device': '4_0_btn_plus', 'name': 'BAR Module Right Side 3R/1'}, 'name': 'Tactile Switch', 'platform': 'mqtt'}'
Error 'The option `options` can only be used together with device class `enum`, got `device_class` 'None'' when processing MQTT discovery message topic: 'homeassistant/sensor/4_0_btn_plus_button_temp_test2_tactile/config', message: '{'object_id': '4_0_btn_plus_button_temp_test2_tactile', 'unique_id': '4_0_btn_plus_button_temp_test2_tactile', 'state_topic': 'buttonplus/4_0_btn_plus/button/temp_test2/tactile', 'options': ['click', 'release', 'longpress'], 'icon': 'mdi:electric-switch', 'device': {'identifiers': '4_0_btn_plus.button.temp_test2', 'manufacturer': 'Button+', 'model': 'BAR Module Right Side, Connector: 3, Page: 1, Uid: temp_test2', 'via_device': '4_0_btn_plus', 'name': 'BAR Module Right Side 3R/1'}, 'name': 'Tactile Switch', 'platform': 'mqtt'}'

Additional information

Will raise a bug on button.plus too.

home-assistant[bot] commented 4 days ago

Hey there @emontnemery, @jbouwh, @bdraco, 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!

Code owner commands Code owners of `mqtt` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mqtt` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


mqtt documentation mqtt source (message by IssueLinks)