Fix entity category for binary_sensor fails setup (#103511)

This commit is contained in:
Jan Bouwhuis 2023-11-08 14:10:24 +01:00 committed by GitHub
parent 5bb3c7ca55
commit db97e7588b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -42,6 +42,7 @@ from .mixins import (
MqttAvailability, MqttAvailability,
MqttEntity, MqttEntity,
async_setup_entity_entry_helper, async_setup_entity_entry_helper,
validate_sensor_entity_category,
write_state_on_attr_change, write_state_on_attr_change,
) )
from .models import MqttValueTemplate, ReceiveMessage from .models import MqttValueTemplate, ReceiveMessage
@ -68,10 +69,12 @@ _PLATFORM_SCHEMA_BASE = MQTT_RO_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema) ).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
DISCOVERY_SCHEMA = vol.All( DISCOVERY_SCHEMA = vol.All(
validate_sensor_entity_category(binary_sensor.DOMAIN, discovery=True),
_PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA), _PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA),
) )
PLATFORM_SCHEMA_MODERN = vol.All( PLATFORM_SCHEMA_MODERN = vol.All(
validate_sensor_entity_category(binary_sensor.DOMAIN, discovery=False),
_PLATFORM_SCHEMA_BASE, _PLATFORM_SCHEMA_BASE,
) )

View File

@ -2172,6 +2172,18 @@ async def test_setup_manual_mqtt_with_invalid_config(
}, },
"sensor.test", "sensor.test",
), ),
(
{
mqtt.DOMAIN: {
"binary_sensor": {
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
}
}
},
"binary_sensor.test",
),
], ],
) )
@patch( @patch(
@ -2195,6 +2207,14 @@ async def test_setup_manual_mqtt_with_invalid_entity_category(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "entity_id"), ("config", "entity_id"),
[ [
(
{
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
},
"binary_sensor.test",
),
( (
{ {
"name": "test", "name": "test",