Add type hints to integration tests (part 22) (#88234)
This commit is contained in:
parent
567c7f4f99
commit
88cfbf6a34
50 changed files with 1269 additions and 559 deletions
|
@ -10,6 +10,7 @@ from hatasmota.utils import (
|
|||
get_topic_tele_sensor,
|
||||
get_topic_tele_will,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import (
|
||||
|
@ -21,6 +22,7 @@ from homeassistant.const import (
|
|||
Platform,
|
||||
)
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .test_common import (
|
||||
|
@ -37,9 +39,12 @@ from .test_common import (
|
|||
)
|
||||
|
||||
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -104,7 +109,9 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert entity.force_update
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_switchname(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_switchname(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -164,7 +171,9 @@ async def test_controlling_state_via_mqtt_switchname(hass, mqtt_mock, setup_tasm
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_pushon_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_pushon_controlling_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 13
|
||||
|
@ -213,7 +222,9 @@ async def test_pushon_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota)
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_friendly_names(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_friendly_names(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -237,7 +248,9 @@ async def test_friendly_names(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("friendly_name") == "Beer"
|
||||
|
||||
|
||||
async def test_off_delay(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_off_delay(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test off_delay option."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 13 # PUSHON: 1s off_delay
|
||||
|
@ -286,8 +299,11 @@ async def test_off_delay(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -297,7 +313,9 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -305,7 +323,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
|
|||
await help_test_availability(hass, mqtt_mock, Platform.BINARY_SENSOR, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -316,8 +336,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -334,7 +357,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_binary_sensor(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered binary_sensor."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config2 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -349,8 +377,11 @@ async def test_discovery_removal_binary_sensor(hass, mqtt_mock, caplog, setup_ta
|
|||
|
||||
|
||||
async def test_discovery_update_unchanged_binary_sensor(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered binary_sensor."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -363,7 +394,9 @@ async def test_discovery_update_unchanged_binary_sensor(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -373,7 +406,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
@ -389,7 +424,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 1
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
"""Test config flow."""
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.service_info.mqtt import MqttServiceInfo
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.typing import MqttMockHAClient
|
||||
|
||||
|
||||
async def test_mqtt_abort_if_existing_entry(hass, mqtt_mock):
|
||||
async def test_mqtt_abort_if_existing_entry(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Check MQTT flow aborts when an entry already exist."""
|
||||
MockConfigEntry(domain="tasmota").add_to_hass(hass)
|
||||
|
||||
|
@ -17,7 +21,9 @@ async def test_mqtt_abort_if_existing_entry(hass, mqtt_mock):
|
|||
assert result["reason"] == "single_instance_allowed"
|
||||
|
||||
|
||||
async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
||||
async def test_mqtt_abort_invalid_topic(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Check MQTT flow aborts if discovery topic is invalid."""
|
||||
discovery_info = MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/bla",
|
||||
|
@ -79,7 +85,7 @@ async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
|||
assert result["type"] == "form"
|
||||
|
||||
|
||||
async def test_mqtt_setup(hass, mqtt_mock) -> None:
|
||||
async def test_mqtt_setup(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
|
||||
"""Test we can finish a config flow through MQTT with custom prefix."""
|
||||
discovery_info = MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/config",
|
||||
|
@ -109,7 +115,7 @@ async def test_mqtt_setup(hass, mqtt_mock) -> None:
|
|||
assert result["result"].data == {"discovery_prefix": "tasmota/discovery"}
|
||||
|
||||
|
||||
async def test_user_setup(hass, mqtt_mock):
|
||||
async def test_user_setup(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota", context={"source": config_entries.SOURCE_USER}
|
||||
|
@ -124,7 +130,9 @@ async def test_user_setup(hass, mqtt_mock):
|
|||
}
|
||||
|
||||
|
||||
async def test_user_setup_advanced(hass, mqtt_mock):
|
||||
async def test_user_setup_advanced(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota",
|
||||
|
@ -142,7 +150,9 @@ async def test_user_setup_advanced(hass, mqtt_mock):
|
|||
}
|
||||
|
||||
|
||||
async def test_user_setup_advanced_strip_wildcard(hass, mqtt_mock):
|
||||
async def test_user_setup_advanced_strip_wildcard(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota",
|
||||
|
@ -160,7 +170,9 @@ async def test_user_setup_advanced_strip_wildcard(hass, mqtt_mock):
|
|||
}
|
||||
|
||||
|
||||
async def test_user_setup_invalid_topic_prefix(hass, mqtt_mock):
|
||||
async def test_user_setup_invalid_topic_prefix(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Test abort on invalid discovery topic."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota",
|
||||
|
@ -176,7 +188,9 @@ async def test_user_setup_invalid_topic_prefix(hass, mqtt_mock):
|
|||
assert result["errors"]["base"] == "invalid_discovery_topic"
|
||||
|
||||
|
||||
async def test_user_single_instance(hass, mqtt_mock):
|
||||
async def test_user_single_instance(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient
|
||||
) -> None:
|
||||
"""Test we only allow a single config flow."""
|
||||
MockConfigEntry(domain="tasmota").add_to_hass(hass)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import pytest
|
|||
from homeassistant.components import cover
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import (
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -29,6 +30,7 @@ from .test_common import (
|
|||
)
|
||||
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
COVER_SUPPORT = (
|
||||
cover.SUPPORT_OPEN
|
||||
|
@ -44,7 +46,9 @@ TILT_SUPPORT = (
|
|||
)
|
||||
|
||||
|
||||
async def test_missing_relay(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_missing_relay(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test no cover is discovered if relays are missing."""
|
||||
|
||||
|
||||
|
@ -58,8 +62,12 @@ async def test_missing_relay(hass, mqtt_mock, setup_tasmota):
|
|||
],
|
||||
)
|
||||
async def test_multiple_covers(
|
||||
hass, mqtt_mock, setup_tasmota, relay_config, num_covers
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
relay_config,
|
||||
num_covers,
|
||||
) -> None:
|
||||
"""Test discovery of multiple covers."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"] = relay_config
|
||||
|
@ -77,7 +85,9 @@ async def test_multiple_covers(
|
|||
assert len(hass.states.async_all("cover")) == num_covers
|
||||
|
||||
|
||||
async def test_tilt_support(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_tilt_support(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test tilt support detection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"] = [3, 3, 3, 3, 3, 3, 3, 3]
|
||||
|
@ -111,7 +121,9 @@ async def test_tilt_support(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes["supported_features"] == COVER_SUPPORT
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_tilt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_tilt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 3
|
||||
|
@ -283,8 +295,8 @@ async def test_controlling_state_via_mqtt_tilt(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
@pytest.mark.parametrize("tilt", ("", ',"Tilt":0'))
|
||||
async def test_controlling_state_via_mqtt_inverted(
|
||||
hass, mqtt_mock, setup_tasmota, tilt
|
||||
):
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota, tilt
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 3
|
||||
|
@ -458,7 +470,9 @@ async def call_service(hass, entity_id, service, **kwargs):
|
|||
)
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -561,7 +575,9 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_inverted(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_inverted(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -626,8 +642,11 @@ async def test_sending_mqtt_commands_inverted(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -643,7 +662,9 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -654,7 +675,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -666,8 +689,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 3
|
||||
|
@ -678,7 +704,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_cover(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_cover(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered cover."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["dn"] = "Test"
|
||||
|
@ -701,7 +732,12 @@ async def test_discovery_removal_cover(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_cover(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_update_unchanged_cover(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered cover."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -722,7 +758,9 @@ async def test_discovery_update_unchanged_cover(hass, mqtt_mock, caplog, setup_t
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -734,7 +772,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -751,7 +791,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
|
|
@ -10,6 +10,7 @@ import homeassistant.components.automation as automation
|
|||
from homeassistant.components.device_automation import DeviceAutomationType
|
||||
from homeassistant.components.tasmota import _LOGGER
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.trigger import async_initialize_triggers
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -22,9 +23,16 @@ from tests.common import (
|
|||
async_get_device_automations,
|
||||
)
|
||||
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
|
||||
from tests.typing import MqttMockHAClient, WebSocketGenerator
|
||||
|
||||
|
||||
async def test_get_triggers_btn(hass, device_reg, entity_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_get_triggers_btn(
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a discovered mqtt device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["btn"][0] = 1
|
||||
|
@ -65,7 +73,13 @@ async def test_get_triggers_btn(hass, device_reg, entity_reg, mqtt_mock, setup_t
|
|||
assert_lists_same(triggers, expected_triggers)
|
||||
|
||||
|
||||
async def test_get_triggers_swc(hass, device_reg, entity_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_get_triggers_swc(
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a discovered mqtt device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 0
|
||||
|
@ -95,8 +109,12 @@ async def test_get_triggers_swc(hass, device_reg, entity_reg, mqtt_mock, setup_t
|
|||
|
||||
|
||||
async def test_get_unknown_triggers(
|
||||
hass, device_reg, entity_reg, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test we don't get unknown triggers."""
|
||||
# Discover a device without device triggers
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -140,8 +158,12 @@ async def test_get_unknown_triggers(
|
|||
|
||||
|
||||
async def test_get_non_existing_triggers(
|
||||
hass, device_reg, entity_reg, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test getting non existing triggers."""
|
||||
# Discover a device without device triggers
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -162,8 +184,12 @@ async def test_get_non_existing_triggers(
|
|||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discover_bad_triggers(
|
||||
hass, device_reg, entity_reg, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test exception handling when discovering trigger."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["swc"][0] = 0
|
||||
|
@ -245,8 +271,12 @@ async def test_discover_bad_triggers(
|
|||
|
||||
|
||||
async def test_update_remove_triggers(
|
||||
hass, device_reg, entity_reg, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test triggers can be updated and removed."""
|
||||
# Discover a device with toggle + hold trigger
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -318,8 +348,8 @@ async def test_update_remove_triggers(
|
|||
|
||||
|
||||
async def test_if_fires_on_mqtt_message_btn(
|
||||
hass, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, device_reg, calls, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test button triggers firing."""
|
||||
# Discover a device with 2 device triggers
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -389,8 +419,8 @@ async def test_if_fires_on_mqtt_message_btn(
|
|||
|
||||
|
||||
async def test_if_fires_on_mqtt_message_swc(
|
||||
hass, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, device_reg, calls, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test switch triggers firing."""
|
||||
# Discover a device with 2 device triggers
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -483,8 +513,8 @@ async def test_if_fires_on_mqtt_message_swc(
|
|||
|
||||
|
||||
async def test_if_fires_on_mqtt_message_late_discover(
|
||||
hass, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, device_reg, calls, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test triggers firing of MQTT device triggers discovered after setup."""
|
||||
# Discover a device without device triggers
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -562,8 +592,8 @@ async def test_if_fires_on_mqtt_message_late_discover(
|
|||
|
||||
|
||||
async def test_if_fires_on_mqtt_message_after_update(
|
||||
hass, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, device_reg, calls, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test triggers firing after update."""
|
||||
# Discover a device with device trigger
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -643,7 +673,9 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||
assert len(calls) == 3
|
||||
|
||||
|
||||
async def test_no_resubscribe_same_topic(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_no_resubscribe_same_topic(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test subscription to topics without change."""
|
||||
# Discover a device with device trigger
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -690,8 +722,8 @@ async def test_no_resubscribe_same_topic(hass, device_reg, mqtt_mock, setup_tasm
|
|||
|
||||
|
||||
async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
||||
hass, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, device_reg, calls, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test triggers not firing after removal."""
|
||||
# Discover a device with device trigger
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -761,8 +793,13 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
|||
|
||||
|
||||
async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
||||
hass, hass_ws_client, device_reg, calls, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_reg,
|
||||
calls,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test triggers not firing after removal."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
# Discover a device with device trigger
|
||||
|
@ -820,7 +857,9 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attach_remove(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_attach_remove(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger."""
|
||||
# Discover a device with device trigger
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -879,7 +918,9 @@ async def test_attach_remove(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attach_remove_late(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_attach_remove_late(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger."""
|
||||
# Discover a device without device triggers
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -950,7 +991,9 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||
assert len(calls) == 1
|
||||
|
||||
|
||||
async def test_attach_remove_late2(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_attach_remove_late2(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger."""
|
||||
# Discover a device without device triggers
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -1006,7 +1049,9 @@ async def test_attach_remove_late2(hass, device_reg, mqtt_mock, setup_tasmota):
|
|||
assert len(calls) == 0
|
||||
|
||||
|
||||
async def test_attach_remove_unknown1(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_attach_remove_unknown1(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test attach and removal of unknown trigger."""
|
||||
# Discover a device without device triggers
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -1044,8 +1089,12 @@ async def test_attach_remove_unknown1(hass, device_reg, mqtt_mock, setup_tasmota
|
|||
|
||||
|
||||
async def test_attach_unknown_remove_device_from_registry(
|
||||
hass, hass_ws_client, device_reg, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_reg,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test attach and removal of device with unknown trigger."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
# Discover a device without device triggers
|
||||
|
@ -1092,7 +1141,9 @@ async def test_attach_unknown_remove_device_from_registry(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_attach_remove_config_entry(hass, device_reg, mqtt_mock, setup_tasmota):
|
||||
async def test_attach_remove_config_entry(
|
||||
hass: HomeAssistant, device_reg, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test trigger cleanup when removing a Tasmota config entry."""
|
||||
# Discover a device with device trigger
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
|
|
@ -3,8 +3,11 @@ import copy
|
|||
import json
|
||||
from unittest.mock import ANY, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.components.tasmota.discovery import ALREADY_DISCOVERED
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
entity_registry as er,
|
||||
|
@ -16,9 +19,12 @@ from .conftest import setup_tasmota_helper
|
|||
from .test_common import DEFAULT_CONFIG, DEFAULT_CONFIG_9_0_0_3, remove_device
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_mqtt_message
|
||||
from tests.typing import MqttMockHAClient, WebSocketGenerator
|
||||
|
||||
|
||||
async def test_subscribing_config_topic(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_subscribing_config_topic(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test setting up discovery."""
|
||||
discovery_topic = DEFAULT_PREFIX
|
||||
|
||||
|
@ -26,7 +32,9 @@ async def test_subscribing_config_topic(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_subscribe.assert_any_call(discovery_topic + "/#", ANY, 0, "utf-8")
|
||||
|
||||
|
||||
async def test_future_discovery_message(hass, mqtt_mock, caplog):
|
||||
async def test_future_discovery_message(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we handle backwards compatible discovery messages."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["future_option"] = "BEST_SINCE_SLICED_BREAD"
|
||||
|
@ -45,7 +53,9 @@ async def test_future_discovery_message(hass, mqtt_mock, caplog):
|
|||
assert mock_tasmota_get_device_config.called
|
||||
|
||||
|
||||
async def test_valid_discovery_message(hass, mqtt_mock, caplog):
|
||||
async def test_valid_discovery_message(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test discovery callback called."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
|
@ -62,7 +72,7 @@ async def test_valid_discovery_message(hass, mqtt_mock, caplog):
|
|||
assert mock_tasmota_get_device_config.called
|
||||
|
||||
|
||||
async def test_invalid_topic(hass, mqtt_mock):
|
||||
async def test_invalid_topic(hass: HomeAssistant, mqtt_mock: MqttMockHAClient) -> None:
|
||||
"""Test receiving discovery message on wrong topic."""
|
||||
with patch(
|
||||
"homeassistant.components.tasmota.discovery.tasmota_get_device_config"
|
||||
|
@ -74,7 +84,9 @@ async def test_invalid_topic(hass, mqtt_mock):
|
|||
assert not mock_tasmota_get_device_config.called
|
||||
|
||||
|
||||
async def test_invalid_message(hass, mqtt_mock, caplog):
|
||||
async def test_invalid_message(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test receiving an invalid message."""
|
||||
with patch(
|
||||
"homeassistant.components.tasmota.discovery.tasmota_get_device_config"
|
||||
|
@ -87,7 +99,9 @@ async def test_invalid_message(hass, mqtt_mock, caplog):
|
|||
assert not mock_tasmota_get_device_config.called
|
||||
|
||||
|
||||
async def test_invalid_mac(hass, mqtt_mock, caplog):
|
||||
async def test_invalid_mac(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test topic is not matching device MAC."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
|
@ -105,8 +119,13 @@ async def test_invalid_mac(hass, mqtt_mock, caplog):
|
|||
|
||||
|
||||
async def test_correct_config_discovery(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test receiving valid discovery message."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -135,8 +154,13 @@ async def test_correct_config_discovery(
|
|||
|
||||
|
||||
async def test_device_discover(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test setting up a device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
mac = config["mac"]
|
||||
|
@ -161,8 +185,13 @@ async def test_device_discover(
|
|||
|
||||
|
||||
async def test_device_discover_deprecated(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test setting up a device with deprecated discovery message."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_9_0_0_3)
|
||||
mac = config["mac"]
|
||||
|
@ -186,8 +215,13 @@ async def test_device_discover_deprecated(
|
|||
|
||||
|
||||
async def test_device_update(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test updating a device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["md"] = "Model 1"
|
||||
|
@ -231,8 +265,13 @@ async def test_device_update(
|
|||
|
||||
|
||||
async def test_device_remove(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a discovered device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
mac = config["mac"]
|
||||
|
@ -265,8 +304,13 @@ async def test_device_remove(
|
|||
|
||||
|
||||
async def test_device_remove_multiple_config_entries_1(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a discovered device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
mac = config["mac"]
|
||||
|
@ -311,8 +355,13 @@ async def test_device_remove_multiple_config_entries_1(
|
|||
|
||||
|
||||
async def test_device_remove_multiple_config_entries_2(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a discovered device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
mac = config["mac"]
|
||||
|
@ -370,8 +419,13 @@ async def test_device_remove_multiple_config_entries_2(
|
|||
|
||||
|
||||
async def test_device_remove_stale(
|
||||
hass, hass_ws_client, mqtt_mock, caplog, device_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a stale (undiscovered) device does not throw."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
mac = "00000049A3BC"
|
||||
|
@ -401,8 +455,13 @@ async def test_device_remove_stale(
|
|||
|
||||
|
||||
async def test_device_rediscover(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a device."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
mac = config["mac"]
|
||||
|
@ -448,7 +507,12 @@ async def test_device_rediscover(
|
|||
assert device_entry1.id == device_entry.id
|
||||
|
||||
|
||||
async def test_entity_duplicate_discovery(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_entity_duplicate_discovery(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test entities are not duplicated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -478,7 +542,12 @@ async def test_entity_duplicate_discovery(hass, mqtt_mock, caplog, setup_tasmota
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_duplicate_removal(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_entity_duplicate_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing entity twice."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -502,8 +571,13 @@ async def test_entity_duplicate_removal(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
|
||||
|
||||
async def test_same_topic(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test detecting devices with same topic."""
|
||||
configs = [
|
||||
copy.deepcopy(DEFAULT_CONFIG),
|
||||
|
@ -621,8 +695,13 @@ async def test_same_topic(
|
|||
|
||||
|
||||
async def test_topic_no_prefix(
|
||||
hass, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test detecting devices with same topic."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
|
|
@ -14,6 +14,7 @@ from voluptuous import MultipleInvalid
|
|||
from homeassistant.components import fan
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import (
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -30,9 +31,12 @@ from .test_common import (
|
|||
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.components.fan import common
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
|
@ -88,7 +92,9 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes["percentage"] == 0
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
|
@ -182,7 +188,9 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_invalid_fan_speed_percentage(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_invalid_fan_speed_percentage(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
|
@ -211,8 +219,11 @@ async def test_invalid_fan_speed_percentage(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -222,7 +233,9 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -230,7 +243,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
|
|||
await help_test_availability(hass, mqtt_mock, Platform.FAN, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -239,8 +254,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["if"] = 1
|
||||
|
@ -250,7 +268,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_fan(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered fan."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["dn"] = "Test"
|
||||
|
@ -264,7 +287,12 @@ async def test_discovery_removal_fan(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_fan(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_update_unchanged_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered fan."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -277,7 +305,9 @@ async def test_discovery_update_unchanged_fan(hass, mqtt_mock, caplog, setup_tas
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -288,7 +318,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
@ -303,7 +335,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["dn"] = "Test"
|
||||
|
|
|
@ -3,7 +3,10 @@ import copy
|
|||
import json
|
||||
from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX, DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -15,11 +18,18 @@ from tests.common import (
|
|||
async_fire_mqtt_message,
|
||||
mock_integration,
|
||||
)
|
||||
from tests.typing import MqttMockHAClient, WebSocketGenerator
|
||||
|
||||
|
||||
async def test_device_remove(
|
||||
hass, hass_ws_client, mqtt_mock, caplog, device_reg, entity_reg, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a discovered device through device registry."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
@ -58,8 +68,12 @@ async def test_device_remove(
|
|||
|
||||
|
||||
async def test_device_remove_non_tasmota_device(
|
||||
hass, device_reg, hass_ws_client, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a non Tasmota device through device registry."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
|
||||
|
@ -99,8 +113,12 @@ async def test_device_remove_non_tasmota_device(
|
|||
|
||||
|
||||
async def test_device_remove_stale_tasmota_device(
|
||||
hass, device_reg, hass_ws_client, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removing a stale (undiscovered) Tasmota device through device registry."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
config_entry = hass.config_entries.async_entries("tasmota")[0]
|
||||
|
@ -126,8 +144,13 @@ async def test_device_remove_stale_tasmota_device(
|
|||
|
||||
|
||||
async def test_tasmota_ws_remove_discovered_device(
|
||||
hass, device_reg, entity_reg, hass_ws_client, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
device_reg,
|
||||
entity_reg,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test Tasmota websocket device removal."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
|
|
@ -9,10 +9,12 @@ from hatasmota.utils import (
|
|||
get_topic_tele_state,
|
||||
get_topic_tele_will,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import LightEntityFeature
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import (
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -29,9 +31,12 @@ from .test_common import (
|
|||
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.components.light import common
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
|
||||
async def test_attributes_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_on_off(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -57,7 +62,9 @@ async def test_attributes_on_off(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "onoff"
|
||||
|
||||
|
||||
async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_dimmer_tuya(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -84,7 +91,9 @@ async def test_attributes_dimmer_tuya(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "brightness"
|
||||
|
||||
|
||||
async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_dimmer(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -110,7 +119,9 @@ async def test_attributes_dimmer(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "brightness"
|
||||
|
||||
|
||||
async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_ct(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -136,7 +147,9 @@ async def test_attributes_ct(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_ct_reduced(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -163,7 +176,9 @@ async def test_attributes_ct_reduced(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_rgb(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -198,7 +213,9 @@ async def test_attributes_rgb(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
|
||||
async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_rgbw(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -233,7 +250,9 @@ async def test_attributes_rgbw(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "hs"
|
||||
|
||||
|
||||
async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_rgbww(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -268,7 +287,9 @@ async def test_attributes_rgbww(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes_rgbww_reduced(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -304,7 +325,9 @@ async def test_attributes_rgbww_reduced(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_on_off(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -353,7 +376,9 @@ async def test_controlling_state_via_mqtt_on_off(hass, mqtt_mock, setup_tasmota)
|
|||
assert "color_mode" not in state.attributes
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_ct(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -416,7 +441,9 @@ async def test_controlling_state_via_mqtt_ct(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("color_mode") == "color_temp"
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_rgbw(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -515,7 +542,9 @@ async def test_controlling_state_via_mqtt_rgbw(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_rgbww(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -614,7 +643,9 @@ async def test_controlling_state_via_mqtt_rgbww(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt_rgbww_tuya(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -723,7 +754,9 @@ async def test_controlling_state_via_mqtt_rgbww_tuya(hass, mqtt_mock, setup_tasm
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_on_off(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -764,7 +797,9 @@ async def test_sending_mqtt_commands_on_off(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_rgbww_tuya(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -812,7 +847,9 @@ async def test_sending_mqtt_commands_rgbww_tuya(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbw_legacy(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_rgbw_legacy(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["sw"] = "9.4.0.3" # RGBW support was added in 9.4.0.4
|
||||
|
@ -910,7 +947,9 @@ async def test_sending_mqtt_commands_rgbw_legacy(hass, mqtt_mock, setup_tasmota)
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_rgbw(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1007,7 +1046,9 @@ async def test_sending_mqtt_commands_rgbw(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_rgbww(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1082,7 +1123,9 @@ async def test_sending_mqtt_commands_rgbww(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_power_unlinked(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands_power_unlinked(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands to a light with unlinked dimlevel and power."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1134,7 +1177,9 @@ async def test_sending_mqtt_commands_power_unlinked(hass, mqtt_mock, setup_tasmo
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_transition(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_transition(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test transition commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1324,7 +1369,9 @@ async def test_transition(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_transition_fixed(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_transition_fixed(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test transition commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1398,7 +1445,9 @@ async def test_transition_fixed(hass, mqtt_mock, setup_tasmota):
|
|||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
|
||||
async def test_relay_as_light(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_relay_as_light(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test relay show up as light in light mode."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -1459,7 +1508,9 @@ async def _test_split_light(hass, mqtt_mock, config, num_lights, num_switches):
|
|||
)
|
||||
|
||||
|
||||
async def test_split_light(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_split_light(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test multi-channel light split to single-channel dimmers."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1473,7 +1524,9 @@ async def test_split_light(hass, mqtt_mock, setup_tasmota):
|
|||
await _test_split_light(hass, mqtt_mock, config, 5, 0)
|
||||
|
||||
|
||||
async def test_split_light2(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_split_light2(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test multi-channel light split to single-channel dimmers."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -1531,7 +1584,9 @@ async def _test_unlinked_light(hass, mqtt_mock, config, num_switches):
|
|||
)
|
||||
|
||||
|
||||
async def test_unlinked_light(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_unlinked_light(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test rgbww light split to rgb+ww."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1542,7 +1597,9 @@ async def test_unlinked_light(hass, mqtt_mock, setup_tasmota):
|
|||
await _test_unlinked_light(hass, mqtt_mock, config, 0)
|
||||
|
||||
|
||||
async def test_unlinked_light2(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_unlinked_light2(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test rgbww light split to rgb+ww."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -1556,8 +1613,11 @@ async def test_unlinked_light2(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_discovery_update_reconfigure_light(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test reconfigure of discovered light."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1587,8 +1647,11 @@ async def test_discovery_update_reconfigure_light(
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1598,7 +1661,9 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1606,7 +1671,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
|
|||
await help_test_availability(hass, mqtt_mock, Platform.LIGHT, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1617,8 +1684,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1629,7 +1699,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_light(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered light."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["rl"][0] = 2
|
||||
|
@ -1643,7 +1718,12 @@ async def test_discovery_removal_light(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_relay_as_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered relay as light."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["rl"][0] = 1
|
||||
|
@ -1658,8 +1738,11 @@ async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_t
|
|||
|
||||
|
||||
async def test_discovery_removal_relay_as_light2(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered relay as light."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["rl"][0] = 1
|
||||
|
@ -1673,7 +1756,12 @@ async def test_discovery_removal_relay_as_light2(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_update_unchanged_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1686,7 +1774,9 @@ async def test_discovery_update_unchanged_light(hass, mqtt_mock, caplog, setup_t
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1697,7 +1787,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove_relay_as_light(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove_relay_as_light(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -1708,7 +1800,9 @@ async def test_discovery_device_remove_relay_as_light(hass, mqtt_mock, setup_tas
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
@ -1723,7 +1817,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 2
|
||||
|
|
|
@ -7,15 +7,20 @@ from hatasmota.const import CONF_MAC
|
|||
from hatasmota.utils import config_get_state_online, get_topic_tele_will
|
||||
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import DEFAULT_CONFIG
|
||||
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
|
||||
async def test_availability_poll_state_once(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test several entities send a single message to update state."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant import config_entries
|
|||
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.util import dt
|
||||
|
||||
|
@ -35,6 +36,7 @@ from .test_common import (
|
|||
)
|
||||
|
||||
from tests.common import async_fire_mqtt_message, async_fire_time_changed
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
BAD_INDEXED_SENSOR_CONFIG_3 = {
|
||||
"sn": {
|
||||
|
@ -118,7 +120,9 @@ NESTED_SENSOR_CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -170,7 +174,9 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == "20.0"
|
||||
|
||||
|
||||
async def test_nested_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_nested_sensor_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(NESTED_SENSOR_CONFIG)
|
||||
|
@ -216,7 +222,9 @@ async def test_nested_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == "23.4"
|
||||
|
||||
|
||||
async def test_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_indexed_sensor_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(INDEXED_SENSOR_CONFIG)
|
||||
|
@ -262,7 +270,9 @@ async def test_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == "7.8"
|
||||
|
||||
|
||||
async def test_indexed_sensor_state_via_mqtt2(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_indexed_sensor_state_via_mqtt2(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT for sensor with last_reset property."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(INDEXED_SENSOR_CONFIG)
|
||||
|
@ -311,7 +321,9 @@ async def test_indexed_sensor_state_via_mqtt2(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == "5.6"
|
||||
|
||||
|
||||
async def test_indexed_sensor_state_via_mqtt3(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_indexed_sensor_state_via_mqtt3(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT for indexed sensor with last_reset property."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(INDEXED_SENSOR_CONFIG_2)
|
||||
|
@ -360,7 +372,9 @@ async def test_indexed_sensor_state_via_mqtt3(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == "7.8"
|
||||
|
||||
|
||||
async def test_bad_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_bad_indexed_sensor_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT where sensor is not matching configuration."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(BAD_INDEXED_SENSOR_CONFIG_3)
|
||||
|
@ -473,7 +487,9 @@ async def test_bad_indexed_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota)
|
|||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_status_sensor_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
|
@ -533,7 +549,9 @@ async def test_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_single_shot_status_sensor_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
|
@ -617,8 +635,8 @@ async def test_single_shot_status_sensor_state_via_mqtt(hass, mqtt_mock, setup_t
|
|||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
@patch.object(hatasmota.status_sensor, "datetime", Mock(wraps=datetime.datetime))
|
||||
async def test_restart_time_status_sensor_state_via_mqtt(
|
||||
hass, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
|
@ -665,7 +683,9 @@ async def test_restart_time_status_sensor_state_via_mqtt(
|
|||
assert state.state == "2020-11-11T07:00:00+00:00"
|
||||
|
||||
|
||||
async def test_attributes(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_attributes(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test correct attributes for sensors."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = {
|
||||
|
@ -703,7 +723,9 @@ async def test_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("unit_of_measurement") == "ppm"
|
||||
|
||||
|
||||
async def test_nested_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_nested_sensor_attributes(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test correct attributes for sensors."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(NESTED_SENSOR_CONFIG)
|
||||
|
@ -735,7 +757,9 @@ async def test_nested_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.attributes.get("unit_of_measurement") == " "
|
||||
|
||||
|
||||
async def test_indexed_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_indexed_sensor_attributes(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test correct attributes for sensors."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = {
|
||||
|
@ -788,8 +812,13 @@ async def test_indexed_sensor_attributes(hass, mqtt_mock, setup_tasmota):
|
|||
],
|
||||
)
|
||||
async def test_diagnostic_sensors(
|
||||
hass, mqtt_mock, setup_tasmota, sensor_name, disabled, disabled_by
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
sensor_name,
|
||||
disabled,
|
||||
disabled_by,
|
||||
) -> None:
|
||||
"""Test properties of diagnostic sensors."""
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
|
@ -813,7 +842,9 @@ async def test_diagnostic_sensors(
|
|||
|
||||
|
||||
@pytest.mark.parametrize("status_sensor_disabled", [False])
|
||||
async def test_enable_status_sensor(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_enable_status_sensor(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test enabling status sensor."""
|
||||
entity_reg = er.async_get(hass)
|
||||
|
||||
|
@ -868,8 +899,11 @@ async def test_enable_status_sensor(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -884,7 +918,9 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -898,7 +934,9 @@ async def test_availability(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -913,8 +951,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -931,7 +972,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_sensor(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered sensor."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config1 = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -951,8 +997,11 @@ async def test_discovery_removal_sensor(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
|
||||
|
||||
async def test_discovery_update_unchanged_sensor(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered sensor."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -972,7 +1021,9 @@ async def test_discovery_update_unchanged_sensor(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -982,7 +1033,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
@ -1002,7 +1055,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
sensor_config = copy.deepcopy(DEFAULT_SENSOR_CONFIG)
|
||||
|
|
|
@ -8,9 +8,11 @@ from hatasmota.utils import (
|
|||
get_topic_tele_state,
|
||||
get_topic_tele_will,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.tasmota.const import DEFAULT_PREFIX
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_common import (
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -27,9 +29,12 @@ from .test_common import (
|
|||
|
||||
from tests.common import async_fire_mqtt_message
|
||||
from tests.components.switch import common
|
||||
from tests.typing import MqttMockHAClient, MqttMockPahoClient
|
||||
|
||||
|
||||
async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_controlling_state_via_mqtt(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test state update via MQTT."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -73,7 +78,9 @@ async def test_controlling_state_via_mqtt(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_sending_mqtt_commands(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -115,7 +122,9 @@ async def test_sending_mqtt_commands(hass, mqtt_mock, setup_tasmota):
|
|||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_relay_as_light(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_relay_as_light(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test relay does not show up as switch in light mode."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -136,8 +145,11 @@ async def test_relay_as_light(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_when_connection_lost(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -146,14 +158,18 @@ async def test_availability_when_connection_lost(
|
|||
)
|
||||
|
||||
|
||||
async def test_availability(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
await help_test_availability(hass, mqtt_mock, Platform.SWITCH, config)
|
||||
|
||||
|
||||
async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_availability_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -163,8 +179,11 @@ async def test_availability_discovery_update(hass, mqtt_mock, setup_tasmota):
|
|||
|
||||
|
||||
async def test_availability_poll_state(
|
||||
hass, mqtt_client_mock, mqtt_mock, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test polling after MQTT connection (re)established."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -174,7 +193,12 @@ async def test_availability_poll_state(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_switch(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_switch(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered switch."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["rl"][0] = 1
|
||||
|
@ -186,7 +210,12 @@ async def test_discovery_removal_switch(hass, mqtt_mock, caplog, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_tasmota):
|
||||
async def test_discovery_removal_relay_as_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test removal of discovered relay as light."""
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config1["rl"][0] = 1
|
||||
|
@ -201,8 +230,11 @@ async def test_discovery_removal_relay_as_light(hass, mqtt_mock, caplog, setup_t
|
|||
|
||||
|
||||
async def test_discovery_update_unchanged_switch(
|
||||
hass, mqtt_mock, caplog, setup_tasmota
|
||||
):
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock: MqttMockHAClient,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
setup_tasmota,
|
||||
) -> None:
|
||||
"""Test update of discovered switch."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -214,7 +246,9 @@ async def test_discovery_update_unchanged_switch(
|
|||
)
|
||||
|
||||
|
||||
async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_discovery_device_remove(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -224,7 +258,9 @@ async def test_discovery_device_remove(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
@ -238,7 +274,9 @@ async def test_entity_id_update_subscriptions(hass, mqtt_mock, setup_tasmota):
|
|||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(hass, mqtt_mock, setup_tasmota):
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock: MqttMockHAClient, setup_tasmota
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["rl"][0] = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue