diff --git a/homeassistant/components/mqtt/binary_sensor.py b/homeassistant/components/mqtt/binary_sensor.py index 7608fc5816c..9143b804c60 100644 --- a/homeassistant/components/mqtt/binary_sensor.py +++ b/homeassistant/components/mqtt/binary_sensor.py @@ -42,6 +42,7 @@ from .mixins import ( MqttAvailability, MqttEntity, async_setup_entity_entry_helper, + validate_sensor_entity_category, write_state_on_attr_change, ) from .models import MqttValueTemplate, ReceiveMessage @@ -68,10 +69,12 @@ _PLATFORM_SCHEMA_BASE = MQTT_RO_SCHEMA.extend( ).extend(MQTT_ENTITY_COMMON_SCHEMA.schema) DISCOVERY_SCHEMA = vol.All( + validate_sensor_entity_category(binary_sensor.DOMAIN, discovery=True), _PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA), ) PLATFORM_SCHEMA_MODERN = vol.All( + validate_sensor_entity_category(binary_sensor.DOMAIN, discovery=False), _PLATFORM_SCHEMA_BASE, ) diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 52c35d380f9..5bb86662322 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -2172,6 +2172,18 @@ async def test_setup_manual_mqtt_with_invalid_config( }, "sensor.test", ), + ( + { + mqtt.DOMAIN: { + "binary_sensor": { + "name": "test", + "state_topic": "test-topic", + "entity_category": "config", + } + } + }, + "binary_sensor.test", + ), ], ) @patch( @@ -2195,6 +2207,14 @@ async def test_setup_manual_mqtt_with_invalid_entity_category( @pytest.mark.parametrize( ("config", "entity_id"), [ + ( + { + "name": "test", + "state_topic": "test-topic", + "entity_category": "config", + }, + "binary_sensor.test", + ), ( { "name": "test",