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
72.93k stars 30.52k forks source link

MQTT error: "voluptuous.error.MultipleInvalid: expected NumberDeviceClass or one of ..." #83790

Closed homonto closed 1 year ago

homonto commented 1 year ago

The problem

MQTT add on (mosquitto) reports the problem with the device class for the number component, complaining there is no device class assigned. However, according to the MQTT documentation on HA, device class is optional: device_class [device_class](https://www.home-assistant.io/docs/configuration/customizing-devices/#device-class) (optional, default: None)

The error from HA:


2022-12-11 21:47:01.588 ERROR (MainThread) [homeassistant.util.logging] Exception in async_discover when dispatching 'mqtt_discovery_new_number_mqtt': ({'name': 'esp32092_sleep', 'state_topic': 'esp32092/sleep/state', 'command_topic': 'esp32092/sleep/cmd', 'min': 1, 'max': 9999, 'unit_of_measurement': 's', 'qos': '2', 'retain': 'true', 'device_class': 'number', 'unique_id': 'esp32092_sleep', 'entity_category': 'config', 'value_template': '{{value_json.sleeptime}}', 'expire_after': 110, 'force_update': 'true', 'device': {'identifiers': '98:CD:AC:BF:B7:78', 'name': 'ESP32S_esp32092_test', 'model': 'ESP32S', 'manufacturer': 'ZH', 'sw_version': 'ESP32S,72.6.1, 7.29.1, May 26 2022 22:52:14'}, 'platform': 'mqtt'},)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/mixins.py", line 328, in async_discover
    config: DiscoveryInfoType = discovery_schema(discovery_payload)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/validators.py", line 232, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/validators.py", line 355, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/validators.py", line 351, in _exec
    v = func(v)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.10/site-packages/voluptuous/schema_builder.py", line 433, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: expected NumberDeviceClass or one of 'apparent_power', 'aqi', 'battery', 'carbon_monoxide', 'carbon_dioxide', 'current', 'distance', 'energy', 'frequency', 'gas', 'humidity', 'illuminance', 'moisture', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'pm1', 'pm10', 'pm25', 'power_factor', 'power', 'precipitation', 'precipitation_intensity', 'pressure', 'reactive_power', 'signal_strength', 'speed', 'sulphur_dioxide', 'temperature', 'volatile_organic_compounds', 'voltage', 'volume', 'water', 'weight', 'wind_speed' for dictionary value @ data['device_class']

What version of Home Assistant Core has the issue?

2022.12.1

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

No response

Diagnostics information

see above

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

homonto commented 1 year ago

I think that was old, retained message - closing it