From c5341b2ff64be6b64b430a4eec287983aec0fb7d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 30 May 2026 11:31:42 +0200 Subject: [PATCH] Fix incorrect use of Platform enum in component tests (#172574) --- tests/components/indevolt/test_number.py | 6 ++--- tests/components/indevolt/test_select.py | 9 ++++--- tests/components/indevolt/test_switch.py | 12 ++++++--- tests/components/pjlink/test_media_player.py | 6 ++--- tests/components/unifi_access/test_select.py | 7 +++--- tests/components/unifiprotect/test_relay.py | 16 ++++++------ tests/components/unifiprotect/test_siren.py | 26 +++++++++++--------- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/tests/components/indevolt/test_number.py b/tests/components/indevolt/test_number.py index 15d3971b277..1e830ca9c9c 100644 --- a/tests/components/indevolt/test_number.py +++ b/tests/components/indevolt/test_number.py @@ -9,7 +9,7 @@ import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.components.indevolt.coordinator import SCAN_INTERVAL -from homeassistant.components.number import SERVICE_SET_VALUE +from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE from homeassistant.const import STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -87,7 +87,7 @@ async def test_number_set_values( # Call the service to set the value await hass.services.async_call( - Platform.NUMBER, + NUMBER_DOMAIN, SERVICE_SET_VALUE, {"entity_id": entity_id, "value": test_value}, blocking=True, @@ -116,7 +116,7 @@ async def test_number_set_value_error( # Attempt to set value with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.NUMBER, + NUMBER_DOMAIN, SERVICE_SET_VALUE, { "entity_id": "number.cms_sf2000_discharge_limit", diff --git a/tests/components/indevolt/test_select.py b/tests/components/indevolt/test_select.py index 7c2a251f3a5..9ae3f87551f 100644 --- a/tests/components/indevolt/test_select.py +++ b/tests/components/indevolt/test_select.py @@ -9,7 +9,10 @@ import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.components.indevolt.coordinator import SCAN_INTERVAL -from homeassistant.components.select import SERVICE_SELECT_OPTION +from homeassistant.components.select import ( + DOMAIN as SELECT_DOMAIN, + SERVICE_SELECT_OPTION, +) from homeassistant.const import STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -66,7 +69,7 @@ async def test_select_option( # Attempt to change option await hass.services.async_call( - Platform.SELECT, + SELECT_DOMAIN, SERVICE_SELECT_OPTION, {"entity_id": "select.cms_sf2000_energy_mode", "option": option}, blocking=True, @@ -97,7 +100,7 @@ async def test_select_set_option_error( # Attempt to change option with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SELECT, + SELECT_DOMAIN, SERVICE_SELECT_OPTION, { "entity_id": "select.cms_sf2000_energy_mode", diff --git a/tests/components/indevolt/test_switch.py b/tests/components/indevolt/test_switch.py index 1184a03ce7a..2e3b2753c7d 100644 --- a/tests/components/indevolt/test_switch.py +++ b/tests/components/indevolt/test_switch.py @@ -9,7 +9,11 @@ import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.components.indevolt.coordinator import SCAN_INTERVAL -from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON +from homeassistant.components.switch import ( + DOMAIN as SWITCH_DOMAIN, + SERVICE_TURN_OFF, + SERVICE_TURN_ON, +) from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -84,7 +88,7 @@ async def test_switch_turn_on( # Call the service to turn on await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {"entity_id": entity_id}, blocking=True, @@ -143,7 +147,7 @@ async def test_switch_turn_off( # Call the service to turn off await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_OFF, {"entity_id": entity_id}, blocking=True, @@ -172,7 +176,7 @@ async def test_switch_set_value_error( # Attempt to switch on with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {"entity_id": "switch.cms_sf2000_allow_grid_charging"}, blocking=True, diff --git a/tests/components/pjlink/test_media_player.py b/tests/components/pjlink/test_media_player.py index 9ccddcff4eb..0b5c88e9308 100644 --- a/tests/components/pjlink/test_media_player.py +++ b/tests/components/pjlink/test_media_player.py @@ -274,9 +274,7 @@ async def test_yaml_import( mocked_projector: MagicMock, ) -> None: """Test a YAML media player is imported and becomes an operational config entry.""" - assert await async_setup_component( - hass, Platform.MEDIA_PLAYER, _EXAMPLE_YAML_CONFIG - ) + assert await async_setup_component(hass, media_player.DOMAIN, _EXAMPLE_YAML_CONFIG) await hass.async_block_till_done() # Verify the config entry was created @@ -308,7 +306,7 @@ async def test_failed_yaml_import( with patch("pypjlink.Projector.from_address", side_effect=side_effect): assert await async_setup_component( - hass, Platform.MEDIA_PLAYER, _EXAMPLE_YAML_CONFIG + hass, media_player.DOMAIN, _EXAMPLE_YAML_CONFIG ) await hass.async_block_till_done() diff --git a/tests/components/unifi_access/test_select.py b/tests/components/unifi_access/test_select.py index 5ee9f93c559..68ad74e727c 100644 --- a/tests/components/unifi_access/test_select.py +++ b/tests/components/unifi_access/test_select.py @@ -14,6 +14,7 @@ from unifi_access_api import ( UnifiAccessError, ) +from homeassistant.components.select import DOMAIN as SELECT_DOMAIN from homeassistant.components.unifi_access.const import DOMAIN from homeassistant.const import STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant @@ -93,7 +94,7 @@ async def test_select_option_calls_api( await setup_integration(hass, mock_config_entry) await hass.services.async_call( - Platform.SELECT, + SELECT_DOMAIN, "select_option", {"entity_id": FRONT_DOOR_LOCK_RULE_SELECT_ENTITY, "option": "keep_lock"}, blocking=True, @@ -116,7 +117,7 @@ async def test_select_schedule_option_does_not_call_api( await setup_integration(hass, mock_config_entry) await hass.services.async_call( - Platform.SELECT, + SELECT_DOMAIN, "select_option", {"entity_id": FRONT_DOOR_LOCK_RULE_SELECT_ENTITY, "option": "schedule"}, blocking=True, @@ -229,7 +230,7 @@ async def test_select_option_raises_on_api_error( with pytest.raises(HomeAssistantError) as exc_info: await hass.services.async_call( - Platform.SELECT, + SELECT_DOMAIN, "select_option", { "entity_id": FRONT_DOOR_LOCK_RULE_SELECT_ENTITY, diff --git a/tests/components/unifiprotect/test_relay.py b/tests/components/unifiprotect/test_relay.py index 51c0b613a97..a2f11fd0926 100644 --- a/tests/components/unifiprotect/test_relay.py +++ b/tests/components/unifiprotect/test_relay.py @@ -13,6 +13,7 @@ from uiprotect.data import ( from uiprotect.exceptions import ClientError, NotAuthorized from uiprotect.websocket import WebsocketState +from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, @@ -21,7 +22,6 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN, - Platform, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -167,7 +167,7 @@ async def test_relay_switch_turn_on_off( await init_entry(hass, ufp, []) await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -176,7 +176,7 @@ async def test_relay_switch_turn_on_off( relay.activate_output.reset_mock() await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -245,7 +245,7 @@ async def test_relay_switch_command_error_raises( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -264,7 +264,7 @@ async def test_relay_switch_client_error_raises( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -284,7 +284,7 @@ async def test_relay_switch_command_when_relay_gone( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -303,7 +303,7 @@ async def test_relay_switch_command_when_bootstrap_unavailable( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, @@ -456,7 +456,7 @@ async def test_relay_switch_command_when_output_gone( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SWITCH, + SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SWITCH_ENTITY_ID}, blocking=True, diff --git a/tests/components/unifiprotect/test_siren.py b/tests/components/unifiprotect/test_siren.py index 4df1b3b9451..1748adacea8 100644 --- a/tests/components/unifiprotect/test_siren.py +++ b/tests/components/unifiprotect/test_siren.py @@ -14,7 +14,11 @@ from uiprotect.data import ( from uiprotect.exceptions import ClientError, NotAuthorized from uiprotect.websocket import WebsocketState -from homeassistant.components.siren import ATTR_DURATION, ATTR_VOLUME_LEVEL +from homeassistant.components.siren import ( + ATTR_DURATION, + ATTR_VOLUME_LEVEL, + DOMAIN as SIREN_DOMAIN, +) from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, @@ -155,7 +159,7 @@ async def test_siren_turn_on( await init_entry(hass, ufp_with_siren, []) await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True, @@ -183,7 +187,7 @@ async def test_siren_turn_on_with_duration( await init_entry(hass, ufp_with_siren, []) await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID, ATTR_DURATION: seconds}, blocking=True, @@ -201,7 +205,7 @@ async def test_siren_turn_on_invalid_duration( with pytest.raises(ServiceValidationError): await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID, ATTR_DURATION: 15}, blocking=True, @@ -223,7 +227,7 @@ async def test_siren_turn_on_invalid_duration_does_not_set_volume( with pytest.raises(ServiceValidationError): await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, { ATTR_ENTITY_ID: SIREN_ENTITY_ID, @@ -245,7 +249,7 @@ async def test_siren_turn_on_with_volume( await init_entry(hass, ufp_with_siren, []) await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID, ATTR_VOLUME_LEVEL: 0.75}, blocking=True, @@ -268,7 +272,7 @@ async def test_siren_turn_off( assert state.state == STATE_ON await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True, @@ -301,7 +305,7 @@ async def test_siren_turn_on_api_error( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True, @@ -319,7 +323,7 @@ async def test_siren_turn_on_when_siren_gone( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True, @@ -337,7 +341,7 @@ async def test_siren_turn_off_when_bootstrap_unavailable( with pytest.raises(HomeAssistantError): await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True, @@ -506,7 +510,7 @@ async def test_siren_turn_off_cancels_scheduled_timer( # Manually turn off — must cancel the scheduled timer. await hass.services.async_call( - Platform.SIREN, + SIREN_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: SIREN_ENTITY_ID}, blocking=True,