Remove work-a-round for mqtt sensors with an entity_category set to config (#107199)

* Remove work-a-round for mqtt sensors with an entity_category set to `config`

* Cleanup strings
This commit is contained in:
Jan Bouwhuis
2024-01-05 09:24:52 +01:00
committed by GitHub
parent 4a2958baeb
commit c7b6c9da31
5 changed files with 4 additions and 175 deletions

View File

@@ -31,12 +31,7 @@ from homeassistant.const import (
import homeassistant.core as ha
from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import (
device_registry as dr,
entity_registry as er,
issue_registry as ir,
template,
)
from homeassistant.helpers import device_registry as dr, entity_registry as er, template
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import async_get_platforms
from homeassistant.helpers.typing import ConfigType
@@ -49,7 +44,6 @@ from .test_common import help_all_subscribe_calls
from tests.common import (
MockConfigEntry,
MockEntity,
async_capture_events,
async_fire_mqtt_message,
async_fire_time_changed,
mock_restore_cache,
@@ -2159,98 +2153,6 @@ async def test_setup_manual_mqtt_with_invalid_config(
assert "required key not provided" in caplog.text
@pytest.mark.parametrize(
("hass_config", "entity_id"),
[
(
{
mqtt.DOMAIN: {
"sensor": {
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
}
}
},
"sensor.test",
),
(
{
mqtt.DOMAIN: {
"binary_sensor": {
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
}
}
},
"binary_sensor.test",
),
],
)
@patch(
"homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR, Platform.SENSOR]
)
async def test_setup_manual_mqtt_with_invalid_entity_category(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
entity_id: str,
) -> None:
"""Test set up a manual sensor item with an invalid entity category."""
events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED)
assert await mqtt_mock_entry()
assert "Entity category `config` is invalid for sensors, ignoring" in caplog.text
state = hass.states.get(entity_id)
assert state is not None
assert len(events) == 1
@pytest.mark.parametrize(
("config", "entity_id"),
[
(
{
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
},
"binary_sensor.test",
),
(
{
"name": "test",
"state_topic": "test-topic",
"entity_category": "config",
},
"sensor.test",
),
],
)
@patch(
"homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR, Platform.SENSOR]
)
async def test_setup_discovery_mqtt_with_invalid_entity_category(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
config: dict[str, Any],
entity_id: str,
) -> None:
"""Test set up a discovered sensor item with an invalid entity category."""
events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED)
assert await mqtt_mock_entry()
domain = entity_id.split(".")[0]
json_config = json.dumps(config)
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", json_config)
await hass.async_block_till_done()
assert "Entity category `config` is invalid for sensors, ignoring" in caplog.text
state = hass.states.get(entity_id)
assert state is not None
assert len(events) == 0
@patch("homeassistant.components.mqtt.PLATFORMS", [])
@pytest.mark.parametrize(
("mqtt_config_entry_data", "protocol"),