Prepare MQTT platform tests part6 (#90129)

* Tests lock

* Tests mixins

* Tests number

* Tests scene
This commit is contained in:
Jan Bouwhuis 2023-03-24 08:41:36 +01:00 committed by GitHub
parent a404d5f6d7
commit 0570405a3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 506 additions and 457 deletions

View file

@ -2,28 +2,19 @@
from unittest.mock import patch
import pytest
from homeassistant.components import mqtt, sensor
from homeassistant.const import EVENT_STATE_CHANGED, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.setup import async_setup_component
from tests.common import async_fire_mqtt_message
from tests.typing import MqttMockHAClientGenerator
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_availability_with_shared_state_topic(
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
) -> None:
"""Test the state is not changed twice.
When an entity with a shared state_topic and availability_topic becomes available
The state should only change once.
"""
assert await async_setup_component(
hass,
mqtt.DOMAIN,
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
sensor.DOMAIN: {
@ -36,10 +27,20 @@ async def test_availability_with_shared_state_topic(
"availability_template": "{{ value != '0' }}",
}
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
}
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_availability_with_shared_state_topic(
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
) -> None:
"""Test the state is not changed twice.
When an entity with a shared state_topic and availability_topic becomes available
The state should only change once.
"""
await mqtt_mock_entry_no_yaml_config()
events = []