Add missed type hints on MQTT platform tests (#87781)
This commit is contained in:
parent
483b0cd017
commit
dc5f35a85e
5 changed files with 18 additions and 11 deletions
|
@ -783,7 +783,7 @@ async def test_invalid_discovery_prefix(
|
||||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||||
mock_try_connection,
|
mock_try_connection,
|
||||||
mock_reload_after_entry_update,
|
mock_reload_after_entry_update,
|
||||||
) -> HomeAssistant:
|
) -> None:
|
||||||
"""Test setting an invalid discovery prefix."""
|
"""Test setting an invalid discovery prefix."""
|
||||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||||
mock_try_connection.return_value = True
|
mock_try_connection.return_value = True
|
||||||
|
@ -1160,7 +1160,7 @@ async def test_try_connection_with_advanced_parameters(
|
||||||
tmp_path: Path,
|
tmp_path: Path,
|
||||||
mock_ssl_context,
|
mock_ssl_context,
|
||||||
mock_process_uploaded_file,
|
mock_process_uploaded_file,
|
||||||
) -> HomeAssistant:
|
) -> None:
|
||||||
"""Test config flow with advanced parameters from config."""
|
"""Test config flow with advanced parameters from config."""
|
||||||
|
|
||||||
with open(tmp_path / "client.crt", "wb") as certfile:
|
with open(tmp_path / "client.crt", "wb") as certfile:
|
||||||
|
|
|
@ -10,7 +10,7 @@ import homeassistant.components.automation as automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
|
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.trigger import async_initialize_triggers
|
from homeassistant.helpers.trigger import async_initialize_triggers
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -28,7 +28,7 @@ from tests.typing import MqttMockHAClient, MqttMockHAClientGenerator, WebSocketG
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def calls(hass):
|
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
||||||
"""Track calls to a mock service."""
|
"""Track calls to a mock service."""
|
||||||
return async_mock_service(hass, "test", "automation")
|
return async_mock_service(hass, "test", "automation")
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,6 @@ light:
|
||||||
brightness_scale: 99
|
brightness_scale: 99
|
||||||
"""
|
"""
|
||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import call, patch
|
from unittest.mock import call, patch
|
||||||
|
|
||||||
|
@ -98,6 +97,7 @@ from homeassistant.const import (
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, State
|
from homeassistant.core import HomeAssistant, State
|
||||||
|
from homeassistant.helpers.json import JsonValueType, json_loads
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
|
@ -154,13 +154,13 @@ def light_platform_only():
|
||||||
class JsonValidator:
|
class JsonValidator:
|
||||||
"""Helper to compare JSON."""
|
"""Helper to compare JSON."""
|
||||||
|
|
||||||
def __init__(self, jsondata):
|
def __init__(self, jsondata: JsonValueType) -> None:
|
||||||
"""Initialize JSON validator."""
|
"""Initialize JSON validator."""
|
||||||
self.jsondata = jsondata
|
self.jsondata = jsondata
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other: JsonValueType) -> bool:
|
||||||
"""Compare JSON data."""
|
"""Compare JSON data."""
|
||||||
return json.loads(self.jsondata) == json.loads(other)
|
return json_loads(self.jsondata) == json_loads(other)
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_setup_if_no_command_topic(
|
async def test_fail_setup_if_no_command_topic(
|
||||||
|
|
|
@ -44,7 +44,7 @@ async def test_availability_with_shared_state_topic(
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def test_callback(event):
|
def test_callback(event) -> None:
|
||||||
events.append(event)
|
events.append(event)
|
||||||
|
|
||||||
hass.bus.async_listen(EVENT_STATE_CHANGED, test_callback)
|
hass.bus.async_listen(EVENT_STATE_CHANGED, test_callback)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""The tests for the MQTT siren platform."""
|
"""The tests for the MQTT siren platform."""
|
||||||
import copy
|
import copy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -66,7 +67,11 @@ def siren_platform_only():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def async_turn_on(hass, entity_id=ENTITY_MATCH_ALL, parameters={}) -> None:
|
async def async_turn_on(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_id: str = ENTITY_MATCH_ALL,
|
||||||
|
parameters: dict[str, Any] = {},
|
||||||
|
) -> None:
|
||||||
"""Turn all or specified siren on."""
|
"""Turn all or specified siren on."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
data.update(parameters)
|
data.update(parameters)
|
||||||
|
@ -74,7 +79,9 @@ async def async_turn_on(hass, entity_id=ENTITY_MATCH_ALL, parameters={}) -> None
|
||||||
await hass.services.async_call(siren.DOMAIN, SERVICE_TURN_ON, data, blocking=True)
|
await hass.services.async_call(siren.DOMAIN, SERVICE_TURN_ON, data, blocking=True)
|
||||||
|
|
||||||
|
|
||||||
async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL) -> None:
|
async def async_turn_off(
|
||||||
|
hass: HomeAssistant, entity_id: str = ENTITY_MATCH_ALL
|
||||||
|
) -> None:
|
||||||
"""Turn all or specified siren off."""
|
"""Turn all or specified siren off."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue