Add type hints to integration tests (part 25) (#88308)

This commit is contained in:
epenet 2023-02-17 16:52:28 +01:00 committed by GitHub
parent aeb09678a8
commit 5b80b1f55a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 444 additions and 278 deletions

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -85,8 +86,8 @@ async def _async_multiple_call_helper(hass, pywemo_device, call1, call2):
async def test_async_update_locked_callback_and_update( async def test_async_update_locked_callback_and_update(
hass, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_device, wemo_entity
): ) -> None:
"""Test that a callback and a state update request can't both happen at the same time. """Test that a callback and a state update request can't both happen at the same time.
When a state update is received via a callback from the device at the same time When a state update is received via a callback from the device at the same time
@ -99,7 +100,9 @@ async def test_async_update_locked_callback_and_update(
await _async_multiple_call_helper(hass, pywemo_device, callback, update) await _async_multiple_call_helper(hass, pywemo_device, callback, update)
async def test_async_update_locked_multiple_updates(hass, pywemo_device, wemo_entity): async def test_async_update_locked_multiple_updates(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Test that two hass async_update state updates do not proceed at the same time.""" """Test that two hass async_update state updates do not proceed at the same time."""
coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
@ -107,7 +110,9 @@ async def test_async_update_locked_multiple_updates(hass, pywemo_device, wemo_en
await _async_multiple_call_helper(hass, pywemo_device, update, update) await _async_multiple_call_helper(hass, pywemo_device, update, update)
async def test_async_update_locked_multiple_callbacks(hass, pywemo_device, wemo_entity): async def test_async_update_locked_multiple_callbacks(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Test that two device callback state updates do not proceed at the same time.""" """Test that two device callback state updates do not proceed at the same time."""
coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) coordinator = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
@ -116,8 +121,8 @@ async def test_async_update_locked_multiple_callbacks(hass, pywemo_device, wemo_
async def test_avaliable_after_update( async def test_avaliable_after_update(
hass, pywemo_registry, pywemo_device, wemo_entity, domain hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity, domain
): ) -> None:
"""Test the avaliability when an On call fails and after an update. """Test the avaliability when an On call fails and after an update.
This test expects that the pywemo_device Mock has been setup to raise an This test expects that the pywemo_device Mock has been setup to raise an
@ -137,7 +142,7 @@ async def test_avaliable_after_update(
assert hass.states.get(wemo_entity.entity_id).state == STATE_ON assert hass.states.get(wemo_entity.entity_id).state == STATE_ON
async def test_turn_off_state(hass, wemo_entity, domain): async def test_turn_off_state(hass: HomeAssistant, wemo_entity, domain) -> None:
"""Test that the device state is updated after turning off.""" """Test that the device state is updated after turning off."""
await hass.services.async_call( await hass.services.async_call(
domain, domain,

View file

@ -56,7 +56,7 @@ async def setup_automation(hass, device_id, trigger_type):
) )
async def test_get_triggers(hass, wemo_entity): async def test_get_triggers(hass: HomeAssistant, wemo_entity) -> None:
"""Test that the triggers appear for a supported device.""" """Test that the triggers appear for a supported device."""
assert wemo_entity.device_id is not None assert wemo_entity.device_id is not None

View file

@ -1,5 +1,4 @@
"""Tests for the Wemo fan entity.""" """Tests for the Wemo fan entity."""
import pytest import pytest
from pywemo.exceptions import ActionException from pywemo.exceptions import ActionException
from pywemo.ouimeaux_device.humidifier import DesiredHumidity, FanMode from pywemo.ouimeaux_device.humidifier import DesiredHumidity, FanMode
@ -16,6 +15,7 @@ from homeassistant.components.homeassistant import (
from homeassistant.components.wemo import fan from homeassistant.components.wemo import fan
from homeassistant.components.wemo.const import DOMAIN from homeassistant.components.wemo.const import DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_OFF, STATE_ON from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import entity_test_helpers from . import entity_test_helpers
@ -43,8 +43,8 @@ test_async_update_locked_callback_and_update = (
async def test_fan_registry_state_callback( async def test_fan_registry_state_callback(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Verify that the fan receives state updates from the registry.""" """Verify that the fan receives state updates from the registry."""
# On state. # On state.
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -59,7 +59,9 @@ async def test_fan_registry_state_callback(
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
async def test_fan_update_entity(hass, pywemo_registry, pywemo_device, wemo_entity): async def test_fan_update_entity(
hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
) -> None:
"""Verify that the fan performs state updates.""" """Verify that the fan performs state updates."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
@ -85,8 +87,8 @@ async def test_fan_update_entity(hass, pywemo_registry, pywemo_device, wemo_enti
async def test_available_after_update( async def test_available_after_update(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Test the avaliability when an On call fails and after an update.""" """Test the avaliability when an On call fails and after an update."""
pywemo_device.set_state.side_effect = ActionException pywemo_device.set_state.side_effect = ActionException
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -95,12 +97,14 @@ async def test_available_after_update(
) )
async def test_turn_off_state(hass, wemo_entity): async def test_turn_off_state(hass: HomeAssistant, wemo_entity) -> None:
"""Test that the device state is updated after turning off.""" """Test that the device state is updated after turning off."""
await entity_test_helpers.test_turn_off_state(hass, wemo_entity, FAN_DOMAIN) await entity_test_helpers.test_turn_off_state(hass, wemo_entity, FAN_DOMAIN)
async def test_fan_reset_filter_service(hass, pywemo_device, wemo_entity): async def test_fan_reset_filter_service(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Verify that SERVICE_RESET_FILTER_LIFE is registered and works.""" """Verify that SERVICE_RESET_FILTER_LIFE is registered and works."""
assert await hass.services.async_call( assert await hass.services.async_call(
DOMAIN, DOMAIN,
@ -123,8 +127,8 @@ async def test_fan_reset_filter_service(hass, pywemo_device, wemo_entity):
], ],
) )
async def test_fan_set_humidity_service( async def test_fan_set_humidity_service(
hass, pywemo_device, wemo_entity, test_input, expected hass: HomeAssistant, pywemo_device, wemo_entity, test_input, expected
): ) -> None:
"""Verify that SERVICE_SET_HUMIDITY is registered and works.""" """Verify that SERVICE_SET_HUMIDITY is registered and works."""
assert await hass.services.async_call( assert await hass.services.async_call(
DOMAIN, DOMAIN,
@ -150,8 +154,8 @@ async def test_fan_set_humidity_service(
], ],
) )
async def test_fan_set_percentage( async def test_fan_set_percentage(
hass, pywemo_device, wemo_entity, percentage, expected_fan_mode hass: HomeAssistant, pywemo_device, wemo_entity, percentage, expected_fan_mode
): ) -> None:
"""Verify set_percentage works properly through the entire range of FanModes.""" """Verify set_percentage works properly through the entire range of FanModes."""
assert await hass.services.async_call( assert await hass.services.async_call(
FAN_DOMAIN, FAN_DOMAIN,
@ -162,7 +166,7 @@ async def test_fan_set_percentage(
pywemo_device.set_state.assert_called_with(expected_fan_mode) pywemo_device.set_state.assert_called_with(expected_fan_mode)
async def test_fan_mode_high_initially(hass, pywemo_device): async def test_fan_mode_high_initially(hass: HomeAssistant, pywemo_device) -> None:
"""Verify the FanMode is set to High when turned on.""" """Verify the FanMode is set to High when turned on."""
pywemo_device.fan_mode = FanMode.Off pywemo_device.fan_mode = FanMode.Off
wemo_entity = await async_create_wemo_entity(hass, pywemo_device, "") wemo_entity = await async_create_wemo_entity(hass, pywemo_device, "")

View file

@ -32,7 +32,9 @@ async def test_config_no_static(hass: HomeAssistant) -> None:
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_DISCOVERY: False}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_DISCOVERY: False}})
async def test_static_duplicate_static_entry(hass, pywemo_device): async def test_static_duplicate_static_entry(
hass: HomeAssistant, pywemo_device
) -> None:
"""Duplicate static entries are merged into a single entity.""" """Duplicate static entries are merged into a single entity."""
static_config_entry = f"{MOCK_HOST}:{MOCK_PORT}" static_config_entry = f"{MOCK_HOST}:{MOCK_PORT}"
assert await async_setup_component( assert await async_setup_component(
@ -54,7 +56,7 @@ async def test_static_duplicate_static_entry(hass, pywemo_device):
assert len(entity_entries) == 1 assert len(entity_entries) == 1
async def test_static_config_with_port(hass, pywemo_device): async def test_static_config_with_port(hass: HomeAssistant, pywemo_device) -> None:
"""Static device with host and port is added and removed.""" """Static device with host and port is added and removed."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -72,7 +74,7 @@ async def test_static_config_with_port(hass, pywemo_device):
assert len(entity_entries) == 1 assert len(entity_entries) == 1
async def test_static_config_without_port(hass, pywemo_device): async def test_static_config_without_port(hass: HomeAssistant, pywemo_device) -> None:
"""Static device with host and no port is added and removed.""" """Static device with host and no port is added and removed."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -105,7 +107,7 @@ async def test_static_config_with_invalid_host(hass: HomeAssistant) -> None:
assert not setup_success assert not setup_success
async def test_discovery(hass, pywemo_registry): async def test_discovery(hass: HomeAssistant, pywemo_registry) -> None:
"""Verify that discovery dispatches devices to the platform for setup.""" """Verify that discovery dispatches devices to the platform for setup."""
def create_device(counter): def create_device(counter):

View file

@ -16,6 +16,7 @@ from homeassistant.components.light import (
ColorMode, ColorMode,
) )
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import entity_test_helpers from . import entity_test_helpers
@ -44,8 +45,8 @@ def pywemo_bridge_light_fixture(pywemo_device):
async def test_async_update_locked_callback_and_update( async def test_async_update_locked_callback_and_update(
hass, pywemo_bridge_light, wemo_entity, pywemo_device hass: HomeAssistant, pywemo_bridge_light, wemo_entity, pywemo_device
): ) -> None:
"""Test that a callback and a state update request can't both happen at the same time.""" """Test that a callback and a state update request can't both happen at the same time."""
await entity_test_helpers.test_async_update_locked_callback_and_update( await entity_test_helpers.test_async_update_locked_callback_and_update(
hass, hass,
@ -55,8 +56,8 @@ async def test_async_update_locked_callback_and_update(
async def test_async_update_locked_multiple_updates( async def test_async_update_locked_multiple_updates(
hass, pywemo_bridge_light, wemo_entity, pywemo_device hass: HomeAssistant, pywemo_bridge_light, wemo_entity, pywemo_device
): ) -> None:
"""Test that two state updates do not proceed at the same time.""" """Test that two state updates do not proceed at the same time."""
await entity_test_helpers.test_async_update_locked_multiple_updates( await entity_test_helpers.test_async_update_locked_multiple_updates(
hass, hass,
@ -66,8 +67,8 @@ async def test_async_update_locked_multiple_updates(
async def test_async_update_locked_multiple_callbacks( async def test_async_update_locked_multiple_callbacks(
hass, pywemo_bridge_light, wemo_entity, pywemo_device hass: HomeAssistant, pywemo_bridge_light, wemo_entity, pywemo_device
): ) -> None:
"""Test that two device callback state updates do not proceed at the same time.""" """Test that two device callback state updates do not proceed at the same time."""
await entity_test_helpers.test_async_update_locked_multiple_callbacks( await entity_test_helpers.test_async_update_locked_multiple_callbacks(
hass, hass,
@ -77,8 +78,12 @@ async def test_async_update_locked_multiple_callbacks(
async def test_available_after_update( async def test_available_after_update(
hass, pywemo_registry, pywemo_device, pywemo_bridge_light, wemo_entity hass: HomeAssistant,
): pywemo_registry,
pywemo_device,
pywemo_bridge_light,
wemo_entity,
) -> None:
"""Test the avaliability when an On call fails and after an update.""" """Test the avaliability when an On call fails and after an update."""
pywemo_bridge_light.turn_on.side_effect = pywemo.exceptions.ActionException pywemo_bridge_light.turn_on.side_effect = pywemo.exceptions.ActionException
pywemo_bridge_light.state["onoff"] = 1 pywemo_bridge_light.state["onoff"] = 1
@ -87,14 +92,16 @@ async def test_available_after_update(
) )
async def test_turn_off_state(hass, pywemo_bridge_light, wemo_entity): async def test_turn_off_state(
hass: HomeAssistant, pywemo_bridge_light, wemo_entity
) -> None:
"""Test that the device state is updated after turning off.""" """Test that the device state is updated after turning off."""
await entity_test_helpers.test_turn_off_state(hass, wemo_entity, LIGHT_DOMAIN) await entity_test_helpers.test_turn_off_state(hass, wemo_entity, LIGHT_DOMAIN)
async def test_light_update_entity( async def test_light_update_entity(
hass, pywemo_registry, pywemo_bridge_light, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_bridge_light, wemo_entity
): ) -> None:
"""Verify that the light performs state updates.""" """Verify that the light performs state updates."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})

View file

@ -1,5 +1,4 @@
"""Tests for the Wemo standalone/non-bridge light entity.""" """Tests for the Wemo standalone/non-bridge light entity."""
import pytest import pytest
from pywemo.exceptions import ActionException from pywemo.exceptions import ActionException
@ -9,6 +8,7 @@ from homeassistant.components.homeassistant import (
) )
from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN as LIGHT_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_OFF, STATE_ON from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import entity_test_helpers from . import entity_test_helpers
@ -35,8 +35,8 @@ test_async_update_locked_callback_and_update = (
async def test_available_after_update( async def test_available_after_update(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Test the avaliability when an On call fails and after an update.""" """Test the avaliability when an On call fails and after an update."""
pywemo_device.on.side_effect = ActionException pywemo_device.on.side_effect = ActionException
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -45,12 +45,14 @@ async def test_available_after_update(
) )
async def test_turn_off_state(hass, wemo_entity): async def test_turn_off_state(hass: HomeAssistant, wemo_entity) -> None:
"""Test that the device state is updated after turning off.""" """Test that the device state is updated after turning off."""
await entity_test_helpers.test_turn_off_state(hass, wemo_entity, LIGHT_DOMAIN) await entity_test_helpers.test_turn_off_state(hass, wemo_entity, LIGHT_DOMAIN)
async def test_turn_on_brightness(hass, pywemo_device, wemo_entity): async def test_turn_on_brightness(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Test setting the brightness value of the light.""" """Test setting the brightness value of the light."""
brightness = 0 brightness = 0
state = 0 state = 0
@ -78,8 +80,8 @@ async def test_turn_on_brightness(hass, pywemo_device, wemo_entity):
async def test_light_registry_state_callback( async def test_light_registry_state_callback(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Verify that the light receives state updates from the registry.""" """Verify that the light receives state updates from the registry."""
# On state. # On state.
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -94,7 +96,9 @@ async def test_light_registry_state_callback(
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
async def test_light_update_entity(hass, pywemo_registry, pywemo_device, wemo_entity): async def test_light_update_entity(
hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
) -> None:
"""Verify that the light performs state updates.""" """Verify that the light performs state updates."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})

View file

@ -1,5 +1,4 @@
"""Tests for the Wemo switch entity.""" """Tests for the Wemo switch entity."""
import pytest import pytest
import pywemo import pywemo
@ -25,6 +24,7 @@ from homeassistant.const import (
STATE_STANDBY, STATE_STANDBY,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import entity_test_helpers from . import entity_test_helpers
@ -56,8 +56,8 @@ test_async_update_locked_callback_and_update = (
async def test_switch_registry_state_callback( async def test_switch_registry_state_callback(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Verify that the switch receives state updates from the registry.""" """Verify that the switch receives state updates from the registry."""
# On state. # On state.
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -72,7 +72,9 @@ async def test_switch_registry_state_callback(
assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF
async def test_switch_update_entity(hass, pywemo_registry, pywemo_device, wemo_entity): async def test_switch_update_entity(
hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
) -> None:
"""Verify that the switch performs state updates.""" """Verify that the switch performs state updates."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
@ -98,8 +100,8 @@ async def test_switch_update_entity(hass, pywemo_registry, pywemo_device, wemo_e
async def test_available_after_update( async def test_available_after_update(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""Test the avaliability when an On call fails and after an update.""" """Test the avaliability when an On call fails and after an update."""
pywemo_device.on.side_effect = pywemo.exceptions.ActionException pywemo_device.on.side_effect = pywemo.exceptions.ActionException
pywemo_device.get_state.return_value = 1 pywemo_device.get_state.return_value = 1
@ -108,12 +110,12 @@ async def test_available_after_update(
) )
async def test_turn_off_state(hass, wemo_entity): async def test_turn_off_state(hass: HomeAssistant, wemo_entity) -> None:
"""Test that the device state is updated after turning off.""" """Test that the device state is updated after turning off."""
await entity_test_helpers.test_turn_off_state(hass, wemo_entity, SWITCH_DOMAIN) await entity_test_helpers.test_turn_off_state(hass, wemo_entity, SWITCH_DOMAIN)
async def test_insight_state_attributes(hass, pywemo_registry): async def test_insight_state_attributes(hass: HomeAssistant, pywemo_registry) -> None:
"""Verify the switch attributes are set for the Insight device.""" """Verify the switch attributes are set for the Insight device."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
with create_pywemo_device(pywemo_registry, "Insight") as insight: with create_pywemo_device(pywemo_registry, "Insight") as insight:
@ -152,7 +154,7 @@ async def test_insight_state_attributes(hass, pywemo_registry):
assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_UNKNOWN assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_UNKNOWN
async def test_maker_state_attributes(hass, pywemo_registry): async def test_maker_state_attributes(hass: HomeAssistant, pywemo_registry) -> None:
"""Verify the switch attributes are set for the Insight device.""" """Verify the switch attributes are set for the Insight device."""
await async_setup_component(hass, HA_DOMAIN, {}) await async_setup_component(hass, HA_DOMAIN, {})
with create_pywemo_device(pywemo_registry, "Maker") as maker: with create_pywemo_device(pywemo_registry, "Maker") as maker:

View file

@ -11,7 +11,7 @@ from pywemo.subscribe import EVENT_TYPE_LONG_PRESS
from homeassistant import runner from homeassistant import runner
from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC, wemo_device from homeassistant.components.wemo import CONF_DISCOVERY, CONF_STATIC, wemo_device
from homeassistant.components.wemo.const import DOMAIN, WEMO_SUBSCRIPTION_EVENT from homeassistant.components.wemo.const import DOMAIN, WEMO_SUBSCRIPTION_EVENT
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry
from homeassistant.helpers.update_coordinator import UpdateFailed from homeassistant.helpers.update_coordinator import UpdateFailed
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -30,7 +30,9 @@ def pywemo_model():
return "LightSwitchLongPress" return "LightSwitchLongPress"
async def test_async_register_device_longpress_fails(hass, pywemo_device): async def test_async_register_device_longpress_fails(
hass: HomeAssistant, pywemo_device
) -> None:
"""Device is still registered if ensure_long_press_virtual_device fails.""" """Device is still registered if ensure_long_press_virtual_device fails."""
with patch.object(pywemo_device, "ensure_long_press_virtual_device") as elp: with patch.object(pywemo_device, "ensure_long_press_virtual_device") as elp:
elp.side_effect = PyWeMoException elp.side_effect = PyWeMoException
@ -52,7 +54,9 @@ async def test_async_register_device_longpress_fails(hass, pywemo_device):
assert device.supports_long_press is False assert device.supports_long_press is False
async def test_long_press_event(hass, pywemo_registry, wemo_entity): async def test_long_press_event(
hass: HomeAssistant, pywemo_registry, wemo_entity
) -> None:
"""Device fires a long press event.""" """Device fires a long press event."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
got_event = asyncio.Event() got_event = asyncio.Event()
@ -85,7 +89,9 @@ async def test_long_press_event(hass, pywemo_registry, wemo_entity):
} }
async def test_subscription_callback(hass, pywemo_registry, wemo_entity): async def test_subscription_callback(
hass: HomeAssistant, pywemo_registry, wemo_entity
) -> None:
"""Device processes a registry subscription callback.""" """Device processes a registry subscription callback."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = False device.last_update_success = False
@ -107,7 +113,9 @@ async def test_subscription_callback(hass, pywemo_registry, wemo_entity):
assert device.last_update_success assert device.last_update_success
async def test_subscription_update_action_exception(hass, pywemo_device, wemo_entity): async def test_subscription_update_action_exception(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Device handles ActionException on get_state properly.""" """Device handles ActionException on get_state properly."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = True device.last_update_success = True
@ -125,7 +133,9 @@ async def test_subscription_update_action_exception(hass, pywemo_device, wemo_en
assert isinstance(device.last_exception, UpdateFailed) assert isinstance(device.last_exception, UpdateFailed)
async def test_subscription_update_exception(hass, pywemo_device, wemo_entity): async def test_subscription_update_exception(
hass: HomeAssistant, pywemo_device, wemo_entity
) -> None:
"""Device handles Exception on get_state properly.""" """Device handles Exception on get_state properly."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
device.last_update_success = True device.last_update_success = True
@ -144,8 +154,8 @@ async def test_subscription_update_exception(hass, pywemo_device, wemo_entity):
async def test_async_update_data_subscribed( async def test_async_update_data_subscribed(
hass, pywemo_registry, pywemo_device, wemo_entity hass: HomeAssistant, pywemo_registry, pywemo_device, wemo_entity
): ) -> None:
"""No update happens when the device is subscribed.""" """No update happens when the device is subscribed."""
device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id) device = wemo_device.async_get_coordinator(hass, wemo_entity.device_id)
pywemo_registry.is_subscribed.return_value = True pywemo_registry.is_subscribed.return_value = True
@ -154,7 +164,7 @@ async def test_async_update_data_subscribed(
pywemo_device.get_state.assert_not_called() pywemo_device.get_state.assert_not_called()
async def test_device_info(hass, wemo_entity): async def test_device_info(hass: HomeAssistant, wemo_entity) -> None:
"""Verify the DeviceInfo data is set properly.""" """Verify the DeviceInfo data is set properly."""
dr = device_registry.async_get(hass) dr = device_registry.async_get(hass)
device_entries = list(dr.devices.values()) device_entries = list(dr.devices.values())
@ -168,7 +178,7 @@ async def test_device_info(hass, wemo_entity):
assert device_entries[0].sw_version == MOCK_FIRMWARE_VERSION assert device_entries[0].sw_version == MOCK_FIRMWARE_VERSION
async def test_dli_device_info(hass, wemo_dli_entity): async def test_dli_device_info(hass: HomeAssistant, wemo_dli_entity) -> None:
"""Verify the DeviceInfo data for Digital Loggers emulated wemo device.""" """Verify the DeviceInfo data for Digital Loggers emulated wemo device."""
dr = device_registry.async_get(hass) dr = device_registry.async_get(hass)
device_entries = list(dr.devices.values()) device_entries = list(dr.devices.values())

View file

@ -63,7 +63,7 @@ async def update_ac_state(
async def test_no_appliances( async def test_no_appliances(
hass: HomeAssistant, mock_appliances_manager_api: MagicMock hass: HomeAssistant, mock_appliances_manager_api: MagicMock
): ) -> None:
"""Test the setup of the climate entities when there are no appliances available.""" """Test the setup of the climate entities when there are no appliances available."""
mock_appliances_manager_api.return_value.aircons = [] mock_appliances_manager_api.return_value.aircons = []
await init_integration(hass) await init_integration(hass)
@ -74,7 +74,7 @@ async def test_static_attributes(
hass: HomeAssistant, hass: HomeAssistant,
mock_aircon1_api: MagicMock, mock_aircon1_api: MagicMock,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test static climate attributes.""" """Test static climate attributes."""
await init_integration(hass) await init_integration(hass)
@ -121,7 +121,7 @@ async def test_dynamic_attributes(
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
mock_aircon1_api: MagicMock, mock_aircon1_api: MagicMock,
mock_aircon2_api: MagicMock, mock_aircon2_api: MagicMock,
): ) -> None:
"""Test dynamic attributes.""" """Test dynamic attributes."""
await init_integration(hass) await init_integration(hass)
@ -210,7 +210,7 @@ async def test_service_calls(
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
mock_aircon1_api: MagicMock, mock_aircon1_api: MagicMock,
mock_aircon2_api: MagicMock, mock_aircon2_api: MagicMock,
): ) -> None:
"""Test controlling the entity through service calls.""" """Test controlling the entity through service calls."""
await init_integration(hass) await init_integration(hass)

View file

@ -19,7 +19,7 @@ async def test_setup(
mock_backend_selector_api: MagicMock, mock_backend_selector_api: MagicMock,
region, region,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test setup.""" """Test setup."""
entry = await init_integration(hass, region[0]) entry = await init_integration(hass, region[0])
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1
@ -31,7 +31,7 @@ async def test_setup_region_fallback(
hass: HomeAssistant, hass: HomeAssistant,
mock_backend_selector_api: MagicMock, mock_backend_selector_api: MagicMock,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test setup when no region is available on the ConfigEntry. """Test setup when no region is available on the ConfigEntry.
This can happen after a version update, since there was no region in the first versions. This can happen after a version update, since there was no region in the first versions.
@ -54,7 +54,7 @@ async def test_setup_http_exception(
hass: HomeAssistant, hass: HomeAssistant,
mock_auth_api: MagicMock, mock_auth_api: MagicMock,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test setup with an http exception.""" """Test setup with an http exception."""
mock_auth_api.return_value.do_auth = AsyncMock( mock_auth_api.return_value.do_auth = AsyncMock(
side_effect=aiohttp.ClientConnectionError() side_effect=aiohttp.ClientConnectionError()
@ -68,7 +68,7 @@ async def test_setup_auth_failed(
hass: HomeAssistant, hass: HomeAssistant,
mock_auth_api: MagicMock, mock_auth_api: MagicMock,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test setup with failed auth.""" """Test setup with failed auth."""
mock_auth_api.return_value.do_auth = AsyncMock() mock_auth_api.return_value.do_auth = AsyncMock()
mock_auth_api.return_value.is_access_token_valid.return_value = False mock_auth_api.return_value.is_access_token_valid.return_value = False
@ -81,7 +81,7 @@ async def test_setup_fetch_appliances_failed(
hass: HomeAssistant, hass: HomeAssistant,
mock_appliances_manager_api: MagicMock, mock_appliances_manager_api: MagicMock,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
): ) -> None:
"""Test setup with failed fetch_appliances.""" """Test setup with failed fetch_appliances."""
mock_appliances_manager_api.return_value.fetch_appliances.return_value = False mock_appliances_manager_api.return_value.fetch_appliances.return_value = False
entry = await init_integration(hass) entry = await init_integration(hass)
@ -93,7 +93,7 @@ async def test_unload_entry(
hass: HomeAssistant, hass: HomeAssistant,
mock_aircon_api_instances: MagicMock, mock_aircon_api_instances: MagicMock,
mock_sensor_api_instances: MagicMock, mock_sensor_api_instances: MagicMock,
): ) -> None:
"""Test successful unload of entry.""" """Test successful unload of entry."""
entry = await init_integration(hass) entry = await init_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1 assert len(hass.config_entries.async_entries(DOMAIN)) == 1

View file

@ -10,7 +10,7 @@ async def test_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
): ) -> None:
"""Test diagnostics.""" """Test diagnostics."""
assert await get_diagnostics_for_config_entry( assert await get_diagnostics_for_config_entry(
hass, hass_client, init_integration hass, hass_client, init_integration

View file

@ -69,7 +69,7 @@ def mock_start_server_failed():
yield server yield server
async def test_form(hass, dummy_tcp_server): async def test_form(hass: HomeAssistant, dummy_tcp_server) -> None:
"""Test how we get the form.""" """Test how we get the form."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -85,7 +85,7 @@ async def test_form(hass, dummy_tcp_server):
assert result2["type"] == FlowResultType.CREATE_ENTRY assert result2["type"] == FlowResultType.CREATE_ENTRY
async def test_form_addr_in_use(hass, addr_in_use): async def test_form_addr_in_use(hass: HomeAssistant, addr_in_use) -> None:
"""Test how we handle addr_in_use error.""" """Test how we handle addr_in_use error."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -99,7 +99,9 @@ async def test_form_addr_in_use(hass, addr_in_use):
assert result2["reason"] == "addr_in_use" assert result2["reason"] == "addr_in_use"
async def test_form_start_server_failed(hass, start_server_failed): async def test_form_start_server_failed(
hass: HomeAssistant, start_server_failed
) -> None:
"""Test how we handle start_server_failed error.""" """Test how we handle start_server_failed error."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}

View file

@ -18,7 +18,9 @@ WITHINGS_MEASUREMENTS_MAP: dict[Measurement, WithingsEntityDescription] = {
async def test_binary_sensor( async def test_binary_sensor(
hass: HomeAssistant, component_factory: ComponentFactory, current_request_with_host hass: HomeAssistant,
component_factory: ComponentFactory,
current_request_with_host: None,
) -> None: ) -> None:
"""Test binary sensor.""" """Test binary sensor."""
in_bed_attribute = WITHINGS_MEASUREMENTS_MAP[Measurement.IN_BED] in_bed_attribute = WITHINGS_MEASUREMENTS_MAP[Measurement.IN_BED]

View file

@ -23,6 +23,7 @@ from .common import ComponentFactory, get_data_manager_by_user_id, new_profile_c
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
async def test_config_entry_withings_api(hass: HomeAssistant) -> None: async def test_config_entry_withings_api(hass: HomeAssistant) -> None:
@ -67,12 +68,12 @@ async def test_config_entry_withings_api(hass: HomeAssistant) -> None:
async def test_webhook_post( async def test_webhook_post(
hass: HomeAssistant, hass: HomeAssistant,
component_factory: ComponentFactory, component_factory: ComponentFactory,
aiohttp_client, aiohttp_client: ClientSessionGenerator,
user_id: int, user_id: int,
arg_user_id: Any, arg_user_id: Any,
arg_appli: Any, arg_appli: Any,
expected_code: int, expected_code: int,
current_request_with_host, current_request_with_host: None,
) -> None: ) -> None:
"""Test webhook callback.""" """Test webhook callback."""
person0 = new_profile_config("person0", user_id) person0 = new_profile_config("person0", user_id)
@ -105,8 +106,8 @@ async def test_webhook_post(
async def test_webhook_head( async def test_webhook_head(
hass: HomeAssistant, hass: HomeAssistant,
component_factory: ComponentFactory, component_factory: ComponentFactory,
aiohttp_client, aiohttp_client: ClientSessionGenerator,
current_request_with_host, current_request_with_host: None,
) -> None: ) -> None:
"""Test head method on webhook view.""" """Test head method on webhook view."""
person0 = new_profile_config("person0", 0) person0 = new_profile_config("person0", 0)
@ -123,8 +124,8 @@ async def test_webhook_head(
async def test_webhook_put( async def test_webhook_put(
hass: HomeAssistant, hass: HomeAssistant,
component_factory: ComponentFactory, component_factory: ComponentFactory,
aiohttp_client, aiohttp_client: ClientSessionGenerator,
current_request_with_host, current_request_with_host: None,
) -> None: ) -> None:
"""Test webhook callback.""" """Test webhook callback."""
person0 = new_profile_config("person0", 0) person0 = new_profile_config("person0", 0)

View file

@ -19,6 +19,8 @@ from homeassistant.helpers.config_entry_oauth2_flow import AUTH_CALLBACK_PATH
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
async def test_config_non_unique_profile(hass: HomeAssistant) -> None: async def test_config_non_unique_profile(hass: HomeAssistant) -> None:
@ -37,7 +39,10 @@ async def test_config_non_unique_profile(hass: HomeAssistant) -> None:
async def test_config_reauth_profile( async def test_config_reauth_profile(
hass: HomeAssistant, hass_client_no_auth, aioclient_mock, current_request_with_host hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
current_request_with_host: None,
) -> None: ) -> None:
"""Test reauth an existing profile re-creates the config entry.""" """Test reauth an existing profile re-creates the config entry."""
hass_config = { hass_config = {

View file

@ -119,7 +119,7 @@ async def test_auth_failure(
hass: HomeAssistant, hass: HomeAssistant,
component_factory: ComponentFactory, component_factory: ComponentFactory,
exception: Exception, exception: Exception,
current_request_with_host, current_request_with_host: None,
) -> None: ) -> None:
"""Test auth failure.""" """Test auth failure."""
person0 = new_profile_config( person0 = new_profile_config(

View file

@ -305,7 +305,9 @@ def async_assert_state_equals(
async def test_sensor_default_enabled_entities( async def test_sensor_default_enabled_entities(
hass: HomeAssistant, component_factory: ComponentFactory, current_request_with_host hass: HomeAssistant,
component_factory: ComponentFactory,
current_request_with_host: None,
) -> None: ) -> None:
"""Test entities enabled by default.""" """Test entities enabled by default."""
entity_registry: EntityRegistry = er.async_get(hass) entity_registry: EntityRegistry = er.async_get(hass)
@ -352,7 +354,9 @@ async def test_sensor_default_enabled_entities(
async def test_all_entities( async def test_all_entities(
hass: HomeAssistant, component_factory: ComponentFactory, current_request_with_host hass: HomeAssistant,
component_factory: ComponentFactory,
current_request_with_host: None,
) -> None: ) -> None:
"""Test all entities.""" """Test all entities."""
entity_registry: EntityRegistry = er.async_get(hass) entity_registry: EntityRegistry = er.async_get(hass)

View file

@ -119,7 +119,9 @@ async def test_user_flow_enters_dns_name(hass: HomeAssistant) -> None:
(ConnectionRefusedError, "cannot_connect"), (ConnectionRefusedError, "cannot_connect"),
], ],
) )
async def test_user_form_exceptions(hass, side_effect, error_base): async def test_user_form_exceptions(
hass: HomeAssistant, side_effect, error_base
) -> None:
"""Test all user exceptions in the flow.""" """Test all user exceptions in the flow."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -169,7 +171,9 @@ async def test_form_updates_unique_id(hass: HomeAssistant) -> None:
(config_entries.SOURCE_INTEGRATION_DISCOVERY, INTEGRATION_DISCOVERY), (config_entries.SOURCE_INTEGRATION_DISCOVERY, INTEGRATION_DISCOVERY),
], ],
) )
async def test_discovered_by_dhcp_connection_fails(hass, source, data): async def test_discovered_by_dhcp_connection_fails(
hass: HomeAssistant, source, data
) -> None:
"""Test we abort on connection failure.""" """Test we abort on connection failure."""
with patch( with patch(
"homeassistant.components.wiz.wizlight.getBulbConfig", "homeassistant.components.wiz.wizlight.getBulbConfig",
@ -246,8 +250,8 @@ async def test_discovered_by_dhcp_connection_fails(hass, source, data):
], ],
) )
async def test_discovered_by_dhcp_or_integration_discovery( async def test_discovered_by_dhcp_or_integration_discovery(
hass, source, data, bulb_type, extended_white_range, name hass: HomeAssistant, source, data, bulb_type, extended_white_range, name
): ) -> None:
"""Test we can configure when discovered from dhcp or discovery.""" """Test we can configure when discovered from dhcp or discovery."""
with _patch_wizlight( with _patch_wizlight(
device=None, extended_white_range=extended_white_range, bulb_type=bulb_type device=None, extended_white_range=extended_white_range, bulb_type=bulb_type
@ -291,8 +295,8 @@ async def test_discovered_by_dhcp_or_integration_discovery(
], ],
) )
async def test_discovered_by_dhcp_or_integration_discovery_updates_host( async def test_discovered_by_dhcp_or_integration_discovery_updates_host(
hass, source, data hass: HomeAssistant, source, data
): ) -> None:
"""Test dhcp or discovery updates existing host.""" """Test dhcp or discovery updates existing host."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -320,8 +324,8 @@ async def test_discovered_by_dhcp_or_integration_discovery_updates_host(
], ],
) )
async def test_discovered_by_dhcp_or_integration_discovery_avoid_waiting_for_retry( async def test_discovered_by_dhcp_or_integration_discovery_avoid_waiting_for_retry(
hass, source, data hass: HomeAssistant, source, data
): ) -> None:
"""Test dhcp or discovery kicks off setup when in retry.""" """Test dhcp or discovery kicks off setup when in retry."""
bulb = _mocked_wizlight(None, None, FAKE_SOCKET) bulb = _mocked_wizlight(None, None, FAKE_SOCKET)
bulb.getMac = AsyncMock(side_effect=OSError) bulb.getMac = AsyncMock(side_effect=OSError)
@ -516,7 +520,7 @@ async def test_discovery_with_firmware_update(hass: HomeAssistant) -> None:
(config_entries.SOURCE_INTEGRATION_DISCOVERY, INTEGRATION_DISCOVERY), (config_entries.SOURCE_INTEGRATION_DISCOVERY, INTEGRATION_DISCOVERY),
], ],
) )
async def test_discovered_during_onboarding(hass, source, data): async def test_discovered_during_onboarding(hass: HomeAssistant, source, data) -> None:
"""Test dhcp or discovery during onboarding creates the config entry.""" """Test dhcp or discovery during onboarding creates the config entry."""
with _patch_wizlight(), patch( with _patch_wizlight(), patch(
"homeassistant.components.wiz.async_setup_entry", "homeassistant.components.wiz.async_setup_entry",

View file

@ -10,7 +10,7 @@ async def test_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
): ) -> None:
"""Test diagnostics.""" """Test diagnostics."""
assert await get_diagnostics_for_config_entry( assert await get_diagnostics_for_config_entry(
hass, hass_client, init_integration hass, hass_client, init_integration

View file

@ -1,6 +1,7 @@
"""The test for the World clock sensor platform.""" """The test for the World clock sensor platform."""
import pytest import pytest
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -11,7 +12,7 @@ def time_zone():
return dt_util.get_time_zone("America/New_York") return dt_util.get_time_zone("America/New_York")
async def test_time(hass, time_zone): async def test_time(hass: HomeAssistant, time_zone) -> None:
"""Test the time at a different location.""" """Test the time at a different location."""
config = {"sensor": {"platform": "worldclock", "time_zone": "America/New_York"}} config = {"sensor": {"platform": "worldclock", "time_zone": "America/New_York"}}
@ -28,7 +29,7 @@ async def test_time(hass, time_zone):
assert state.state == dt_util.now(time_zone=time_zone).strftime("%H:%M") assert state.state == dt_util.now(time_zone=time_zone).strftime("%H:%M")
async def test_time_format(hass, time_zone): async def test_time_format(hass: HomeAssistant, time_zone) -> None:
"""Test time_format setting.""" """Test time_format setting."""
time_format = "%a, %b %d, %Y %I:%M %p" time_format = "%a, %b %d, %Y %I:%M %p"
config = { config = {

View file

@ -2,6 +2,8 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import re import re
import requests_mock
import homeassistant.components.wsdot.sensor as wsdot import homeassistant.components.wsdot.sensor as wsdot
from homeassistant.components.wsdot.sensor import ( from homeassistant.components.wsdot.sensor import (
ATTR_DESCRIPTION, ATTR_DESCRIPTION,
@ -30,7 +32,7 @@ async def test_setup_with_config(hass: HomeAssistant) -> None:
assert await async_setup_component(hass, "sensor", {"wsdot": config}) assert await async_setup_component(hass, "sensor", {"wsdot": config})
async def test_setup(hass, requests_mock): async def test_setup(hass: HomeAssistant, requests_mock: requests_mock.Mocker) -> None:
"""Test for operational WSDOT sensor with proper attributes.""" """Test for operational WSDOT sensor with proper attributes."""
entities = [] entities = []

View file

@ -8,6 +8,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
CLIENT_ID = "1234" CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"
@ -25,8 +27,11 @@ async def test_abort_if_existing_entry(hass: HomeAssistant) -> None:
async def test_full_flow( async def test_full_flow(
hass, hass_client_no_auth, aioclient_mock, current_request_with_host hass: HomeAssistant,
): hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
current_request_with_host: None,
) -> None:
"""Check full flow.""" """Check full flow."""
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,

View file

@ -9,6 +9,7 @@ from homeassistant.components.device_tracker import DOMAIN
import homeassistant.components.xiaomi.device_tracker as xiaomi import homeassistant.components.xiaomi.device_tracker as xiaomi
from homeassistant.components.xiaomi.device_tracker import get_scanner from homeassistant.components.xiaomi.device_tracker import get_scanner
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME
from homeassistant.core import HomeAssistant
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -147,7 +148,7 @@ def mocked_requests(*args, **kwargs):
"homeassistant.components.xiaomi.device_tracker.XiaomiDeviceScanner", "homeassistant.components.xiaomi.device_tracker.XiaomiDeviceScanner",
return_value=MagicMock(), return_value=MagicMock(),
) )
async def test_config(xiaomi_mock, hass): async def test_config(xiaomi_mock, hass: HomeAssistant) -> None:
"""Testing minimal configuration.""" """Testing minimal configuration."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DOMAIN: xiaomi.PLATFORM_SCHEMA(
@ -172,7 +173,7 @@ async def test_config(xiaomi_mock, hass):
"homeassistant.components.xiaomi.device_tracker.XiaomiDeviceScanner", "homeassistant.components.xiaomi.device_tracker.XiaomiDeviceScanner",
return_value=MagicMock(), return_value=MagicMock(),
) )
async def test_config_full(xiaomi_mock, hass): async def test_config_full(xiaomi_mock, hass: HomeAssistant) -> None:
"""Testing full configuration.""" """Testing full configuration."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DOMAIN: xiaomi.PLATFORM_SCHEMA(
@ -196,7 +197,7 @@ async def test_config_full(xiaomi_mock, hass):
@patch("requests.get", side_effect=mocked_requests) @patch("requests.get", side_effect=mocked_requests)
@patch("requests.post", side_effect=mocked_requests) @patch("requests.post", side_effect=mocked_requests)
async def test_invalid_credential(mock_get, mock_post, hass): async def test_invalid_credential(mock_get, mock_post, hass: HomeAssistant) -> None:
"""Testing invalid credential handling.""" """Testing invalid credential handling."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DOMAIN: xiaomi.PLATFORM_SCHEMA(
@ -213,7 +214,7 @@ async def test_invalid_credential(mock_get, mock_post, hass):
@patch("requests.get", side_effect=mocked_requests) @patch("requests.get", side_effect=mocked_requests)
@patch("requests.post", side_effect=mocked_requests) @patch("requests.post", side_effect=mocked_requests)
async def test_valid_credential(mock_get, mock_post, hass): async def test_valid_credential(mock_get, mock_post, hass: HomeAssistant) -> None:
"""Testing valid refresh.""" """Testing valid refresh."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DOMAIN: xiaomi.PLATFORM_SCHEMA(
@ -234,7 +235,7 @@ async def test_valid_credential(mock_get, mock_post, hass):
@patch("requests.get", side_effect=mocked_requests) @patch("requests.get", side_effect=mocked_requests)
@patch("requests.post", side_effect=mocked_requests) @patch("requests.post", side_effect=mocked_requests)
async def test_token_timed_out(mock_get, mock_post, hass): async def test_token_timed_out(mock_get, mock_post, hass: HomeAssistant) -> None:
"""Testing refresh with a timed out token. """Testing refresh with a timed out token.
New token is requested and list is downloaded a second time. New token is requested and list is downloaded a second time.

View file

@ -262,7 +262,7 @@ async def test_smoke(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_unavailable(hass): async def test_unavailable(hass: HomeAssistant) -> None:
"""Test normal device goes to unavailable after 60 minutes.""" """Test normal device goes to unavailable after 60 minutes."""
start_monotonic = time.monotonic() start_monotonic = time.monotonic()
@ -314,7 +314,7 @@ async def test_unavailable(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_sleepy_device(hass): async def test_sleepy_device(hass: HomeAssistant) -> None:
"""Test sleepy device does not go to unavailable after 60 minutes.""" """Test sleepy device does not go to unavailable after 60 minutes."""
start_monotonic = time.monotonic() start_monotonic = time.monotonic()

View file

@ -194,8 +194,8 @@ async def test_async_step_bluetooth_valid_device_legacy_encryption_wrong_key(
async def test_async_step_bluetooth_valid_device_legacy_encryption_wrong_key_length( async def test_async_step_bluetooth_valid_device_legacy_encryption_wrong_key_length(
hass, hass: HomeAssistant,
): ) -> None:
"""Test discovery via bluetooth with a valid device, with legacy encryption and wrong key length.""" """Test discovery via bluetooth with a valid device, with legacy encryption and wrong key length."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -640,8 +640,8 @@ async def test_async_step_user_with_found_devices_legacy_encryption(
async def test_async_step_user_with_found_devices_legacy_encryption_wrong_key( async def test_async_step_user_with_found_devices_legacy_encryption_wrong_key(
hass, hass: HomeAssistant,
): ) -> None:
"""Test setup from service info cache with devices found, with legacy encryption and wrong key.""" """Test setup from service info cache with devices found, with legacy encryption and wrong key."""
with patch( with patch(
"homeassistant.components.xiaomi_ble.config_flow.async_discovered_service_info", "homeassistant.components.xiaomi_ble.config_flow.async_discovered_service_info",
@ -685,8 +685,8 @@ async def test_async_step_user_with_found_devices_legacy_encryption_wrong_key(
async def test_async_step_user_with_found_devices_legacy_encryption_wrong_key_length( async def test_async_step_user_with_found_devices_legacy_encryption_wrong_key_length(
hass, hass: HomeAssistant,
): ) -> None:
"""Test setup from service info cache with devices found, with legacy encryption and wrong key length.""" """Test setup from service info cache with devices found, with legacy encryption and wrong key length."""
with patch( with patch(
"homeassistant.components.xiaomi_ble.config_flow.async_discovered_service_info", "homeassistant.components.xiaomi_ble.config_flow.async_discovered_service_info",

View file

@ -179,7 +179,7 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None:
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_if_fires_on_motion_detected(hass, calls): async def test_if_fires_on_motion_detected(hass: HomeAssistant, calls) -> None:
"""Test for motion event trigger firing.""" """Test for motion event trigger firing."""
mac = "DE:70:E8:B2:39:0C" mac = "DE:70:E8:B2:39:0C"
entry = await _async_setup_xiaomi_device(hass, mac) entry = await _async_setup_xiaomi_device(hass, mac)
@ -332,7 +332,7 @@ async def test_automation_with_invalid_trigger_event_property(
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_triggers_for_invalid__model(hass, calls): async def test_triggers_for_invalid__model(hass: HomeAssistant, calls) -> None:
"""Test invalid model doesn't return triggers.""" """Test invalid model doesn't return triggers."""
mac = "DE:70:E8:B2:39:0C" mac = "DE:70:E8:B2:39:0C"
entry = await _async_setup_xiaomi_device(hass, mac) entry = await _async_setup_xiaomi_device(hass, mac)

View file

@ -48,6 +48,7 @@ from homeassistant.const import (
CONF_TOKEN, CONF_TOKEN,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from . import TEST_MAC from . import TEST_MAC
@ -220,7 +221,7 @@ def mirobo_is_on_fixture():
yield mock_vacuum yield mock_vacuum
async def test_xiaomi_exceptions(hass, mock_mirobo_is_on): async def test_xiaomi_exceptions(hass: HomeAssistant, mock_mirobo_is_on) -> None:
"""Test error logging on exceptions.""" """Test error logging on exceptions."""
entity_name = "test_vacuum_cleaner_error" entity_name = "test_vacuum_cleaner_error"
entity_id = await setup_component(hass, entity_name) entity_id = await setup_component(hass, entity_name)
@ -251,7 +252,9 @@ async def test_xiaomi_exceptions(hass, mock_mirobo_is_on):
assert mock_mirobo_is_on.status.call_count == 1 assert mock_mirobo_is_on.status.call_count == 1
async def test_xiaomi_vacuum_services(hass, mock_mirobo_is_got_error): async def test_xiaomi_vacuum_services(
hass: HomeAssistant, mock_mirobo_is_got_error
) -> None:
"""Test vacuum supported features.""" """Test vacuum supported features."""
entity_name = "test_vacuum_cleaner_1" entity_name = "test_vacuum_cleaner_1"
entity_id = await setup_component(hass, entity_name) entity_id = await setup_component(hass, entity_name)
@ -442,7 +445,7 @@ async def test_xiaomi_vacuum_services(hass, mock_mirobo_is_got_error):
], ],
) )
async def test_xiaomi_specific_services( async def test_xiaomi_specific_services(
hass, hass: HomeAssistant,
mock_mirobo_is_on, mock_mirobo_is_on,
service, service,
service_data, service_data,
@ -450,7 +453,7 @@ async def test_xiaomi_specific_services(
device_method_call, device_method_call,
error, error,
status_calls, status_calls,
): ) -> None:
"""Test vacuum supported features.""" """Test vacuum supported features."""
entity_name = "test_vacuum_cleaner_2" entity_name = "test_vacuum_cleaner_2"
entity_id = await setup_component(hass, entity_name) entity_id = await setup_component(hass, entity_name)
@ -490,7 +493,9 @@ async def test_xiaomi_specific_services(
mock_mirobo_is_on.reset_mock() mock_mirobo_is_on.reset_mock()
async def test_xiaomi_vacuum_fanspeeds(hass, caplog, mock_mirobo_fanspeeds): async def test_xiaomi_vacuum_fanspeeds(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_mirobo_fanspeeds
) -> None:
"""Test Xiaomi vacuum fanspeeds.""" """Test Xiaomi vacuum fanspeeds."""
entity_name = "test_vacuum_cleaner_2" entity_name = "test_vacuum_cleaner_2"
entity_id = await setup_component(hass, entity_name) entity_id = await setup_component(hass, entity_name)

View file

@ -6,6 +6,7 @@ import pytest
import homeassistant.components.media_player as mp import homeassistant.components.media_player as mp
from homeassistant.components.yamaha import media_player as yamaha from homeassistant.components.yamaha import media_player as yamaha
from homeassistant.components.yamaha.const import DOMAIN from homeassistant.components.yamaha.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -47,7 +48,7 @@ def device_fixture(main_zone):
yield device yield device
async def test_setup_host(hass, device, main_zone): async def test_setup_host(hass: HomeAssistant, device, main_zone) -> None:
"""Test set up integration with host.""" """Test set up integration with host."""
assert await async_setup_component(hass, mp.DOMAIN, CONFIG) assert await async_setup_component(hass, mp.DOMAIN, CONFIG)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -58,7 +59,7 @@ async def test_setup_host(hass, device, main_zone):
assert state.state == "off" assert state.state == "off"
async def test_setup_no_host(hass, device, main_zone): async def test_setup_no_host(hass: HomeAssistant, device, main_zone) -> None:
"""Test set up integration without host.""" """Test set up integration without host."""
with patch("rxv.find", return_value=[device]): with patch("rxv.find", return_value=[device]):
assert await async_setup_component( assert await async_setup_component(
@ -72,7 +73,7 @@ async def test_setup_no_host(hass, device, main_zone):
assert state.state == "off" assert state.state == "off"
async def test_setup_discovery(hass, device, main_zone): async def test_setup_discovery(hass: HomeAssistant, device, main_zone) -> None:
"""Test set up integration via discovery.""" """Test set up integration via discovery."""
discovery_info = { discovery_info = {
"name": "Yamaha Receiver", "name": "Yamaha Receiver",
@ -91,7 +92,7 @@ async def test_setup_discovery(hass, device, main_zone):
assert state.state == "off" assert state.state == "off"
async def test_setup_zone_ignore(hass, device, main_zone): async def test_setup_zone_ignore(hass: HomeAssistant, device, main_zone) -> None:
"""Test set up integration without host.""" """Test set up integration without host."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -111,7 +112,7 @@ async def test_setup_zone_ignore(hass, device, main_zone):
assert state is None assert state is None
async def test_enable_output(hass, device, main_zone): async def test_enable_output(hass: HomeAssistant, device, main_zone) -> None:
"""Test enable output service.""" """Test enable output service."""
assert await async_setup_component(hass, mp.DOMAIN, CONFIG) assert await async_setup_component(hass, mp.DOMAIN, CONFIG)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -142,7 +143,7 @@ async def test_enable_output(hass, device, main_zone):
], ],
) )
@pytest.mark.usefixtures("device") @pytest.mark.usefixtures("device")
async def test_menu_cursor(hass, main_zone, cursor, method): async def test_menu_cursor(hass: HomeAssistant, main_zone, cursor, method) -> None:
"""Verify that the correct menu method is called for the menu_cursor service.""" """Verify that the correct menu method is called for the menu_cursor service."""
assert await async_setup_component(hass, mp.DOMAIN, CONFIG) assert await async_setup_component(hass, mp.DOMAIN, CONFIG)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -156,7 +157,9 @@ async def test_menu_cursor(hass, main_zone, cursor, method):
getattr(main_zone, method).assert_called_once_with() getattr(main_zone, method).assert_called_once_with()
async def test_select_scene(hass, device, main_zone, caplog): async def test_select_scene(
hass: HomeAssistant, device, main_zone, caplog: pytest.LogCaptureFixture
) -> None:
"""Test select scene service.""" """Test select scene service."""
scene_prop = PropertyMock(return_value=None) scene_prop = PropertyMock(return_value=None)
type(main_zone).scene = scene_prop type(main_zone).scene = scene_prop

View file

@ -1,5 +1,4 @@
"""Test config flow.""" """Test config flow."""
from unittest.mock import patch from unittest.mock import patch
from aiomusiccast import MusicCastConnectionException from aiomusiccast import MusicCastConnectionException
@ -10,6 +9,7 @@ from homeassistant.components import ssdp
from homeassistant.components.yamaha_musiccast.const import DOMAIN from homeassistant.components.yamaha_musiccast.const import DOMAIN
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -125,8 +125,8 @@ def mock_empty_discovery_information():
async def test_user_input_device_not_found( async def test_user_input_device_not_found(
hass, mock_get_device_info_mc_exception, mock_get_source_ip hass: HomeAssistant, mock_get_device_info_mc_exception, mock_get_source_ip
): ) -> None:
"""Test when user specifies a non-existing device.""" """Test when user specifies a non-existing device."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -143,8 +143,8 @@ async def test_user_input_device_not_found(
async def test_user_input_non_yamaha_device_found( async def test_user_input_non_yamaha_device_found(
hass, mock_get_device_info_invalid, mock_get_source_ip hass: HomeAssistant, mock_get_device_info_invalid, mock_get_source_ip
): ) -> None:
"""Test when user specifies an existing device, which does not provide the musiccast API.""" """Test when user specifies an existing device, which does not provide the musiccast API."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -161,8 +161,8 @@ async def test_user_input_non_yamaha_device_found(
async def test_user_input_device_already_existing( async def test_user_input_device_already_existing(
hass, mock_get_device_info_valid, mock_get_source_ip hass: HomeAssistant, mock_get_device_info_valid, mock_get_source_ip
): ) -> None:
"""Test when user specifies an existing device.""" """Test when user specifies an existing device."""
mock_entry = MockConfigEntry( mock_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -185,8 +185,8 @@ async def test_user_input_device_already_existing(
async def test_user_input_unknown_error( async def test_user_input_unknown_error(
hass, mock_get_device_info_exception, mock_get_source_ip hass: HomeAssistant, mock_get_device_info_exception, mock_get_source_ip
): ) -> None:
"""Test when user specifies an existing device, which does not provide the musiccast API.""" """Test when user specifies an existing device, which does not provide the musiccast API."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -203,11 +203,11 @@ async def test_user_input_unknown_error(
async def test_user_input_device_found( async def test_user_input_device_found(
hass, hass: HomeAssistant,
mock_get_device_info_valid, mock_get_device_info_valid,
mock_valid_discovery_information, mock_valid_discovery_information,
mock_get_source_ip, mock_get_source_ip,
): ) -> None:
"""Test when user specifies an existing device.""" """Test when user specifies an existing device."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -229,11 +229,11 @@ async def test_user_input_device_found(
async def test_user_input_device_found_no_ssdp( async def test_user_input_device_found_no_ssdp(
hass, hass: HomeAssistant,
mock_get_device_info_valid, mock_get_device_info_valid,
mock_empty_discovery_information, mock_empty_discovery_information,
mock_get_source_ip, mock_get_source_ip,
): ) -> None:
"""Test when user specifies an existing device, which no discovery data are present for.""" """Test when user specifies an existing device, which no discovery data are present for."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -257,7 +257,9 @@ async def test_user_input_device_found_no_ssdp(
# SSDP Flows # SSDP Flows
async def test_ssdp_discovery_failed(hass, mock_ssdp_no_yamaha, mock_get_source_ip): async def test_ssdp_discovery_failed(
hass: HomeAssistant, mock_ssdp_no_yamaha, mock_get_source_ip
) -> None:
"""Test when an SSDP discovered device is not a musiccast device.""" """Test when an SSDP discovered device is not a musiccast device."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -278,8 +280,8 @@ async def test_ssdp_discovery_failed(hass, mock_ssdp_no_yamaha, mock_get_source_
async def test_ssdp_discovery_successful_add_device( async def test_ssdp_discovery_successful_add_device(
hass, mock_ssdp_yamaha, mock_get_source_ip hass: HomeAssistant, mock_ssdp_yamaha, mock_get_source_ip
): ) -> None:
"""Test when the SSDP discovered device is a musiccast device and the user confirms it.""" """Test when the SSDP discovered device is a musiccast device and the user confirms it."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -314,8 +316,8 @@ async def test_ssdp_discovery_successful_add_device(
async def test_ssdp_discovery_existing_device_update( async def test_ssdp_discovery_existing_device_update(
hass, mock_ssdp_yamaha, mock_get_source_ip hass: HomeAssistant, mock_ssdp_yamaha, mock_get_source_ip
): ) -> None:
"""Test when the SSDP discovered device is a musiccast device, but it already exists with another IP.""" """Test when the SSDP discovered device is a musiccast device, but it already exists with another IP."""
mock_entry = MockConfigEntry( mock_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -1,5 +1,4 @@
"""Tests for the yandex transport platform.""" """Tests for the yandex transport platform."""
import json import json
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
@ -7,6 +6,7 @@ import pytest
import homeassistant.components.sensor as sensor import homeassistant.components.sensor as sensor
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -80,33 +80,37 @@ async def assert_setup_sensor(hass, config, count=1):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_setup_platform_valid_config(hass, mock_requester_bus): async def test_setup_platform_valid_config(
hass: HomeAssistant, mock_requester_bus
) -> None:
"""Test that sensor is set up properly with valid config.""" """Test that sensor is set up properly with valid config."""
await assert_setup_sensor(hass, TEST_BUS_CONFIG) await assert_setup_sensor(hass, TEST_BUS_CONFIG)
async def test_setup_platform_invalid_config(hass, mock_requester_bus): async def test_setup_platform_invalid_config(
hass: HomeAssistant, mock_requester_bus
) -> None:
"""Check an invalid configuration.""" """Check an invalid configuration."""
await assert_setup_sensor( await assert_setup_sensor(
hass, {"sensor": {"platform": "yandex_transport", "stopid": 1234}}, count=0 hass, {"sensor": {"platform": "yandex_transport", "stopid": 1234}}, count=0
) )
async def test_name(hass, mock_requester_bus): async def test_name(hass: HomeAssistant, mock_requester_bus) -> None:
"""Return the name if set in the configuration.""" """Return the name if set in the configuration."""
await assert_setup_sensor(hass, TEST_BUS_CONFIG) await assert_setup_sensor(hass, TEST_BUS_CONFIG)
state = hass.states.get("sensor.test_name") state = hass.states.get("sensor.test_name")
assert state.name == TEST_BUS_CONFIG["sensor"][CONF_NAME] assert state.name == TEST_BUS_CONFIG["sensor"][CONF_NAME]
async def test_state(hass, mock_requester_bus): async def test_state(hass: HomeAssistant, mock_requester_bus) -> None:
"""Return the contents of _state.""" """Return the contents of _state."""
await assert_setup_sensor(hass, TEST_BUS_CONFIG) await assert_setup_sensor(hass, TEST_BUS_CONFIG)
state = hass.states.get("sensor.test_name") state = hass.states.get("sensor.test_name")
assert state.state == BUS_RESULT_STATE assert state.state == BUS_RESULT_STATE
async def test_filtered_attributes(hass, mock_requester_bus): async def test_filtered_attributes(hass: HomeAssistant, mock_requester_bus) -> None:
"""Return the contents of attributes.""" """Return the contents of attributes."""
await assert_setup_sensor(hass, TEST_BUS_CONFIG) await assert_setup_sensor(hass, TEST_BUS_CONFIG)
state = hass.states.get("sensor.test_name") state = hass.states.get("sensor.test_name")
@ -114,7 +118,9 @@ async def test_filtered_attributes(hass, mock_requester_bus):
assert state_attrs == FILTERED_ATTRS assert state_attrs == FILTERED_ATTRS
async def test_suburban_trains(hass, mock_requester_suburban_train): async def test_suburban_trains(
hass: HomeAssistant, mock_requester_suburban_train
) -> None:
"""Return the contents of _state for suburban.""" """Return the contents of _state for suburban."""
await assert_setup_sensor(hass, TEST_SUBURBAN_CONFIG) await assert_setup_sensor(hass, TEST_SUBURBAN_CONFIG)
state = hass.states.get("sensor.test_name") state = hass.states.get("sensor.test_name")

View file

@ -18,7 +18,7 @@ from . import (
ENTITY_BINARY_SENSOR = f"binary_sensor.{NAME}_nightlight" ENTITY_BINARY_SENSOR = f"binary_sensor.{NAME}_nightlight"
async def test_nightlight(hass: HomeAssistant): async def test_nightlight(hass: HomeAssistant) -> None:
"""Test nightlight sensor.""" """Test nightlight sensor."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
with _patch_discovery(), patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb): with _patch_discovery(), patch(f"{MODULE}.AsyncBulb", return_value=mocked_bulb):

View file

@ -59,7 +59,7 @@ SSDP_INFO = ssdp.SsdpServiceInfo(
) )
async def test_discovery(hass: HomeAssistant): async def test_discovery(hass: HomeAssistant) -> None:
"""Test setting up discovery.""" """Test setting up discovery."""
with _patch_discovery(), _patch_discovery_interval(): with _patch_discovery(), _patch_discovery_interval():
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -116,7 +116,7 @@ async def test_discovery(hass: HomeAssistant):
assert result2["reason"] == "no_devices_found" assert result2["reason"] == "no_devices_found"
async def test_discovery_with_existing_device_present(hass: HomeAssistant): async def test_discovery_with_existing_device_present(hass: HomeAssistant) -> None:
"""Test setting up discovery.""" """Test setting up discovery."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_ID: "0x000000000099999", CONF_HOST: "4.4.4.4"} domain=DOMAIN, data={CONF_ID: "0x000000000099999", CONF_HOST: "4.4.4.4"}
@ -194,7 +194,7 @@ async def test_discovery_with_existing_device_present(hass: HomeAssistant):
assert result2["reason"] == "no_devices_found" assert result2["reason"] == "no_devices_found"
async def test_discovery_no_device(hass: HomeAssistant): async def test_discovery_no_device(hass: HomeAssistant) -> None:
"""Test discovery without device.""" """Test discovery without device."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -209,7 +209,7 @@ async def test_discovery_no_device(hass: HomeAssistant):
assert result2["reason"] == "no_devices_found" assert result2["reason"] == "no_devices_found"
async def test_import(hass: HomeAssistant): async def test_import(hass: HomeAssistant) -> None:
"""Test import from yaml.""" """Test import from yaml."""
config = { config = {
CONF_NAME: DEFAULT_NAME, CONF_NAME: DEFAULT_NAME,
@ -269,7 +269,7 @@ async def test_import(hass: HomeAssistant):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_manual(hass: HomeAssistant): async def test_manual(hass: HomeAssistant) -> None:
"""Test manually setup.""" """Test manually setup."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -339,7 +339,7 @@ async def test_manual(hass: HomeAssistant):
assert result2["reason"] == "already_configured" assert result2["reason"] == "already_configured"
async def test_options(hass: HomeAssistant): async def test_options(hass: HomeAssistant) -> None:
"""Test options flow.""" """Test options flow."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -382,7 +382,7 @@ async def test_options(hass: HomeAssistant):
assert hass.states.get(f"light.{NAME}_nightlight") is not None assert hass.states.get(f"light.{NAME}_nightlight") is not None
async def test_options_unknown_model(hass: HomeAssistant): async def test_options_unknown_model(hass: HomeAssistant) -> None:
"""Test options flow with an unknown model.""" """Test options flow with an unknown model."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -424,7 +424,7 @@ async def test_options_unknown_model(hass: HomeAssistant):
assert hass.states.get(f"light.{NAME}_nightlight") is not None assert hass.states.get(f"light.{NAME}_nightlight") is not None
async def test_manual_no_capabilities(hass: HomeAssistant): async def test_manual_no_capabilities(hass: HomeAssistant) -> None:
"""Test manually setup without successful get_capabilities.""" """Test manually setup without successful get_capabilities."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -546,7 +546,7 @@ async def test_discovered_by_homekit_and_dhcp(hass: HomeAssistant) -> None:
), ),
], ],
) )
async def test_discovered_by_dhcp_or_homekit(hass, source, data): async def test_discovered_by_dhcp_or_homekit(hass: HomeAssistant, source, data) -> None:
"""Test we can setup when discovered from dhcp or homekit.""" """Test we can setup when discovered from dhcp or homekit."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
@ -614,7 +614,9 @@ async def test_discovered_by_dhcp_or_homekit(hass, source, data):
), ),
], ],
) )
async def test_discovered_by_dhcp_or_homekit_failed_to_get_id(hass, source, data): async def test_discovered_by_dhcp_or_homekit_failed_to_get_id(
hass: HomeAssistant, source, data
) -> None:
"""Test we abort if we cannot get the unique id when discovered from dhcp or homekit.""" """Test we abort if we cannot get the unique id when discovered from dhcp or homekit."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
@ -738,7 +740,7 @@ async def test_discovered_zeroconf(hass: HomeAssistant) -> None:
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_discovery_updates_ip(hass: HomeAssistant): async def test_discovery_updates_ip(hass: HomeAssistant) -> None:
"""Test discovery updates ip.""" """Test discovery updates ip."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "1.2.2.3"}, unique_id=ID domain=DOMAIN, data={CONF_HOST: "1.2.2.3"}, unique_id=ID
@ -761,7 +763,9 @@ async def test_discovery_updates_ip(hass: HomeAssistant):
assert config_entry.data[CONF_HOST] == IP_ADDRESS assert config_entry.data[CONF_HOST] == IP_ADDRESS
async def test_discovery_updates_ip_no_reload_setup_in_progress(hass: HomeAssistant): async def test_discovery_updates_ip_no_reload_setup_in_progress(
hass: HomeAssistant,
) -> None:
"""Test discovery updates ip does not reload if setup is an an error state.""" """Test discovery updates ip does not reload if setup is an an error state."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -790,7 +794,7 @@ async def test_discovery_updates_ip_no_reload_setup_in_progress(hass: HomeAssist
assert len(mock_setup_entry.mock_calls) == 0 assert len(mock_setup_entry.mock_calls) == 0
async def test_discovery_adds_missing_ip_id_only(hass: HomeAssistant): async def test_discovery_adds_missing_ip_id_only(hass: HomeAssistant) -> None:
"""Test discovery adds missing ip.""" """Test discovery adds missing ip."""
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_ID: ID}) config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_ID: ID})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
@ -834,7 +838,7 @@ async def test_discovery_adds_missing_ip_id_only(hass: HomeAssistant):
), ),
], ],
) )
async def test_discovered_during_onboarding(hass, source, data): async def test_discovered_during_onboarding(hass: HomeAssistant, source, data) -> None:
"""Test we create a config entry when discovered during onboarding.""" """Test we create a config entry when discovered during onboarding."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
with _patch_discovery(), _patch_discovery_interval(), patch( with _patch_discovery(), _patch_discovery_interval(), patch(

View file

@ -51,7 +51,7 @@ from . import (
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
async def test_ip_changes_fallback_discovery(hass: HomeAssistant): async def test_ip_changes_fallback_discovery(hass: HomeAssistant) -> None:
"""Test Yeelight ip changes and we fallback to discovery.""" """Test Yeelight ip changes and we fallback to discovery."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_ID: ID, CONF_HOST: "5.5.5.5"}, unique_id=ID domain=DOMAIN, data={CONF_ID: ID, CONF_HOST: "5.5.5.5"}, unique_id=ID
@ -96,7 +96,7 @@ async def test_ip_changes_fallback_discovery(hass: HomeAssistant):
assert entity_registry.async_get(binary_sensor_entity_id) is not None assert entity_registry.async_get(binary_sensor_entity_id) is not None
async def test_ip_changes_id_missing_cannot_fallback(hass: HomeAssistant): async def test_ip_changes_id_missing_cannot_fallback(hass: HomeAssistant) -> None:
"""Test Yeelight ip changes and we fallback to discovery.""" """Test Yeelight ip changes and we fallback to discovery."""
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "5.5.5.5"}) config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "5.5.5.5"})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
@ -112,7 +112,7 @@ async def test_ip_changes_id_missing_cannot_fallback(hass: HomeAssistant):
assert config_entry.state is ConfigEntryState.SETUP_RETRY assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_setup_discovery(hass: HomeAssistant): async def test_setup_discovery(hass: HomeAssistant) -> None:
"""Test setting up Yeelight by discovery.""" """Test setting up Yeelight by discovery."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA} domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA}
@ -154,7 +154,7 @@ _ADAPTERS_WITH_MANUAL_CONFIG = [
async def test_setup_discovery_with_manually_configured_network_adapter( async def test_setup_discovery_with_manually_configured_network_adapter(
hass: HomeAssistant, hass: HomeAssistant,
): ) -> None:
"""Test setting up Yeelight by discovery with a manually configured network adapter.""" """Test setting up Yeelight by discovery with a manually configured network adapter."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA} domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA}
@ -209,8 +209,8 @@ _ADAPTERS_WITH_MANUAL_CONFIG_ONE_FAILING = [
async def test_setup_discovery_with_manually_configured_network_adapter_one_fails( async def test_setup_discovery_with_manually_configured_network_adapter_one_fails(
hass: HomeAssistant, caplog hass: HomeAssistant, caplog: pytest.LogCaptureFixture
): ) -> None:
"""Test setting up Yeelight by discovery with a manually configured network adapter with one that fails to bind.""" """Test setting up Yeelight by discovery with a manually configured network adapter with one that fails to bind."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA} domain=DOMAIN, data={CONF_HOST: IP_ADDRESS, **CONFIG_ENTRY_DATA}
@ -244,7 +244,7 @@ async def test_setup_discovery_with_manually_configured_network_adapter_one_fail
assert f"Failed to setup listener for ('{FAIL_TO_BIND_IP}', 0)" in caplog.text assert f"Failed to setup listener for ('{FAIL_TO_BIND_IP}', 0)" in caplog.text
async def test_setup_import(hass: HomeAssistant): async def test_setup_import(hass: HomeAssistant) -> None:
"""Test import from yaml.""" """Test import from yaml."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
name = "yeelight" name = "yeelight"
@ -273,7 +273,7 @@ async def test_setup_import(hass: HomeAssistant):
assert entry.data[CONF_ID] == "0x000000000015243f" assert entry.data[CONF_ID] == "0x000000000015243f"
async def test_unique_ids_device(hass: HomeAssistant): async def test_unique_ids_device(hass: HomeAssistant) -> None:
"""Test Yeelight unique IDs from yeelight device IDs.""" """Test Yeelight unique IDs from yeelight device IDs."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -298,7 +298,7 @@ async def test_unique_ids_device(hass: HomeAssistant):
assert entity_registry.async_get(ENTITY_AMBILIGHT).unique_id == f"{ID}-ambilight" assert entity_registry.async_get(ENTITY_AMBILIGHT).unique_id == f"{ID}-ambilight"
async def test_unique_ids_entry(hass: HomeAssistant): async def test_unique_ids_entry(hass: HomeAssistant) -> None:
"""Test Yeelight unique IDs from entry IDs.""" """Test Yeelight unique IDs from entry IDs."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -329,7 +329,7 @@ async def test_unique_ids_entry(hass: HomeAssistant):
) )
async def test_bulb_off_while_adding_in_ha(hass: HomeAssistant): async def test_bulb_off_while_adding_in_ha(hass: HomeAssistant) -> None:
"""Test Yeelight off while adding to ha, for example on HA start.""" """Test Yeelight off while adding to ha, for example on HA start."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={**CONFIG_ENTRY_DATA, CONF_HOST: IP_ADDRESS}, unique_id=ID domain=DOMAIN, data={**CONFIG_ENTRY_DATA, CONF_HOST: IP_ADDRESS}, unique_id=ID
@ -435,7 +435,7 @@ async def test_unload_before_discovery(
assert config_entry.state is ConfigEntryState.NOT_LOADED assert config_entry.state is ConfigEntryState.NOT_LOADED
async def test_async_listen_error_has_host_with_id(hass: HomeAssistant): async def test_async_listen_error_has_host_with_id(hass: HomeAssistant) -> None:
"""Test the async listen error.""" """Test the async listen error."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_ID: ID, CONF_HOST: "127.0.0.1"} domain=DOMAIN, data={CONF_ID: ID, CONF_HOST: "127.0.0.1"}
@ -452,7 +452,7 @@ async def test_async_listen_error_has_host_with_id(hass: HomeAssistant):
assert config_entry.state is ConfigEntryState.SETUP_RETRY assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_async_listen_error_has_host_without_id(hass: HomeAssistant): async def test_async_listen_error_has_host_without_id(hass: HomeAssistant) -> None:
"""Test the async listen error but no id.""" """Test the async listen error but no id."""
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}) config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "127.0.0.1"})
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
@ -467,7 +467,7 @@ async def test_async_listen_error_has_host_without_id(hass: HomeAssistant):
assert config_entry.state is ConfigEntryState.SETUP_RETRY assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_async_setup_with_missing_id(hass: HomeAssistant): async def test_async_setup_with_missing_id(hass: HomeAssistant) -> None:
"""Test that setting adds the missing CONF_ID from unique_id.""" """Test that setting adds the missing CONF_ID from unique_id."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -493,7 +493,7 @@ async def test_async_setup_with_missing_id(hass: HomeAssistant):
assert config_entry.state is ConfigEntryState.LOADED assert config_entry.state is ConfigEntryState.LOADED
async def test_async_setup_with_missing_unique_id(hass: HomeAssistant): async def test_async_setup_with_missing_unique_id(hass: HomeAssistant) -> None:
"""Test that setting adds the missing unique_id from CONF_ID.""" """Test that setting adds the missing unique_id from CONF_ID."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -518,7 +518,7 @@ async def test_async_setup_with_missing_unique_id(hass: HomeAssistant):
assert config_entry.state is ConfigEntryState.LOADED assert config_entry.state is ConfigEntryState.LOADED
async def test_connection_dropped_resyncs_properties(hass: HomeAssistant): async def test_connection_dropped_resyncs_properties(hass: HomeAssistant) -> None:
"""Test handling a connection drop results in a property resync.""" """Test handling a connection drop results in a property resync."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -548,7 +548,9 @@ async def test_connection_dropped_resyncs_properties(hass: HomeAssistant):
assert len(mocked_bulb.async_get_properties.mock_calls) == 2 assert len(mocked_bulb.async_get_properties.mock_calls) == 2
async def test_oserror_on_first_update_results_in_unavailable(hass: HomeAssistant): async def test_oserror_on_first_update_results_in_unavailable(
hass: HomeAssistant,
) -> None:
"""Test that an OSError on first update results in unavailable.""" """Test that an OSError on first update results in unavailable."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -572,7 +574,7 @@ async def test_oserror_on_first_update_results_in_unavailable(hass: HomeAssistan
@pytest.mark.parametrize("exception", [BulbException, asyncio.TimeoutError]) @pytest.mark.parametrize("exception", [BulbException, asyncio.TimeoutError])
async def test_non_oserror_exception_on_first_update( async def test_non_oserror_exception_on_first_update(
hass: HomeAssistant, exception: Exception hass: HomeAssistant, exception: Exception
): ) -> None:
"""Test that an exceptions other than OSError on first update do not result in unavailable. """Test that an exceptions other than OSError on first update do not result in unavailable.
The unavailable state will come as a push update in this case The unavailable state will come as a push update in this case
@ -596,7 +598,7 @@ async def test_non_oserror_exception_on_first_update(
assert hass.states.get("light.test_name").state != STATE_UNAVAILABLE assert hass.states.get("light.test_name").state != STATE_UNAVAILABLE
async def test_async_setup_with_discovery_not_working(hass: HomeAssistant): async def test_async_setup_with_discovery_not_working(hass: HomeAssistant) -> None:
"""Test we can setup even if discovery is broken.""" """Test we can setup even if discovery is broken."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -138,7 +138,7 @@ SUPPORT_YEELIGHT = (
) )
async def test_services(hass: HomeAssistant, caplog): async def test_services(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
"""Test Yeelight services.""" """Test Yeelight services."""
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
@ -525,7 +525,9 @@ async def test_services(hass: HomeAssistant, caplog):
assert hass.states.get(ENTITY_LIGHT).state == STATE_UNAVAILABLE assert hass.states.get(ENTITY_LIGHT).state == STATE_UNAVAILABLE
async def test_update_errors(hass: HomeAssistant, caplog): async def test_update_errors(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test update errors.""" """Test update errors."""
assert await async_setup_component(hass, "homeassistant", {}) assert await async_setup_component(hass, "homeassistant", {})
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
@ -575,7 +577,7 @@ async def test_update_errors(hass: HomeAssistant, caplog):
assert hass.states.get(ENTITY_LIGHT).state == STATE_UNAVAILABLE assert hass.states.get(ENTITY_LIGHT).state == STATE_UNAVAILABLE
async def test_state_already_set_avoid_ratelimit(hass: HomeAssistant): async def test_state_already_set_avoid_ratelimit(hass: HomeAssistant) -> None:
"""Ensure we suppress state changes that will increase the rate limit when there is no change.""" """Ensure we suppress state changes that will increase the rate limit when there is no change."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
properties = {**PROPERTIES} properties = {**PROPERTIES}
@ -767,7 +769,9 @@ async def test_state_already_set_avoid_ratelimit(hass: HomeAssistant):
mocked_bulb.last_properties["flowing"] = "0" mocked_bulb.last_properties["flowing"] = "0"
async def test_device_types(hass: HomeAssistant, caplog): async def test_device_types(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test different device types.""" """Test different device types."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
properties = {**PROPERTIES} properties = {**PROPERTIES}
@ -1337,7 +1341,7 @@ async def test_device_types(hass: HomeAssistant, caplog):
) )
async def test_effects(hass: HomeAssistant): async def test_effects(hass: HomeAssistant) -> None:
"""Test effects.""" """Test effects."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -1508,7 +1512,7 @@ async def test_effects(hass: HomeAssistant):
await _async_test_effect("not_existed", called=False) await _async_test_effect("not_existed", called=False)
async def test_ambilight_with_nightlight_disabled(hass: HomeAssistant): async def test_ambilight_with_nightlight_disabled(hass: HomeAssistant) -> None:
"""Test that main light on ambilights with the nightlight disabled shows the correct brightness.""" """Test that main light on ambilights with the nightlight disabled shows the correct brightness."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
properties = {**PROPERTIES} properties = {**PROPERTIES}
@ -1542,7 +1546,7 @@ async def test_ambilight_with_nightlight_disabled(hass: HomeAssistant):
assert state.attributes[ATTR_BRIGHTNESS] == 128 assert state.attributes[ATTR_BRIGHTNESS] == 128
async def test_state_fails_to_update_triggers_update(hass: HomeAssistant): async def test_state_fails_to_update_triggers_update(hass: HomeAssistant) -> None:
"""Ensure we call async_get_properties if the turn on/off fails to update the state.""" """Ensure we call async_get_properties if the turn on/off fails to update the state."""
mocked_bulb = _mocked_bulb() mocked_bulb = _mocked_bulb()
properties = {**PROPERTIES} properties = {**PROPERTIES}

View file

@ -11,6 +11,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
CLIENT_ID = "12345" CLIENT_ID = "12345"
CLIENT_SECRET = "6789" CLIENT_SECRET = "6789"
@ -26,7 +28,7 @@ async def test_abort_if_no_configuration(hass: HomeAssistant) -> None:
assert result["reason"] == "missing_credentials" assert result["reason"] == "missing_credentials"
async def test_abort_if_existing_entry(hass: HomeAssistant): async def test_abort_if_existing_entry(hass: HomeAssistant) -> None:
"""Check flow abort when an entry already exist.""" """Check flow abort when an entry already exist."""
MockConfigEntry(domain=DOMAIN, unique_id=DOMAIN).add_to_hass(hass) MockConfigEntry(domain=DOMAIN, unique_id=DOMAIN).add_to_hass(hass)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -37,8 +39,11 @@ async def test_abort_if_existing_entry(hass: HomeAssistant):
async def test_full_flow( async def test_full_flow(
hass, hass_client_no_auth, aioclient_mock, current_request_with_host hass: HomeAssistant,
): hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
current_request_with_host: None,
) -> None:
"""Check full flow.""" """Check full flow."""
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
@ -105,7 +110,9 @@ async def test_full_flow(
assert len(mock_setup.mock_calls) == 1 assert len(mock_setup.mock_calls) == 1
async def test_abort_if_authorization_timeout(hass, current_request_with_host): async def test_abort_if_authorization_timeout(
hass: HomeAssistant, current_request_with_host: None
) -> None:
"""Check yolink authorization timeout.""" """Check yolink authorization timeout."""
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
@ -131,8 +138,11 @@ async def test_abort_if_authorization_timeout(hass, current_request_with_host):
async def test_reauthentication( async def test_reauthentication(
hass, hass_client_no_auth, aioclient_mock, current_request_with_host hass: HomeAssistant,
): hass_client_no_auth: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
current_request_with_host: None,
) -> None:
"""Test yolink reauthentication.""" """Test yolink reauthentication."""
await setup.async_setup_component( await setup.async_setup_component(
hass, hass,

View file

@ -3,6 +3,7 @@ from ipaddress import ip_address
from typing import Any from typing import Any
from unittest.mock import call, patch from unittest.mock import call, patch
import pytest
from zeroconf import ( from zeroconf import (
BadTypeInNameException, BadTypeInNameException,
InterfaceChoice, InterfaceChoice,
@ -151,7 +152,7 @@ def get_zeroconf_info_mock_model(model):
return mock_zc_info return mock_zc_info
async def test_setup(hass, mock_async_zeroconf): async def test_setup(hass: HomeAssistant, mock_async_zeroconf: None) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
mock_zc = { mock_zc = {
"_http._tcp.local.": [ "_http._tcp.local.": [
@ -196,7 +197,9 @@ async def test_setup(hass, mock_async_zeroconf):
) )
async def test_setup_with_overly_long_url_and_name(hass, mock_async_zeroconf, caplog): async def test_setup_with_overly_long_url_and_name(
hass: HomeAssistant, mock_async_zeroconf: None, caplog: pytest.LogCaptureFixture
) -> None:
"""Test we still setup with long urls and names.""" """Test we still setup with long urls and names."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -233,7 +236,9 @@ async def test_setup_with_overly_long_url_and_name(hass, mock_async_zeroconf, ca
assert "German Umlaut" in caplog.text assert "German Umlaut" in caplog.text
async def test_setup_with_default_interface(hass, mock_async_zeroconf): async def test_setup_with_default_interface(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test default interface config.""" """Test default interface config."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -250,7 +255,9 @@ async def test_setup_with_default_interface(hass, mock_async_zeroconf):
assert mock_async_zeroconf.called_with(interface_choice=InterfaceChoice.Default) assert mock_async_zeroconf.called_with(interface_choice=InterfaceChoice.Default)
async def test_setup_without_default_interface(hass, mock_async_zeroconf): async def test_setup_without_default_interface(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test without default interface config.""" """Test without default interface config."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -265,7 +272,9 @@ async def test_setup_without_default_interface(hass, mock_async_zeroconf):
assert mock_async_zeroconf.called_with() assert mock_async_zeroconf.called_with()
async def test_setup_without_ipv6(hass, mock_async_zeroconf): async def test_setup_without_ipv6(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test without ipv6.""" """Test without ipv6."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -282,7 +291,7 @@ async def test_setup_without_ipv6(hass, mock_async_zeroconf):
assert mock_async_zeroconf.called_with(ip_version=IPVersion.V4Only) assert mock_async_zeroconf.called_with(ip_version=IPVersion.V4Only)
async def test_setup_with_ipv6(hass, mock_async_zeroconf): async def test_setup_with_ipv6(hass: HomeAssistant, mock_async_zeroconf: None) -> None:
"""Test without ipv6.""" """Test without ipv6."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -299,7 +308,9 @@ async def test_setup_with_ipv6(hass, mock_async_zeroconf):
assert mock_async_zeroconf.called_with() assert mock_async_zeroconf.called_with()
async def test_setup_with_ipv6_default(hass, mock_async_zeroconf): async def test_setup_with_ipv6_default(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test without ipv6 as default.""" """Test without ipv6 as default."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -314,7 +325,9 @@ async def test_setup_with_ipv6_default(hass, mock_async_zeroconf):
assert mock_async_zeroconf.called_with() assert mock_async_zeroconf.called_with()
async def test_zeroconf_match_macaddress(hass, mock_async_zeroconf): async def test_zeroconf_match_macaddress(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -356,7 +369,9 @@ async def test_zeroconf_match_macaddress(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][2]["context"] == {"source": "zeroconf"} assert mock_config_flow.mock_calls[0][2]["context"] == {"source": "zeroconf"}
async def test_zeroconf_match_manufacturer(hass, mock_async_zeroconf): async def test_zeroconf_match_manufacturer(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -393,7 +408,9 @@ async def test_zeroconf_match_manufacturer(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "samsungtv" assert mock_config_flow.mock_calls[0][1][0] == "samsungtv"
async def test_zeroconf_match_model(hass, mock_async_zeroconf): async def test_zeroconf_match_model(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test matching a specific model in zeroconf.""" """Test matching a specific model in zeroconf."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -430,7 +447,9 @@ async def test_zeroconf_match_model(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "appletv" assert mock_config_flow.mock_calls[0][1][0] == "appletv"
async def test_zeroconf_match_manufacturer_not_present(hass, mock_async_zeroconf): async def test_zeroconf_match_manufacturer_not_present(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test matchers reject when a property is missing.""" """Test matchers reject when a property is missing."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -466,7 +485,9 @@ async def test_zeroconf_match_manufacturer_not_present(hass, mock_async_zeroconf
assert len(mock_config_flow.mock_calls) == 0 assert len(mock_config_flow.mock_calls) == 0
async def test_zeroconf_no_match(hass, mock_async_zeroconf): async def test_zeroconf_no_match(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -498,7 +519,9 @@ async def test_zeroconf_no_match(hass, mock_async_zeroconf):
assert len(mock_config_flow.mock_calls) == 0 assert len(mock_config_flow.mock_calls) == 0
async def test_zeroconf_no_match_manufacturer(hass, mock_async_zeroconf): async def test_zeroconf_no_match_manufacturer(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
def http_only_service_update_mock(ipv6, zeroconf, services, handlers): def http_only_service_update_mock(ipv6, zeroconf, services, handlers):
@ -534,7 +557,9 @@ async def test_zeroconf_no_match_manufacturer(hass, mock_async_zeroconf):
assert len(mock_config_flow.mock_calls) == 0 assert len(mock_config_flow.mock_calls) == 0
async def test_homekit_match_partial_space(hass, mock_async_zeroconf): async def test_homekit_match_partial_space(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -570,7 +595,9 @@ async def test_homekit_match_partial_space(hass, mock_async_zeroconf):
} }
async def test_device_with_invalid_name(hass, mock_async_zeroconf, caplog): async def test_device_with_invalid_name(
hass: HomeAssistant, mock_async_zeroconf: None, caplog: pytest.LogCaptureFixture
) -> None:
"""Test we ignore devices with an invalid name.""" """Test we ignore devices with an invalid name."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -601,7 +628,9 @@ async def test_device_with_invalid_name(hass, mock_async_zeroconf, caplog):
assert "Bad name in zeroconf record" in caplog.text assert "Bad name in zeroconf record" in caplog.text
async def test_homekit_match_partial_dash(hass, mock_async_zeroconf): async def test_homekit_match_partial_dash(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -632,7 +661,9 @@ async def test_homekit_match_partial_dash(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "lutron_caseta" assert mock_config_flow.mock_calls[0][1][0] == "lutron_caseta"
async def test_homekit_match_partial_fnmatch(hass, mock_async_zeroconf): async def test_homekit_match_partial_fnmatch(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test matching homekit devices with fnmatch.""" """Test matching homekit devices with fnmatch."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -663,7 +694,9 @@ async def test_homekit_match_partial_fnmatch(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "yeelight" assert mock_config_flow.mock_calls[0][1][0] == "yeelight"
async def test_homekit_match_full(hass, mock_async_zeroconf): async def test_homekit_match_full(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test configured options for a device are loaded via config entry.""" """Test configured options for a device are loaded via config entry."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -694,7 +727,9 @@ async def test_homekit_match_full(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "hue" assert mock_config_flow.mock_calls[0][1][0] == "hue"
async def test_homekit_already_paired(hass, mock_async_zeroconf): async def test_homekit_already_paired(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test that an already paired device is sent to homekit_controller.""" """Test that an already paired device is sent to homekit_controller."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -729,7 +764,9 @@ async def test_homekit_already_paired(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[1][1][0] == "homekit_controller" assert mock_config_flow.mock_calls[1][1][0] == "homekit_controller"
async def test_homekit_invalid_paring_status(hass, mock_async_zeroconf): async def test_homekit_invalid_paring_status(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test that missing paring data is not sent to homekit_controller.""" """Test that missing paring data is not sent to homekit_controller."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -760,7 +797,9 @@ async def test_homekit_invalid_paring_status(hass, mock_async_zeroconf):
assert mock_config_flow.mock_calls[0][1][0] == "lutron_caseta" assert mock_config_flow.mock_calls[0][1][0] == "lutron_caseta"
async def test_homekit_not_paired(hass, mock_async_zeroconf): async def test_homekit_not_paired(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test that an not paired device is sent to homekit_controller.""" """Test that an not paired device is sent to homekit_controller."""
with patch.dict( with patch.dict(
zc_gen.ZEROCONF, zc_gen.ZEROCONF,
@ -786,8 +825,8 @@ async def test_homekit_not_paired(hass, mock_async_zeroconf):
async def test_homekit_controller_still_discovered_unpaired_for_cloud( async def test_homekit_controller_still_discovered_unpaired_for_cloud(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test discovery is still passed to homekit controller when unpaired. """Test discovery is still passed to homekit controller when unpaired.
When unpaired and discovered by cloud integration. When unpaired and discovered by cloud integration.
@ -826,8 +865,8 @@ async def test_homekit_controller_still_discovered_unpaired_for_cloud(
async def test_homekit_controller_still_discovered_unpaired_for_polling( async def test_homekit_controller_still_discovered_unpaired_for_polling(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test discovery is still passed to homekit controller when unpaired. """Test discovery is still passed to homekit controller when unpaired.
When unpaired and discovered by polling integration. When unpaired and discovered by polling integration.
@ -962,7 +1001,7 @@ async def test_info_from_service_can_return_ipv6(hass: HomeAssistant) -> None:
assert info.host == "fd11:1111:1111:0:1234:1234:1234:1234" assert info.host == "fd11:1111:1111:0:1234:1234:1234:1234"
async def test_get_instance(hass, mock_async_zeroconf): async def test_get_instance(hass: HomeAssistant, mock_async_zeroconf: None) -> None:
"""Test we get an instance.""" """Test we get an instance."""
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}}) assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})
assert ( assert (
@ -973,7 +1012,7 @@ async def test_get_instance(hass, mock_async_zeroconf):
assert len(mock_async_zeroconf.ha_async_close.mock_calls) == 1 assert len(mock_async_zeroconf.ha_async_close.mock_calls) == 1
async def test_removed_ignored(hass, mock_async_zeroconf): async def test_removed_ignored(hass: HomeAssistant, mock_async_zeroconf: None) -> None:
"""Test we remove it when a zeroconf entry is removed.""" """Test we remove it when a zeroconf entry is removed."""
def service_update_mock(ipv6, zeroconf, services, handlers): def service_update_mock(ipv6, zeroconf, services, handlers):
@ -1025,8 +1064,8 @@ _ADAPTER_WITH_DEFAULT_ENABLED = [
async def test_async_detect_interfaces_setting_non_loopback_route( async def test_async_detect_interfaces_setting_non_loopback_route(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test without default interface and the route returns a non-loopback address.""" """Test without default interface and the route returns a non-loopback address."""
with patch("homeassistant.components.zeroconf.HaZeroconf") as mock_zc, patch.object( with patch("homeassistant.components.zeroconf.HaZeroconf") as mock_zc, patch.object(
hass.config_entries.flow, "async_init" hass.config_entries.flow, "async_init"
@ -1109,8 +1148,8 @@ _ADAPTERS_WITH_MANUAL_CONFIG = [
async def test_async_detect_interfaces_setting_empty_route_linux( async def test_async_detect_interfaces_setting_empty_route_linux(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test without default interface config and the route returns nothing on linux.""" """Test without default interface config and the route returns nothing on linux."""
with patch("homeassistant.components.zeroconf.sys.platform", "linux"), patch( with patch("homeassistant.components.zeroconf.sys.platform", "linux"), patch(
"homeassistant.components.zeroconf.HaZeroconf" "homeassistant.components.zeroconf.HaZeroconf"
@ -1139,8 +1178,8 @@ async def test_async_detect_interfaces_setting_empty_route_linux(
async def test_async_detect_interfaces_setting_empty_route_freebsd( async def test_async_detect_interfaces_setting_empty_route_freebsd(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test without default interface and the route returns nothing on freebsd.""" """Test without default interface and the route returns nothing on freebsd."""
with patch("homeassistant.components.zeroconf.sys.platform", "freebsd"), patch( with patch("homeassistant.components.zeroconf.sys.platform", "freebsd"), patch(
"homeassistant.components.zeroconf.HaZeroconf" "homeassistant.components.zeroconf.HaZeroconf"
@ -1165,7 +1204,9 @@ async def test_async_detect_interfaces_setting_empty_route_freebsd(
) )
async def test_get_announced_addresses(hass, mock_async_zeroconf): async def test_get_announced_addresses(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test addresses for mDNS announcement.""" """Test addresses for mDNS announcement."""
expected = { expected = {
ip_address(ip).packed ip_address(ip).packed
@ -1207,8 +1248,8 @@ _ADAPTER_WITH_DEFAULT_ENABLED_AND_IPV6 = [
async def test_async_detect_interfaces_explicitly_set_ipv6_linux( async def test_async_detect_interfaces_explicitly_set_ipv6_linux(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test interfaces are explicitly set when IPv6 is present on linux.""" """Test interfaces are explicitly set when IPv6 is present on linux."""
with patch("homeassistant.components.zeroconf.sys.platform", "linux"), patch( with patch("homeassistant.components.zeroconf.sys.platform", "linux"), patch(
"homeassistant.components.zeroconf.HaZeroconf" "homeassistant.components.zeroconf.HaZeroconf"
@ -1232,8 +1273,8 @@ async def test_async_detect_interfaces_explicitly_set_ipv6_linux(
async def test_async_detect_interfaces_explicitly_set_ipv6_freebsd( async def test_async_detect_interfaces_explicitly_set_ipv6_freebsd(
hass, mock_async_zeroconf hass: HomeAssistant, mock_async_zeroconf: None
): ) -> None:
"""Test interfaces are explicitly set when IPv6 is present on freebsd.""" """Test interfaces are explicitly set when IPv6 is present on freebsd."""
with patch("homeassistant.components.zeroconf.sys.platform", "freebsd"), patch( with patch("homeassistant.components.zeroconf.sys.platform", "freebsd"), patch(
"homeassistant.components.zeroconf.HaZeroconf" "homeassistant.components.zeroconf.HaZeroconf"
@ -1256,7 +1297,7 @@ async def test_async_detect_interfaces_explicitly_set_ipv6_freebsd(
) )
async def test_no_name(hass, mock_async_zeroconf): async def test_no_name(hass: HomeAssistant, mock_async_zeroconf: None) -> None:
"""Test fallback to Home for mDNS announcement if the name is missing.""" """Test fallback to Home for mDNS announcement if the name is missing."""
hass.config.location_name = "" hass.config.location_name = ""
with patch("homeassistant.components.zeroconf.HaZeroconf"): with patch("homeassistant.components.zeroconf.HaZeroconf"):
@ -1270,8 +1311,8 @@ async def test_no_name(hass, mock_async_zeroconf):
async def test_setup_with_disallowed_characters_in_local_name( async def test_setup_with_disallowed_characters_in_local_name(
hass, mock_async_zeroconf, caplog hass: HomeAssistant, mock_async_zeroconf: None, caplog: pytest.LogCaptureFixture
): ) -> None:
"""Test we still setup with disallowed characters in the location name.""" """Test we still setup with disallowed characters in the location name."""
with patch.object(hass.config_entries.flow, "async_init"), patch.object( with patch.object(hass.config_entries.flow, "async_init"), patch.object(
zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock zeroconf, "HaAsyncServiceBrowser", side_effect=service_update_mock
@ -1288,7 +1329,9 @@ async def test_setup_with_disallowed_characters_in_local_name(
assert calls[0][1][0].name == "My House._home-assistant._tcp.local." assert calls[0][1][0].name == "My House._home-assistant._tcp.local."
async def test_start_with_frontend(hass, mock_async_zeroconf): async def test_start_with_frontend(
hass: HomeAssistant, mock_async_zeroconf: None
) -> None:
"""Test we start with the frontend.""" """Test we start with the frontend."""
with patch("homeassistant.components.zeroconf.HaZeroconf"): with patch("homeassistant.components.zeroconf.HaZeroconf"):
assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}}) assert await async_setup_component(hass, zeroconf.DOMAIN, {zeroconf.DOMAIN: {}})

View file

@ -1,18 +1,23 @@
"""Test Zeroconf multiple instance protection.""" """Test Zeroconf multiple instance protection."""
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
import pytest
import zeroconf import zeroconf
from homeassistant.components.zeroconf import async_get_instance from homeassistant.components.zeroconf import async_get_instance
from homeassistant.components.zeroconf.usage import install_multiple_zeroconf_catcher from homeassistant.components.zeroconf.usage import install_multiple_zeroconf_catcher
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
DOMAIN = "zeroconf" DOMAIN = "zeroconf"
async def test_multiple_zeroconf_instances( async def test_multiple_zeroconf_instances(
hass, mock_async_zeroconf, mock_zeroconf, caplog hass: HomeAssistant,
): mock_async_zeroconf: None,
mock_zeroconf: None,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test creating multiple zeroconf throws without an integration.""" """Test creating multiple zeroconf throws without an integration."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
@ -27,8 +32,11 @@ async def test_multiple_zeroconf_instances(
async def test_multiple_zeroconf_instances_gives_shared( async def test_multiple_zeroconf_instances_gives_shared(
hass, mock_async_zeroconf, mock_zeroconf, caplog hass: HomeAssistant,
): mock_async_zeroconf: None,
mock_zeroconf: None,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test creating multiple zeroconf gives the shared instance to an integration.""" """Test creating multiple zeroconf gives the shared instance to an integration."""
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}}) assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})

View file

@ -28,6 +28,7 @@ from homeassistant.const import (
STATE_ON, STATE_ON,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import HomeAssistant
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
@ -66,7 +67,7 @@ async def mock_light(hass, mock_entry):
return light return light
async def test_init(hass, mock_entry): async def test_init(hass: HomeAssistant, mock_entry) -> None:
"""Test platform setup.""" """Test platform setup."""
mock_entry.add_to_hass(hass) mock_entry.add_to_hass(hass)
@ -126,7 +127,7 @@ async def test_init(hass, mock_entry):
assert hass.data[DOMAIN]["addresses"] == {"AA:BB:CC:DD:EE:FF", "11:22:33:44:55:66"} assert hass.data[DOMAIN]["addresses"] == {"AA:BB:CC:DD:EE:FF", "11:22:33:44:55:66"}
async def test_discovery_exception(hass, mock_entry): async def test_discovery_exception(hass: HomeAssistant, mock_entry) -> None:
"""Test platform setup.""" """Test platform setup."""
mock_entry.add_to_hass(hass) mock_entry.add_to_hass(hass)
@ -142,7 +143,7 @@ async def test_discovery_exception(hass, mock_entry):
assert len(hass.data[DOMAIN]["addresses"]) == 0 assert len(hass.data[DOMAIN]["addresses"]) == 0
async def test_remove_entry(hass, mock_light, mock_entry): async def test_remove_entry(hass: HomeAssistant, mock_light, mock_entry) -> None:
"""Test platform setup.""" """Test platform setup."""
assert hass.data[DOMAIN][DATA_ADDRESSES] == {"AA:BB:CC:DD:EE:FF"} assert hass.data[DOMAIN][DATA_ADDRESSES] == {"AA:BB:CC:DD:EE:FF"}
assert DATA_DISCOVERY_SUBSCRIPTION in hass.data[DOMAIN] assert DATA_DISCOVERY_SUBSCRIPTION in hass.data[DOMAIN]
@ -154,7 +155,9 @@ async def test_remove_entry(hass, mock_light, mock_entry):
assert DOMAIN not in hass.data assert DOMAIN not in hass.data
async def test_remove_entry_exceptions_caught(hass, mock_light, mock_entry): async def test_remove_entry_exceptions_caught(
hass: HomeAssistant, mock_light, mock_entry
) -> None:
"""Assert that disconnect exceptions are caught.""" """Assert that disconnect exceptions are caught."""
with patch.object( with patch.object(
mock_light, "disconnect", side_effect=pyzerproc.ZerprocException("Mock error") mock_light, "disconnect", side_effect=pyzerproc.ZerprocException("Mock error")
@ -164,7 +167,7 @@ async def test_remove_entry_exceptions_caught(hass, mock_light, mock_entry):
assert mock_disconnect.called assert mock_disconnect.called
async def test_light_turn_on(hass, mock_light): async def test_light_turn_on(hass: HomeAssistant, mock_light) -> None:
"""Test ZerprocLight turn_on.""" """Test ZerprocLight turn_on."""
utcnow = dt_util.utcnow() utcnow = dt_util.utcnow()
with patch.object(mock_light, "turn_on") as mock_turn_on: with patch.object(mock_light, "turn_on") as mock_turn_on:
@ -256,7 +259,7 @@ async def test_light_turn_on(hass, mock_light):
mock_set_color.assert_called_with(162, 200, 50) mock_set_color.assert_called_with(162, 200, 50)
async def test_light_turn_off(hass, mock_light): async def test_light_turn_off(hass: HomeAssistant, mock_light) -> None:
"""Test ZerprocLight turn_on.""" """Test ZerprocLight turn_on."""
with patch.object(mock_light, "turn_off") as mock_turn_off: with patch.object(mock_light, "turn_off") as mock_turn_off:
await hass.services.async_call( await hass.services.async_call(
@ -269,7 +272,7 @@ async def test_light_turn_off(hass, mock_light):
mock_turn_off.assert_called() mock_turn_off.assert_called()
async def test_light_update(hass, mock_light): async def test_light_update(hass: HomeAssistant, mock_light) -> None:
"""Test ZerprocLight update.""" """Test ZerprocLight update."""
utcnow = dt_util.utcnow() utcnow = dt_util.utcnow()

View file

@ -19,6 +19,7 @@ from homeassistant.components.zodiac.const import (
SIGN_TAURUS, SIGN_TAURUS,
) )
from homeassistant.const import ATTR_DEVICE_CLASS from homeassistant.const import ATTR_DEVICE_CLASS
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -36,7 +37,7 @@ DAY3 = datetime(2020, 4, 21, tzinfo=dt_util.UTC)
(DAY3, SIGN_TAURUS, ELEMENT_EARTH, MODALITY_FIXED), (DAY3, SIGN_TAURUS, ELEMENT_EARTH, MODALITY_FIXED),
], ],
) )
async def test_zodiac_day(hass, now, sign, element, modality): async def test_zodiac_day(hass: HomeAssistant, now, sign, element, modality) -> None:
"""Test the zodiac sensor.""" """Test the zodiac sensor."""
hass.config.set_time_zone("UTC") hass.config.set_time_zone("UTC")
config = {DOMAIN: {}} config = {DOMAIN: {}}

View file

@ -18,7 +18,8 @@ from homeassistant.core import Context, HomeAssistant
from homeassistant.exceptions import Unauthorized from homeassistant.exceptions import Unauthorized
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry from tests.common import MockConfigEntry, MockUser
from tests.typing import WebSocketGenerator
@pytest.fixture @pytest.fixture
@ -246,7 +247,9 @@ async def test_core_config_update(hass: HomeAssistant) -> None:
assert home_updated.attributes["longitude"] == 20 assert home_updated.attributes["longitude"] == 20
async def test_reload(hass, hass_admin_user, hass_read_only_user): async def test_reload(
hass: HomeAssistant, hass_admin_user: MockUser, hass_read_only_user: MockUser
) -> None:
"""Test reload service.""" """Test reload service."""
count_start = len(hass.states.async_entity_ids()) count_start = len(hass.states.async_entity_ids())
ent_reg = er.async_get(hass) ent_reg = er.async_get(hass)
@ -317,7 +320,7 @@ async def test_reload(hass, hass_admin_user, hass_read_only_user):
assert state_3.attributes["longitude"] == 6 assert state_3.attributes["longitude"] == 6
async def test_load_from_storage(hass, storage_setup): async def test_load_from_storage(hass: HomeAssistant, storage_setup) -> None:
"""Test set up from storage.""" """Test set up from storage."""
assert await storage_setup() assert await storage_setup()
state = hass.states.get(f"{DOMAIN}.from_storage") state = hass.states.get(f"{DOMAIN}.from_storage")
@ -326,7 +329,7 @@ async def test_load_from_storage(hass, storage_setup):
assert state.attributes.get(ATTR_EDITABLE) assert state.attributes.get(ATTR_EDITABLE)
async def test_editable_state_attribute(hass, storage_setup): async def test_editable_state_attribute(hass: HomeAssistant, storage_setup) -> None:
"""Test editable attribute.""" """Test editable attribute."""
assert await storage_setup( assert await storage_setup(
config={DOMAIN: [{"name": "yaml option", "latitude": 3, "longitude": 4}]} config={DOMAIN: [{"name": "yaml option", "latitude": 3, "longitude": 4}]}
@ -342,7 +345,9 @@ async def test_editable_state_attribute(hass, storage_setup):
assert not state.attributes.get(ATTR_EDITABLE) assert not state.attributes.get(ATTR_EDITABLE)
async def test_ws_list(hass, hass_ws_client, storage_setup): async def test_ws_list(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
) -> None:
"""Test listing via WS.""" """Test listing via WS."""
assert await storage_setup( assert await storage_setup(
config={DOMAIN: [{"name": "yaml option", "latitude": 3, "longitude": 4}]} config={DOMAIN: [{"name": "yaml option", "latitude": 3, "longitude": 4}]}
@ -364,7 +369,9 @@ async def test_ws_list(hass, hass_ws_client, storage_setup):
assert result[storage_ent][ATTR_NAME] == "from storage" assert result[storage_ent][ATTR_NAME] == "from storage"
async def test_ws_delete(hass, hass_ws_client, storage_setup): async def test_ws_delete(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
) -> None:
"""Test WS delete cleans up entity registry.""" """Test WS delete cleans up entity registry."""
assert await storage_setup() assert await storage_setup()
@ -389,7 +396,9 @@ async def test_ws_delete(hass, hass_ws_client, storage_setup):
assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None assert ent_reg.async_get_entity_id(DOMAIN, DOMAIN, input_id) is None
async def test_update(hass, hass_ws_client, storage_setup): async def test_update(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
) -> None:
"""Test updating min/max updates the state.""" """Test updating min/max updates the state."""
items = [ items = [
@ -434,7 +443,9 @@ async def test_update(hass, hass_ws_client, storage_setup):
assert state.attributes["passive"] is True assert state.attributes["passive"] is True
async def test_ws_create(hass, hass_ws_client, storage_setup): async def test_ws_create(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, storage_setup
) -> None:
"""Test create WS.""" """Test create WS."""
assert await storage_setup(items=[]) assert await storage_setup(items=[])

View file

@ -3,7 +3,7 @@ import pytest
from homeassistant.components import automation, zone from homeassistant.components import automation, zone
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
from homeassistant.core import Context from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -37,7 +37,7 @@ def setup_comp(hass):
) )
async def test_if_fires_on_zone_enter(hass, calls): async def test_if_fires_on_zone_enter(hass: HomeAssistant, calls) -> None:
"""Test for firing on zone enter.""" """Test for firing on zone enter."""
context = Context() context = Context()
hass.states.async_set( hass.states.async_set(
@ -109,7 +109,7 @@ async def test_if_fires_on_zone_enter(hass, calls):
assert len(calls) == 1 assert len(calls) == 1
async def test_if_fires_on_zone_enter_uuid(hass, calls): async def test_if_fires_on_zone_enter_uuid(hass: HomeAssistant, calls) -> None:
"""Test for firing on zone enter when device is specified by entity registry id.""" """Test for firing on zone enter when device is specified by entity registry id."""
context = Context() context = Context()
@ -188,7 +188,7 @@ async def test_if_fires_on_zone_enter_uuid(hass, calls):
assert len(calls) == 1 assert len(calls) == 1
async def test_if_not_fires_for_enter_on_zone_leave(hass, calls): async def test_if_not_fires_for_enter_on_zone_leave(hass: HomeAssistant, calls) -> None:
"""Test for not firing on zone leave.""" """Test for not firing on zone leave."""
hass.states.async_set( hass.states.async_set(
"test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564}
@ -219,7 +219,7 @@ async def test_if_not_fires_for_enter_on_zone_leave(hass, calls):
assert len(calls) == 0 assert len(calls) == 0
async def test_if_fires_on_zone_leave(hass, calls): async def test_if_fires_on_zone_leave(hass: HomeAssistant, calls) -> None:
"""Test for firing on zone leave.""" """Test for firing on zone leave."""
hass.states.async_set( hass.states.async_set(
"test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564}
@ -250,7 +250,7 @@ async def test_if_fires_on_zone_leave(hass, calls):
assert len(calls) == 1 assert len(calls) == 1
async def test_if_not_fires_for_leave_on_zone_enter(hass, calls): async def test_if_not_fires_for_leave_on_zone_enter(hass: HomeAssistant, calls) -> None:
"""Test for not firing on zone enter.""" """Test for not firing on zone enter."""
hass.states.async_set( hass.states.async_set(
"test.entity", "hello", {"latitude": 32.881011, "longitude": -117.234758} "test.entity", "hello", {"latitude": 32.881011, "longitude": -117.234758}
@ -281,7 +281,7 @@ async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
assert len(calls) == 0 assert len(calls) == 0
async def test_zone_condition(hass, calls): async def test_zone_condition(hass: HomeAssistant, calls) -> None:
"""Test for zone condition.""" """Test for zone condition."""
hass.states.async_set( hass.states.async_set(
"test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564} "test.entity", "hello", {"latitude": 32.880586, "longitude": -117.237564}
@ -309,7 +309,9 @@ async def test_zone_condition(hass, calls):
assert len(calls) == 1 assert len(calls) == 1
async def test_unknown_zone(hass, calls, caplog): async def test_unknown_zone(
hass: HomeAssistant, calls, caplog: pytest.LogCaptureFixture
) -> None:
"""Test for firing on zone enter.""" """Test for firing on zone enter."""
context = Context() context = Context()
hass.states.async_set( hass.states.async_set(

View file

@ -57,7 +57,7 @@ async def test_form(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_zeroconf(hass: HomeAssistant): async def test_zeroconf(hass: HomeAssistant) -> None:
"""Test starting a flow from zeroconf.""" """Test starting a flow from zeroconf."""
with patch( with patch(
"homeassistant.components.zwave_me.async_setup_entry", "homeassistant.components.zwave_me.async_setup_entry",
@ -91,7 +91,7 @@ async def test_zeroconf(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_error_handling_zeroconf(hass: HomeAssistant): async def test_error_handling_zeroconf(hass: HomeAssistant) -> None:
"""Test getting proper errors from no uuid.""" """Test getting proper errors from no uuid."""
with patch("homeassistant.components.zwave_me.helpers.get_uuid", return_value=None): with patch("homeassistant.components.zwave_me.helpers.get_uuid", return_value=None):
result: FlowResult = await hass.config_entries.flow.async_init( result: FlowResult = await hass.config_entries.flow.async_init(
@ -103,7 +103,7 @@ async def test_error_handling_zeroconf(hass: HomeAssistant):
assert result["reason"] == "no_valid_uuid_set" assert result["reason"] == "no_valid_uuid_set"
async def test_handle_error_user(hass: HomeAssistant): async def test_handle_error_user(hass: HomeAssistant) -> None:
"""Test getting proper errors from no uuid.""" """Test getting proper errors from no uuid."""
with patch("homeassistant.components.zwave_me.helpers.get_uuid", return_value=None): with patch("homeassistant.components.zwave_me.helpers.get_uuid", return_value=None):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -121,7 +121,7 @@ async def test_handle_error_user(hass: HomeAssistant):
assert result2["errors"] == {"base": "no_valid_uuid_set"} assert result2["errors"] == {"base": "no_valid_uuid_set"}
async def test_duplicate_user(hass: HomeAssistant): async def test_duplicate_user(hass: HomeAssistant) -> None:
"""Test getting proper errors from duplicate uuid.""" """Test getting proper errors from duplicate uuid."""
entry: MockConfigEntry = MockConfigEntry( entry: MockConfigEntry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -153,7 +153,7 @@ async def test_duplicate_user(hass: HomeAssistant):
assert result2["reason"] == "already_configured" assert result2["reason"] == "already_configured"
async def test_duplicate_zeroconf(hass: HomeAssistant): async def test_duplicate_zeroconf(hass: HomeAssistant) -> None:
"""Test getting proper errors from duplicate uuid.""" """Test getting proper errors from duplicate uuid."""
entry: MockConfigEntry = MockConfigEntry( entry: MockConfigEntry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -8,6 +8,7 @@ from zwave_me_ws import ZWaveMeData
from homeassistant.components.zwave_me import ZWaveMePlatform from homeassistant.components.zwave_me import ZWaveMePlatform
from homeassistant.const import CONF_TOKEN, CONF_URL from homeassistant.const import CONF_TOKEN, CONF_URL
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -34,8 +35,8 @@ async def mock_connection(controller):
], ],
) )
async def test_remove_stale_devices( async def test_remove_stale_devices(
hass: HomeAssistant, device_registry, identifier, should_exist hass: HomeAssistant, device_registry: dr.DeviceRegistry, identifier, should_exist
): ) -> None:
"""Test removing devices with old-format ids.""" """Test removing devices with old-format ids."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(