Improve test coverage mqtt vacuum (#96288)

This commit is contained in:
Jan Bouwhuis 2023-07-11 10:16:00 +02:00 committed by GitHub
parent beff19f93c
commit f3e55e96f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 1 deletions

View File

@ -321,6 +321,41 @@ async def test_commands_without_supported_features(
mqtt_mock.async_publish.reset_mock()
@pytest.mark.parametrize(
"hass_config",
[
{
"mqtt": {
"vacuum": {
"name": "test",
"schema": "legacy",
mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings(
ALL_SERVICES, SERVICE_TO_STRING
),
}
}
}
],
)
async def test_command_without_command_topic(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test commands which are not supported by the vacuum."""
mqtt_mock = await mqtt_mock_entry()
await common.async_turn_on(hass, "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
await common.async_set_fan_speed(hass, "low", "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
await common.async_send_command(hass, "some command", "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
@pytest.mark.parametrize(
"hass_config",
[

View File

@ -11,7 +11,10 @@ from homeassistant.components.mqtt.const import CONF_COMMAND_TOPIC, CONF_STATE_T
from homeassistant.components.mqtt.vacuum import CONF_SCHEMA, schema_state as mqttvacuum
from homeassistant.components.mqtt.vacuum.const import MQTT_VACUUM_ATTRIBUTES_BLOCKED
from homeassistant.components.mqtt.vacuum.schema import services_to_strings
from homeassistant.components.mqtt.vacuum.schema_state import SERVICE_TO_STRING
from homeassistant.components.mqtt.vacuum.schema_state import (
ALL_SERVICES,
SERVICE_TO_STRING,
)
from homeassistant.components.vacuum import (
ATTR_BATTERY_ICON,
ATTR_BATTERY_LEVEL,
@ -255,6 +258,41 @@ async def test_commands_without_supported_features(
mqtt_mock.async_publish.assert_not_called()
@pytest.mark.parametrize(
"hass_config",
[
{
"mqtt": {
"vacuum": {
"name": "test",
"schema": "state",
mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings(
ALL_SERVICES, SERVICE_TO_STRING
),
}
}
}
],
)
async def test_command_without_command_topic(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test commands which are not supported by the vacuum."""
mqtt_mock = await mqtt_mock_entry()
await common.async_start(hass, "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
await common.async_set_fan_speed(hass, "low", "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
await common.async_send_command(hass, "some command", "vacuum.test")
mqtt_mock.async_publish.assert_not_called()
mqtt_mock.async_publish.reset_mock()
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
async def test_status(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator