Improve type hints in emulated_hue tests (#120664)

This commit is contained in:
epenet 2024-06-27 14:27:35 +02:00 committed by GitHub
parent 8de771de96
commit 0d53ce4fb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,15 +1,18 @@
"""The tests for the emulated Hue component.""" """The tests for the emulated Hue component."""
from __future__ import annotations
import asyncio import asyncio
from datetime import timedelta from datetime import timedelta
from http import HTTPStatus from http import HTTPStatus
from ipaddress import ip_address from ipaddress import ip_address
import json import json
from unittest.mock import patch from unittest.mock import AsyncMock, _patch, patch
from aiohttp.hdrs import CONTENT_TYPE from aiohttp.hdrs import CONTENT_TYPE
from aiohttp.test_utils import TestClient from aiohttp.test_utils import TestClient
import pytest import pytest
from typing_extensions import Generator
from homeassistant import const, setup from homeassistant import const, setup
from homeassistant.components import ( from homeassistant.components import (
@ -56,6 +59,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from homeassistant.util.json import JsonObjectType
from tests.common import ( from tests.common import (
async_fire_time_changed, async_fire_time_changed,
@ -104,14 +108,14 @@ ENTITY_IDS_BY_NUMBER = {
ENTITY_NUMBERS_BY_ID = {v: k for k, v in ENTITY_IDS_BY_NUMBER.items()} ENTITY_NUMBERS_BY_ID = {v: k for k, v in ENTITY_IDS_BY_NUMBER.items()}
def patch_upnp(): def patch_upnp() -> _patch[AsyncMock]:
"""Patch async_create_upnp_datagram_endpoint.""" """Patch async_create_upnp_datagram_endpoint."""
return patch( return patch(
"homeassistant.components.emulated_hue.async_create_upnp_datagram_endpoint" "homeassistant.components.emulated_hue.async_create_upnp_datagram_endpoint"
) )
async def async_get_lights(client): async def async_get_lights(client: TestClient) -> JsonObjectType:
"""Get lights with the hue client.""" """Get lights with the hue client."""
result = await client.get("/api/username/lights") result = await client.get("/api/username/lights")
assert result.status == HTTPStatus.OK assert result.status == HTTPStatus.OK
@ -131,7 +135,7 @@ async def _async_setup_emulated_hue(hass: HomeAssistant, conf: ConfigType) -> No
@pytest.fixture @pytest.fixture
async def base_setup(hass): async def base_setup(hass: HomeAssistant) -> None:
"""Set up homeassistant and http.""" """Set up homeassistant and http."""
await asyncio.gather( await asyncio.gather(
setup.async_setup_component(hass, "homeassistant", {}), setup.async_setup_component(hass, "homeassistant", {}),
@ -142,7 +146,7 @@ async def base_setup(hass):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
async def wanted_platforms_only() -> None: def wanted_platforms_only() -> Generator[None]:
"""Enable only the wanted demo platforms.""" """Enable only the wanted demo platforms."""
with patch( with patch(
"homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM",
@ -159,7 +163,7 @@ async def wanted_platforms_only() -> None:
@pytest.fixture @pytest.fixture
async def demo_setup(hass, wanted_platforms_only): async def demo_setup(hass: HomeAssistant, wanted_platforms_only: None) -> None:
"""Fixture to setup demo platforms.""" """Fixture to setup demo platforms."""
# We need to do this to get access to homeassistant/turn_(on,off) # We need to do this to get access to homeassistant/turn_(on,off)
setups = [ setups = [
@ -211,7 +215,9 @@ async def demo_setup(hass, wanted_platforms_only):
@pytest.fixture @pytest.fixture
async def hass_hue(hass, base_setup, demo_setup): async def hass_hue(
hass: HomeAssistant, base_setup: None, demo_setup: None
) -> HomeAssistant:
"""Set up a Home Assistant instance for these tests.""" """Set up a Home Assistant instance for these tests."""
await _async_setup_emulated_hue( await _async_setup_emulated_hue(
hass, hass,
@ -245,7 +251,7 @@ def _mock_hue_endpoints(
@pytest.fixture @pytest.fixture
async def hue_client( async def hue_client(
hass_hue, hass_client_no_auth: ClientSessionGenerator hass_hue: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
) -> TestClient: ) -> TestClient:
"""Create web client for emulated hue api.""" """Create web client for emulated hue api."""
_mock_hue_endpoints( _mock_hue_endpoints(
@ -285,7 +291,7 @@ async def hue_client(
return await hass_client_no_auth() return await hass_client_no_auth()
async def test_discover_lights(hass: HomeAssistant, hue_client) -> None: async def test_discover_lights(hass: HomeAssistant, hue_client: TestClient) -> None:
"""Test the discovery of lights.""" """Test the discovery of lights."""
result = await hue_client.get("/api/username/lights") result = await hue_client.get("/api/username/lights")
@ -343,7 +349,8 @@ async def test_discover_lights(hass: HomeAssistant, hue_client) -> None:
assert device["state"][HUE_API_STATE_ON] is False assert device["state"][HUE_API_STATE_ON] is False
async def test_light_without_brightness_supported(hass_hue, hue_client) -> None: @pytest.mark.usefixtures("hass_hue")
async def test_light_without_brightness_supported(hue_client: TestClient) -> None:
"""Test that light without brightness is supported.""" """Test that light without brightness is supported."""
light_without_brightness_json = await perform_get_light_state( light_without_brightness_json = await perform_get_light_state(
hue_client, "light.no_brightness", HTTPStatus.OK hue_client, "light.no_brightness", HTTPStatus.OK
@ -382,7 +389,9 @@ async def test_lights_all_dimmable(
) )
async def test_light_without_brightness_can_be_turned_off(hass_hue, hue_client) -> None: async def test_light_without_brightness_can_be_turned_off(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test that light without brightness can be turned off.""" """Test that light without brightness can be turned off."""
hass_hue.states.async_set("light.no_brightness", "on", {}) hass_hue.states.async_set("light.no_brightness", "on", {})
turn_off_calls = [] turn_off_calls = []
@ -417,7 +426,9 @@ async def test_light_without_brightness_can_be_turned_off(hass_hue, hue_client)
assert "light.no_brightness" in call.data[ATTR_ENTITY_ID] assert "light.no_brightness" in call.data[ATTR_ENTITY_ID]
async def test_light_without_brightness_can_be_turned_on(hass_hue, hue_client) -> None: async def test_light_without_brightness_can_be_turned_on(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test that light without brightness can be turned on.""" """Test that light without brightness can be turned on."""
hass_hue.states.async_set("light.no_brightness", "off", {}) hass_hue.states.async_set("light.no_brightness", "off", {})
@ -467,7 +478,9 @@ async def test_light_without_brightness_can_be_turned_on(hass_hue, hue_client) -
(const.STATE_UNKNOWN, True), (const.STATE_UNKNOWN, True),
], ],
) )
async def test_reachable_for_state(hass_hue, hue_client, state, is_reachable) -> None: async def test_reachable_for_state(
hass_hue: HomeAssistant, hue_client: TestClient, state: str, is_reachable: bool
) -> None:
"""Test that an entity is reported as unreachable if in unavailable state.""" """Test that an entity is reported as unreachable if in unavailable state."""
entity_id = "light.ceiling_lights" entity_id = "light.ceiling_lights"
@ -478,7 +491,7 @@ async def test_reachable_for_state(hass_hue, hue_client, state, is_reachable) ->
assert state_json["state"]["reachable"] == is_reachable, state_json assert state_json["state"]["reachable"] == is_reachable, state_json
async def test_discover_full_state(hue_client) -> None: async def test_discover_full_state(hue_client: TestClient) -> None:
"""Test the discovery of full state.""" """Test the discovery of full state."""
result = await hue_client.get(f"/api/{HUE_API_USERNAME}") result = await hue_client.get(f"/api/{HUE_API_USERNAME}")
@ -529,7 +542,7 @@ async def test_discover_full_state(hue_client) -> None:
assert config_json["linkbutton"] is True assert config_json["linkbutton"] is True
async def test_discover_config(hue_client) -> None: async def test_discover_config(hue_client: TestClient) -> None:
"""Test the discovery of configuration.""" """Test the discovery of configuration."""
result = await hue_client.get(f"/api/{HUE_API_USERNAME}/config") result = await hue_client.get(f"/api/{HUE_API_USERNAME}/config")
@ -587,7 +600,7 @@ async def test_discover_config(hue_client) -> None:
assert "error" not in config_json assert "error" not in config_json
async def test_get_light_state(hass_hue, hue_client) -> None: async def test_get_light_state(hass_hue: HomeAssistant, hue_client: TestClient) -> None:
"""Test the getting of light state.""" """Test the getting of light state."""
# Turn ceiling lights on and set to 127 brightness, and set light color # Turn ceiling lights on and set to 127 brightness, and set light color
await hass_hue.services.async_call( await hass_hue.services.async_call(
@ -648,7 +661,9 @@ async def test_get_light_state(hass_hue, hue_client) -> None:
) )
async def test_put_light_state(hass: HomeAssistant, hass_hue, hue_client) -> None: async def test_put_light_state(
hass: HomeAssistant, hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test the setting of light states.""" """Test the setting of light states."""
await perform_put_test_on_ceiling_lights(hass_hue, hue_client) await perform_put_test_on_ceiling_lights(hass_hue, hue_client)
@ -818,7 +833,7 @@ async def test_put_light_state(hass: HomeAssistant, hass_hue, hue_client) -> Non
async def test_put_light_state_script( async def test_put_light_state_script(
hass: HomeAssistant, hass_hue, hue_client hass: HomeAssistant, hass_hue: HomeAssistant, hue_client: TestClient
) -> None: ) -> None:
"""Test the setting of script variables.""" """Test the setting of script variables."""
# Turn the kitchen light off first # Turn the kitchen light off first
@ -834,7 +849,7 @@ async def test_put_light_state_script(
brightness = round(level * 254 / 100) brightness = round(level * 254 / 100)
script_result = await perform_put_light_state( script_result = await perform_put_light_state(
hass_hue, hue_client, "script.set_kitchen_light", True, brightness hass_hue, hue_client, "script.set_kitchen_light", True, brightness=brightness
) )
script_result_json = await script_result.json() script_result_json = await script_result.json()
@ -851,13 +866,15 @@ async def test_put_light_state_script(
) )
async def test_put_light_state_climate_set_temperature(hass_hue, hue_client) -> None: async def test_put_light_state_climate_set_temperature(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test setting climate temperature.""" """Test setting climate temperature."""
brightness = 19 brightness = 19
temperature = round(brightness / 254 * 100) temperature = round(brightness / 254 * 100)
hvac_result = await perform_put_light_state( hvac_result = await perform_put_light_state(
hass_hue, hue_client, "climate.hvac", True, brightness hass_hue, hue_client, "climate.hvac", True, brightness=brightness
) )
hvac_result_json = await hvac_result.json() hvac_result_json = await hvac_result.json()
@ -876,7 +893,9 @@ async def test_put_light_state_climate_set_temperature(hass_hue, hue_client) ->
assert ecobee_result.status == HTTPStatus.UNAUTHORIZED assert ecobee_result.status == HTTPStatus.UNAUTHORIZED
async def test_put_light_state_humidifier_set_humidity(hass_hue, hue_client) -> None: async def test_put_light_state_humidifier_set_humidity(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test setting humidifier target humidity.""" """Test setting humidifier target humidity."""
# Turn the humidifier off first # Turn the humidifier off first
await hass_hue.services.async_call( await hass_hue.services.async_call(
@ -890,7 +909,7 @@ async def test_put_light_state_humidifier_set_humidity(hass_hue, hue_client) ->
humidity = round(brightness / 254 * 100) humidity = round(brightness / 254 * 100)
humidifier_result = await perform_put_light_state( humidifier_result = await perform_put_light_state(
hass_hue, hue_client, "humidifier.humidifier", True, brightness hass_hue, hue_client, "humidifier.humidifier", True, brightness=brightness
) )
humidifier_result_json = await humidifier_result.json() humidifier_result_json = await humidifier_result.json()
@ -909,7 +928,9 @@ async def test_put_light_state_humidifier_set_humidity(hass_hue, hue_client) ->
assert hygrostat_result.status == HTTPStatus.UNAUTHORIZED assert hygrostat_result.status == HTTPStatus.UNAUTHORIZED
async def test_put_light_state_media_player(hass_hue, hue_client) -> None: async def test_put_light_state_media_player(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test turning on media player and setting volume.""" """Test turning on media player and setting volume."""
# Turn the music player off first # Turn the music player off first
await hass_hue.services.async_call( await hass_hue.services.async_call(
@ -924,7 +945,7 @@ async def test_put_light_state_media_player(hass_hue, hue_client) -> None:
brightness = round(level * 254) brightness = round(level * 254)
mp_result = await perform_put_light_state( mp_result = await perform_put_light_state(
hass_hue, hue_client, "media_player.walkman", True, brightness hass_hue, hue_client, "media_player.walkman", True, brightness=brightness
) )
mp_result_json = await mp_result.json() mp_result_json = await mp_result.json()
@ -937,7 +958,9 @@ async def test_put_light_state_media_player(hass_hue, hue_client) -> None:
assert walkman.attributes[media_player.ATTR_MEDIA_VOLUME_LEVEL] == level assert walkman.attributes[media_player.ATTR_MEDIA_VOLUME_LEVEL] == level
async def test_open_cover_without_position(hass_hue, hue_client) -> None: async def test_open_cover_without_position(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test opening cover .""" """Test opening cover ."""
cover_id = "cover.living_room_window" cover_id = "cover.living_room_window"
# Close cover first # Close cover first
@ -1000,7 +1023,9 @@ async def test_open_cover_without_position(hass_hue, hue_client) -> None:
assert cover_test_2.attributes.get("current_position") == 0 assert cover_test_2.attributes.get("current_position") == 0
async def test_set_position_cover(hass_hue, hue_client) -> None: async def test_set_position_cover(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test setting position cover .""" """Test setting position cover ."""
cover_id = "cover.living_room_window" cover_id = "cover.living_room_window"
cover_number = ENTITY_NUMBERS_BY_ID[cover_id] cover_number = ENTITY_NUMBERS_BY_ID[cover_id]
@ -1034,7 +1059,7 @@ async def test_set_position_cover(hass_hue, hue_client) -> None:
# Go through the API to open # Go through the API to open
cover_result = await perform_put_light_state( cover_result = await perform_put_light_state(
hass_hue, hue_client, cover_id, False, brightness hass_hue, hue_client, cover_id, False, brightness=brightness
) )
assert cover_result.status == HTTPStatus.OK assert cover_result.status == HTTPStatus.OK
@ -1057,7 +1082,9 @@ async def test_set_position_cover(hass_hue, hue_client) -> None:
assert cover_test_2.attributes.get("current_position") == level assert cover_test_2.attributes.get("current_position") == level
async def test_put_light_state_fan(hass_hue, hue_client) -> None: async def test_put_light_state_fan(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test turning on fan and setting speed.""" """Test turning on fan and setting speed."""
# Turn the fan off first # Turn the fan off first
await hass_hue.services.async_call( await hass_hue.services.async_call(
@ -1072,7 +1099,7 @@ async def test_put_light_state_fan(hass_hue, hue_client) -> None:
brightness = round(level * 254 / 100) brightness = round(level * 254 / 100)
fan_result = await perform_put_light_state( fan_result = await perform_put_light_state(
hass_hue, hue_client, "fan.living_room_fan", True, brightness hass_hue, hue_client, "fan.living_room_fan", True, brightness=brightness
) )
fan_result_json = await fan_result.json() fan_result_json = await fan_result.json()
@ -1166,7 +1193,9 @@ async def test_put_light_state_fan(hass_hue, hue_client) -> None:
assert fan_json["state"][HUE_API_STATE_BRI] == 1 assert fan_json["state"][HUE_API_STATE_BRI] == 1
async def test_put_with_form_urlencoded_content_type(hass_hue, hue_client) -> None: async def test_put_with_form_urlencoded_content_type(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test the form with urlencoded content.""" """Test the form with urlencoded content."""
entity_number = ENTITY_NUMBERS_BY_ID["light.ceiling_lights"] entity_number = ENTITY_NUMBERS_BY_ID["light.ceiling_lights"]
# Needed for Alexa # Needed for Alexa
@ -1185,7 +1214,7 @@ async def test_put_with_form_urlencoded_content_type(hass_hue, hue_client) -> No
assert result.status == HTTPStatus.BAD_REQUEST assert result.status == HTTPStatus.BAD_REQUEST
async def test_entity_not_found(hue_client) -> None: async def test_entity_not_found(hue_client: TestClient) -> None:
"""Test for entity which are not found.""" """Test for entity which are not found."""
result = await hue_client.get("/api/username/lights/98") result = await hue_client.get("/api/username/lights/98")
@ -1196,7 +1225,7 @@ async def test_entity_not_found(hue_client) -> None:
assert result.status == HTTPStatus.NOT_FOUND assert result.status == HTTPStatus.NOT_FOUND
async def test_allowed_methods(hue_client) -> None: async def test_allowed_methods(hue_client: TestClient) -> None:
"""Test the allowed methods.""" """Test the allowed methods."""
result = await hue_client.get( result = await hue_client.get(
"/api/username/lights/ENTITY_NUMBERS_BY_ID[light.ceiling_lights]/state" "/api/username/lights/ENTITY_NUMBERS_BY_ID[light.ceiling_lights]/state"
@ -1215,7 +1244,7 @@ async def test_allowed_methods(hue_client) -> None:
assert result.status == HTTPStatus.METHOD_NOT_ALLOWED assert result.status == HTTPStatus.METHOD_NOT_ALLOWED
async def test_proper_put_state_request(hue_client) -> None: async def test_proper_put_state_request(hue_client: TestClient) -> None:
"""Test the request to set the state.""" """Test the request to set the state."""
# Test proper on value parsing # Test proper on value parsing
result = await hue_client.put( result = await hue_client.put(
@ -1238,7 +1267,7 @@ async def test_proper_put_state_request(hue_client) -> None:
assert result.status == HTTPStatus.BAD_REQUEST assert result.status == HTTPStatus.BAD_REQUEST
async def test_get_empty_groups_state(hue_client) -> None: async def test_get_empty_groups_state(hue_client: TestClient) -> None:
"""Test the request to get groups endpoint.""" """Test the request to get groups endpoint."""
# Test proper on value parsing # Test proper on value parsing
result = await hue_client.get("/api/username/groups") result = await hue_client.get("/api/username/groups")
@ -1251,7 +1280,9 @@ async def test_get_empty_groups_state(hue_client) -> None:
async def perform_put_test_on_ceiling_lights( async def perform_put_test_on_ceiling_lights(
hass_hue, hue_client, content_type=CONTENT_TYPE_JSON hass_hue: HomeAssistant,
hue_client: TestClient,
content_type: str = CONTENT_TYPE_JSON,
): ):
"""Test the setting of a light.""" """Test the setting of a light."""
# Turn the office light off first # Turn the office light off first
@ -1267,7 +1298,12 @@ async def perform_put_test_on_ceiling_lights(
# Go through the API to turn it on # Go through the API to turn it on
office_result = await perform_put_light_state( office_result = await perform_put_light_state(
hass_hue, hue_client, "light.ceiling_lights", True, 56, content_type hass_hue,
hue_client,
"light.ceiling_lights",
True,
brightness=56,
content_type=content_type,
) )
assert office_result.status == HTTPStatus.OK assert office_result.status == HTTPStatus.OK
@ -1283,7 +1319,9 @@ async def perform_put_test_on_ceiling_lights(
assert ceiling_lights.attributes[light.ATTR_BRIGHTNESS] == 56 assert ceiling_lights.attributes[light.ATTR_BRIGHTNESS] == 56
async def perform_get_light_state_by_number(client, entity_number, expected_status): async def perform_get_light_state_by_number(
client: TestClient, entity_number: int | str, expected_status: HTTPStatus
) -> JsonObjectType | None:
"""Test the getting of a light state.""" """Test the getting of a light state."""
result = await client.get(f"/api/username/lights/{entity_number}") result = await client.get(f"/api/username/lights/{entity_number}")
@ -1297,7 +1335,9 @@ async def perform_get_light_state_by_number(client, entity_number, expected_stat
return None return None
async def perform_get_light_state(client, entity_id, expected_status): async def perform_get_light_state(
client: TestClient, entity_id: str, expected_status: HTTPStatus
) -> JsonObjectType | None:
"""Test the getting of a light state.""" """Test the getting of a light state."""
entity_number = ENTITY_NUMBERS_BY_ID[entity_id] entity_number = ENTITY_NUMBERS_BY_ID[entity_id]
return await perform_get_light_state_by_number( return await perform_get_light_state_by_number(
@ -1306,18 +1346,19 @@ async def perform_get_light_state(client, entity_id, expected_status):
async def perform_put_light_state( async def perform_put_light_state(
hass_hue, hass_hue: HomeAssistant,
client, client: TestClient,
entity_id, entity_id: str,
is_on, is_on: bool,
brightness=None, *,
content_type=CONTENT_TYPE_JSON, brightness: int | None = None,
hue=None, content_type: str = CONTENT_TYPE_JSON,
saturation=None, hue: int | None = None,
color_temp=None, saturation: int | None = None,
with_state=True, color_temp: int | None = None,
xy=None, with_state: bool = True,
transitiontime=None, xy: tuple[float, float] | None = None,
transitiontime: int | None = None,
): ):
"""Test the setting of a light state.""" """Test the setting of a light state."""
req_headers = {"Content-Type": content_type} req_headers = {"Content-Type": content_type}
@ -1353,7 +1394,7 @@ async def perform_put_light_state(
return result return result
async def test_external_ip_blocked(hue_client) -> None: async def test_external_ip_blocked(hue_client: TestClient) -> None:
"""Test external IP blocked.""" """Test external IP blocked."""
getUrls = [ getUrls = [
"/api/username/groups", "/api/username/groups",
@ -1391,7 +1432,7 @@ async def test_external_ip_blocked(hue_client) -> None:
_remote_is_allowed.cache_clear() _remote_is_allowed.cache_clear()
async def test_unauthorized_user_blocked(hue_client) -> None: async def test_unauthorized_user_blocked(hue_client: TestClient) -> None:
"""Test unauthorized_user blocked.""" """Test unauthorized_user blocked."""
getUrls = [ getUrls = [
"/api/wronguser", "/api/wronguser",
@ -1405,7 +1446,7 @@ async def test_unauthorized_user_blocked(hue_client) -> None:
async def test_put_then_get_cached_properly( async def test_put_then_get_cached_properly(
hass: HomeAssistant, hass_hue, hue_client hass: HomeAssistant, hass_hue: HomeAssistant, hue_client: TestClient
) -> None: ) -> None:
"""Test the setting of light states and an immediate readback reads the same values.""" """Test the setting of light states and an immediate readback reads the same values."""
@ -1530,7 +1571,7 @@ async def test_put_then_get_cached_properly(
async def test_put_than_get_when_service_call_fails( async def test_put_than_get_when_service_call_fails(
hass: HomeAssistant, hass_hue, hue_client hass: HomeAssistant, hass_hue: HomeAssistant, hue_client: TestClient
) -> None: ) -> None:
"""Test putting and getting the light state when the service call fails.""" """Test putting and getting the light state when the service call fails."""
@ -1581,14 +1622,17 @@ async def test_put_than_get_when_service_call_fails(
assert ceiling_json["state"][HUE_API_STATE_ON] is False assert ceiling_json["state"][HUE_API_STATE_ON] is False
async def test_get_invalid_entity(hass: HomeAssistant, hass_hue, hue_client) -> None: @pytest.mark.usefixtures("hass_hue")
async def test_get_invalid_entity(hue_client: TestClient) -> None:
"""Test the setting of light states and an immediate readback reads the same values.""" """Test the setting of light states and an immediate readback reads the same values."""
# Check that we get an error with an invalid entity number. # Check that we get an error with an invalid entity number.
await perform_get_light_state_by_number(hue_client, 999, HTTPStatus.NOT_FOUND) await perform_get_light_state_by_number(hue_client, 999, HTTPStatus.NOT_FOUND)
async def test_put_light_state_scene(hass: HomeAssistant, hass_hue, hue_client) -> None: async def test_put_light_state_scene(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test the setting of scene variables.""" """Test the setting of scene variables."""
# Turn the kitchen lights off first # Turn the kitchen lights off first
await hass_hue.services.async_call( await hass_hue.services.async_call(
@ -1630,7 +1674,9 @@ async def test_put_light_state_scene(hass: HomeAssistant, hass_hue, hue_client)
assert hass_hue.states.get("light.kitchen_lights").state == STATE_OFF assert hass_hue.states.get("light.kitchen_lights").state == STATE_OFF
async def test_only_change_contrast(hass: HomeAssistant, hass_hue, hue_client) -> None: async def test_only_change_contrast(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test when only changing the contrast of a light state.""" """Test when only changing the contrast of a light state."""
# Turn the kitchen lights off first # Turn the kitchen lights off first
@ -1661,7 +1707,7 @@ async def test_only_change_contrast(hass: HomeAssistant, hass_hue, hue_client) -
async def test_only_change_hue_or_saturation( async def test_only_change_hue_or_saturation(
hass: HomeAssistant, hass_hue, hue_client hass_hue: HomeAssistant, hue_client: TestClient
) -> None: ) -> None:
"""Test setting either the hue or the saturation but not both.""" """Test setting either the hue or the saturation but not both."""
@ -1700,8 +1746,9 @@ async def test_only_change_hue_or_saturation(
] == (0, 3) ] == (0, 3)
@pytest.mark.usefixtures("base_setup")
async def test_specificly_exposed_entities( async def test_specificly_exposed_entities(
hass: HomeAssistant, base_setup, hass_client_no_auth: ClientSessionGenerator hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
) -> None: ) -> None:
"""Test specific entities with expose by default off.""" """Test specific entities with expose by default off."""
conf = { conf = {
@ -1731,7 +1778,9 @@ async def test_specificly_exposed_entities(
assert "1" in result_json assert "1" in result_json
async def test_get_light_state_when_none(hass_hue: HomeAssistant, hue_client) -> None: async def test_get_light_state_when_none(
hass_hue: HomeAssistant, hue_client: TestClient
) -> None:
"""Test the getting of light state when brightness is None.""" """Test the getting of light state when brightness is None."""
hass_hue.states.async_set( hass_hue.states.async_set(
"light.ceiling_lights", "light.ceiling_lights",