mirror of
https://github.com/home-assistant/core.git
synced 2026-07-02 04:06:41 +01:00
Fix incorrect use of Platform enum in component tests (#172574)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user