Cleanup mqtt platform tests part 3 (#120493)

This commit is contained in:
Jan Bouwhuis 2024-06-26 09:29:40 +02:00 committed by GitHub
parent 5a0841155e
commit c5b7d2d868
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 54 deletions

View File

@ -83,10 +83,9 @@ DEFAULT_CONFIG = {
@pytest.mark.parametrize("hass_config", [{mqtt.DOMAIN: {fan.DOMAIN: {"name": "test"}}}]) @pytest.mark.parametrize("hass_config", [{mqtt.DOMAIN: {fan.DOMAIN: {"name": "test"}}}])
@pytest.mark.usefixtures("hass")
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mqtt_mock_entry: MqttMockHAClientGenerator
caplog: pytest.LogCaptureFixture,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test if command fails with command topic.""" """Test if command fails with command topic."""
assert await mqtt_mock_entry() assert await mqtt_mock_entry()
@ -611,8 +610,7 @@ async def test_controlling_state_via_topic_and_json_message_shared_topic(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic( async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic.""" """Test optimistic mode without state topic."""
mqtt_mock = await mqtt_mock_entry() mqtt_mock = await mqtt_mock_entry()
@ -861,9 +859,7 @@ async def test_sending_mqtt_commands_with_alternate_speed_range(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic_no_legacy( async def test_sending_mqtt_commands_and_optimistic_no_legacy(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test optimistic mode without state topic without legacy speed command topic.""" """Test optimistic mode without state topic without legacy speed command topic."""
mqtt_mock = await mqtt_mock_entry() mqtt_mock = await mqtt_mock_entry()
@ -1005,8 +1001,7 @@ async def test_sending_mqtt_commands_and_optimistic_no_legacy(
], ],
) )
async def test_sending_mqtt_command_templates_( async def test_sending_mqtt_command_templates_(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic without legacy speed command topic.""" """Test optimistic mode without state topic without legacy speed command topic."""
mqtt_mock = await mqtt_mock_entry() mqtt_mock = await mqtt_mock_entry()
@ -1166,8 +1161,7 @@ async def test_sending_mqtt_command_templates_(
], ],
) )
async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic( async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode without state topic without percentage command topic.""" """Test optimistic mode without state topic without percentage command topic."""
mqtt_mock = await mqtt_mock_entry() mqtt_mock = await mqtt_mock_entry()
@ -1237,8 +1231,7 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
], ],
) )
async def test_sending_mqtt_commands_and_explicit_optimistic( async def test_sending_mqtt_commands_and_explicit_optimistic(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test optimistic mode with state topic and turn on attributes.""" """Test optimistic mode with state topic and turn on attributes."""
mqtt_mock = await mqtt_mock_entry() mqtt_mock = await mqtt_mock_entry()
@ -1533,9 +1526,7 @@ async def test_encoding_subscribable_topics(
], ],
) )
async def test_attributes( async def test_attributes(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes.""" """Test attributes."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -2215,8 +2206,7 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable( async def test_reloadable(
hass: HomeAssistant, hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient
mqtt_client_mock: MqttMockPahoClient,
) -> None: ) -> None:
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = fan.DOMAIN domain = fan.DOMAIN
@ -2239,8 +2229,7 @@ async def test_setup_manual_entity_from_yaml(
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = fan.DOMAIN domain = fan.DOMAIN

View File

@ -83,17 +83,16 @@ DEFAULT_CONFIG = {
} }
async def async_turn_on( async def async_turn_on(hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL) -> None:
hass: HomeAssistant,
entity_id=ENTITY_MATCH_ALL,
) -> None:
"""Turn all or specified humidifier on.""" """Turn all or specified humidifier on."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data, blocking=True) await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data, blocking=True)
async def async_turn_off(hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL) -> None: async def async_turn_off(
hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL
) -> None:
"""Turn all or specified humidier off.""" """Turn all or specified humidier off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
@ -101,7 +100,7 @@ async def async_turn_off(hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL) -> Non
async def async_set_mode( async def async_set_mode(
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, mode: str | None = None hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL, mode: str | None = None
) -> None: ) -> None:
"""Set mode for all or specified humidifier.""" """Set mode for all or specified humidifier."""
data = { data = {
@ -114,7 +113,7 @@ async def async_set_mode(
async def async_set_humidity( async def async_set_humidity(
hass: HomeAssistant, entity_id=ENTITY_MATCH_ALL, humidity: int | None = None hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL, humidity: int | None = None
) -> None: ) -> None:
"""Set target humidity for all or specified humidifier.""" """Set target humidity for all or specified humidifier."""
data = { data = {
@ -129,10 +128,9 @@ async def async_set_humidity(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hass_config", [{mqtt.DOMAIN: {humidifier.DOMAIN: {"name": "test"}}}] "hass_config", [{mqtt.DOMAIN: {humidifier.DOMAIN: {"name": "test"}}}]
) )
@pytest.mark.usefixtures("hass")
async def test_fail_setup_if_no_command_topic( async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test if command fails with command topic.""" """Test if command fails with command topic."""
assert await mqtt_mock_entry() assert await mqtt_mock_entry()
@ -892,9 +890,7 @@ async def test_encoding_subscribable_topics(
], ],
) )
async def test_attributes( async def test_attributes(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None: ) -> None:
"""Test attributes.""" """Test attributes."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -1048,9 +1044,7 @@ async def test_attributes(
], ],
) )
async def test_validity_configurations( async def test_validity_configurations(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator, valid: bool
mqtt_mock_entry: MqttMockHAClientGenerator,
valid: bool,
) -> None: ) -> None:
"""Test validity of configurations.""" """Test validity of configurations."""
await mqtt_mock_entry() await mqtt_mock_entry()
@ -1499,8 +1493,7 @@ async def test_publishing_with_custom_encoding(
async def test_reloadable( async def test_reloadable(
hass: HomeAssistant, hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient
mqtt_client_mock: MqttMockPahoClient,
) -> None: ) -> None:
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN
@ -1523,8 +1516,7 @@ async def test_setup_manual_entity_from_yaml(
async def test_unload_config_entry( async def test_unload_config_entry(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = humidifier.DOMAIN domain = humidifier.DOMAIN

View File

@ -356,7 +356,6 @@ async def test_image_from_url_content_type(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
content_type: str, content_type: str,
setup_ok: bool, setup_ok: bool,
) -> None: ) -> None:
@ -425,7 +424,6 @@ async def test_image_from_url_fails(
hass: HomeAssistant, hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator, hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
side_effect: Exception, side_effect: Exception,
) -> None: ) -> None:
"""Test setup with minimum configuration.""" """Test setup with minimum configuration."""
@ -501,9 +499,8 @@ async def test_image_from_url_fails(
), ),
], ],
) )
@pytest.mark.usesfixtures("hass", "hass_client_no_auth")
async def test_image_config_fails( async def test_image_config_fails(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
mqtt_mock_entry: MqttMockHAClientGenerator, mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
error_msg: str, error_msg: str,
@ -721,11 +718,7 @@ async def test_entity_id_update_subscriptions(
) -> None: ) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated.""" """Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions( await help_test_entity_id_update_subscriptions(
hass, hass, mqtt_mock_entry, image.DOMAIN, DEFAULT_CONFIG, ["test_topic"]
mqtt_mock_entry,
image.DOMAIN,
DEFAULT_CONFIG,
["test_topic"],
) )
@ -754,8 +747,7 @@ async def test_entity_debug_info_message(
async def test_reloadable( async def test_reloadable(
hass: HomeAssistant, hass: HomeAssistant, mqtt_client_mock: MqttMockPahoClient
mqtt_client_mock: MqttMockPahoClient,
) -> None: ) -> None:
"""Test reloading the MQTT platform.""" """Test reloading the MQTT platform."""
domain = image.DOMAIN domain = image.DOMAIN
@ -774,8 +766,7 @@ async def test_setup_manual_entity_from_yaml(
async def test_unload_entry( async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None: ) -> None:
"""Test unloading the config entry.""" """Test unloading the config entry."""
domain = image.DOMAIN domain = image.DOMAIN