Add missed type hints on MQTT platform tests (#87781)

This commit is contained in:
Jan Bouwhuis 2023-02-09 15:22:30 +01:00 committed by GitHub
parent 483b0cd017
commit dc5f35a85e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 11 deletions

View file

@ -783,7 +783,7 @@ async def test_invalid_discovery_prefix(
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
mock_try_connection,
mock_reload_after_entry_update,
) -> HomeAssistant:
) -> None:
"""Test setting an invalid discovery prefix."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
mock_try_connection.return_value = True
@ -1160,7 +1160,7 @@ async def test_try_connection_with_advanced_parameters(
tmp_path: Path,
mock_ssl_context,
mock_process_uploaded_file,
) -> HomeAssistant:
) -> None:
"""Test config flow with advanced parameters from config."""
with open(tmp_path / "client.crt", "wb") as certfile:

View file

@ -10,7 +10,7 @@ import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
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.trigger import async_initialize_triggers
from homeassistant.setup import async_setup_component
@ -28,7 +28,7 @@ from tests.typing import MqttMockHAClient, MqttMockHAClientGenerator, WebSocketG
@pytest.fixture
def calls(hass):
def calls(hass: HomeAssistant) -> list[ServiceCall]:
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")

View file

@ -79,7 +79,6 @@ light:
brightness_scale: 99
"""
import copy
import json
from pathlib import Path
from unittest.mock import call, patch
@ -98,6 +97,7 @@ from homeassistant.const import (
Platform,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.json import JsonValueType, json_loads
from homeassistant.setup import async_setup_component
from .test_common import (
@ -154,13 +154,13 @@ def light_platform_only():
class JsonValidator:
"""Helper to compare JSON."""
def __init__(self, jsondata):
def __init__(self, jsondata: JsonValueType) -> None:
"""Initialize JSON validator."""
self.jsondata = jsondata
def __eq__(self, other):
def __eq__(self, other: JsonValueType) -> bool:
"""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(

View file

@ -44,7 +44,7 @@ async def test_availability_with_shared_state_topic(
events = []
@callback
def test_callback(event):
def test_callback(event) -> None:
events.append(event)
hass.bus.async_listen(EVENT_STATE_CHANGED, test_callback)

View file

@ -1,6 +1,7 @@
"""The tests for the MQTT siren platform."""
import copy
from pathlib import Path
from typing import Any
from unittest.mock import patch
import pytest
@ -66,7 +67,11 @@ def siren_platform_only():
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."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
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)
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."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}