Add alias to DOMAIN import in tests [n-z] (#125581)

This commit is contained in:
epenet 2024-09-09 15:14:05 +02:00 committed by GitHub
parent dee4b33c64
commit af6434a533
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 240 additions and 209 deletions

View File

@ -1,6 +1,10 @@
"""The tests for notify_events.""" """The tests for notify_events."""
from homeassistant.components.notify import ATTR_DATA, ATTR_MESSAGE, DOMAIN from homeassistant.components.notify import (
ATTR_DATA,
ATTR_MESSAGE,
DOMAIN as NOTIFY_DOMAIN,
)
from homeassistant.components.notify_events.notify import ( from homeassistant.components.notify_events.notify import (
ATTR_LEVEL, ATTR_LEVEL,
ATTR_PRIORITY, ATTR_PRIORITY,
@ -13,10 +17,10 @@ from tests.common import async_mock_service
async def test_send_msg(hass: HomeAssistant) -> None: async def test_send_msg(hass: HomeAssistant) -> None:
"""Test notify.events service.""" """Test notify.events service."""
notify_calls = async_mock_service(hass, DOMAIN, "events") notify_calls = async_mock_service(hass, NOTIFY_DOMAIN, "events")
await hass.services.async_call( await hass.services.async_call(
DOMAIN, NOTIFY_DOMAIN,
"events", "events",
{ {
ATTR_MESSAGE: "message content", ATTR_MESSAGE: "message content",
@ -32,7 +36,7 @@ async def test_send_msg(hass: HomeAssistant) -> None:
assert len(notify_calls) == 1 assert len(notify_calls) == 1
call = notify_calls[-1] call = notify_calls[-1]
assert call.domain == DOMAIN assert call.domain == NOTIFY_DOMAIN
assert call.service == "events" assert call.service == "events"
assert call.data.get(ATTR_MESSAGE) == "message content" assert call.data.get(ATTR_MESSAGE) == "message content"
assert call.data.get(ATTR_DATA).get(ATTR_TOKEN) == "XYZ" assert call.data.get(ATTR_DATA).get(ATTR_TOKEN) == "XYZ"

View File

@ -5,7 +5,7 @@ from unittest.mock import MagicMock, Mock
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from homeassistant.components.todo import ATTR_ITEM, DOMAIN, TodoServices from homeassistant.components.todo import ATTR_ITEM, DOMAIN as TODO_DOMAIN, TodoServices
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
@ -91,7 +91,7 @@ async def test_create_todo_list_item(
mock_picnic_api.add_product = Mock() mock_picnic_api.add_product = Mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, TODO_DOMAIN,
TodoServices.ADD_ITEM, TodoServices.ADD_ITEM,
{ATTR_ITEM: "Melk"}, {ATTR_ITEM: "Melk"},
target={ATTR_ENTITY_ID: ENTITY_ID}, target={ATTR_ENTITY_ID: ENTITY_ID},
@ -119,7 +119,7 @@ async def test_create_todo_list_item_not_found(
with pytest.raises(ServiceValidationError): with pytest.raises(ServiceValidationError):
await hass.services.async_call( await hass.services.async_call(
DOMAIN, TODO_DOMAIN,
TodoServices.ADD_ITEM, TodoServices.ADD_ITEM,
{ATTR_ITEM: "Melk"}, {ATTR_ITEM: "Melk"},
target={ATTR_ENTITY_ID: ENTITY_ID}, target={ATTR_ENTITY_ID: ENTITY_ID},

View File

@ -1,6 +1,9 @@
"""The tests for SleepIQ binary sensor platform.""" """The tests for SleepIQ binary sensor platform."""
from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDeviceClass from homeassistant.components.binary_sensor import (
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
ATTR_FRIENDLY_NAME, ATTR_FRIENDLY_NAME,
@ -28,7 +31,7 @@ async def test_binary_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ binary sensors.""" """Test the SleepIQ binary sensors."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, BINARY_SENSOR_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"binary_sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_is_in_bed" f"binary_sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_is_in_bed"

View File

@ -1,6 +1,6 @@
"""The tests for SleepIQ binary sensor platform.""" """The tests for SleepIQ binary sensor platform."""
from homeassistant.components.button import DOMAIN from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -12,7 +12,7 @@ async def test_button_calibrate(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ calibrate button.""" """Test the SleepIQ calibrate button."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, BUTTON_DOMAIN)
state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_calibrate") state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_calibrate")
assert ( assert (
@ -24,7 +24,7 @@ async def test_button_calibrate(
assert entity.unique_id == f"{BED_ID}-calibrate" assert entity.unique_id == f"{BED_ID}-calibrate"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, BUTTON_DOMAIN,
"press", "press",
{ATTR_ENTITY_ID: f"button.sleepnumber_{BED_NAME_LOWER}_calibrate"}, {ATTR_ENTITY_ID: f"button.sleepnumber_{BED_NAME_LOWER}_calibrate"},
blocking=True, blocking=True,
@ -38,7 +38,7 @@ async def test_button_stop_pump(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ stop pump button.""" """Test the SleepIQ stop pump button."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, BUTTON_DOMAIN)
state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_stop_pump") state = hass.states.get(f"button.sleepnumber_{BED_NAME_LOWER}_stop_pump")
assert ( assert (
@ -50,7 +50,7 @@ async def test_button_stop_pump(
assert entity.unique_id == f"{BED_ID}-stop-pump" assert entity.unique_id == f"{BED_ID}-stop-pump"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, BUTTON_DOMAIN,
"press", "press",
{ATTR_ENTITY_ID: f"button.sleepnumber_{BED_NAME_LOWER}_stop_pump"}, {ATTR_ENTITY_ID: f"button.sleepnumber_{BED_NAME_LOWER}_stop_pump"},
blocking=True, blocking=True,

View File

@ -1,6 +1,6 @@
"""The tests for SleepIQ light platform.""" """The tests for SleepIQ light platform."""
from homeassistant.components.light import DOMAIN from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.components.sleepiq.coordinator import LONGER_UPDATE_INTERVAL from homeassistant.components.sleepiq.coordinator import LONGER_UPDATE_INTERVAL
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.core import HomeAssistant
@ -16,7 +16,7 @@ async def test_setup(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test for successfully setting up the SleepIQ platform.""" """Test for successfully setting up the SleepIQ platform."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, LIGHT_DOMAIN)
assert len(entity_registry.entities) == 2 assert len(entity_registry.entities) == 2
@ -33,10 +33,10 @@ async def test_setup(
async def test_light_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None: async def test_light_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
"""Test light change.""" """Test light change."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, LIGHT_DOMAIN)
await hass.services.async_call( await hass.services.async_call(
DOMAIN, LIGHT_DOMAIN,
"turn_on", "turn_on",
{ATTR_ENTITY_ID: f"light.sleepnumber_{BED_NAME_LOWER}_light_1"}, {ATTR_ENTITY_ID: f"light.sleepnumber_{BED_NAME_LOWER}_light_1"},
blocking=True, blocking=True,
@ -45,7 +45,7 @@ async def test_light_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
mock_asyncsleepiq.beds[BED_ID].foundation.lights[0].turn_on.assert_called_once() mock_asyncsleepiq.beds[BED_ID].foundation.lights[0].turn_on.assert_called_once()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, LIGHT_DOMAIN,
"turn_off", "turn_off",
{ATTR_ENTITY_ID: f"light.sleepnumber_{BED_NAME_LOWER}_light_1"}, {ATTR_ENTITY_ID: f"light.sleepnumber_{BED_NAME_LOWER}_light_1"},
blocking=True, blocking=True,
@ -56,7 +56,7 @@ async def test_light_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None: async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
"""Test light update.""" """Test light update."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, LIGHT_DOMAIN)
assert ( assert (
hass.states.get(f"light.sleepnumber_{BED_NAME_LOWER}_light_1").state hass.states.get(f"light.sleepnumber_{BED_NAME_LOWER}_light_1").state

View File

@ -5,7 +5,7 @@ from homeassistant.components.number import (
ATTR_MIN, ATTR_MIN,
ATTR_STEP, ATTR_STEP,
ATTR_VALUE, ATTR_VALUE,
DOMAIN, DOMAIN as NUMBER_DOMAIN,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
) )
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON
@ -30,7 +30,7 @@ async def test_firmness(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ firmness number values for a bed with two sides.""" """Test the SleepIQ firmness number values for a bed with two sides."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, NUMBER_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_firmness" f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_firmness"
@ -71,7 +71,7 @@ async def test_firmness(
assert entry.unique_id == f"{SLEEPER_R_ID}_firmness" assert entry.unique_id == f"{SLEEPER_R_ID}_firmness"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, NUMBER_DOMAIN,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
{ {
ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_firmness", ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_firmness",
@ -89,7 +89,7 @@ async def test_actuators(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ actuator position values for a bed with adjustable head and foot.""" """Test the SleepIQ actuator position values for a bed with adjustable head and foot."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, NUMBER_DOMAIN)
state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position") state = hass.states.get(f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position")
assert state.state == "60.0" assert state.state == "60.0"
@ -143,7 +143,7 @@ async def test_actuators(
assert entry.unique_id == f"{BED_ID}_F" assert entry.unique_id == f"{BED_ID}_F"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, NUMBER_DOMAIN,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
{ {
ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position", ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_right_head_position",
@ -165,7 +165,7 @@ async def test_foot_warmer_timer(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ foot warmer number values for a bed with two sides.""" """Test the SleepIQ foot warmer number values for a bed with two sides."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, NUMBER_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warming_timer" f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warming_timer"
@ -187,7 +187,7 @@ async def test_foot_warmer_timer(
assert entry.unique_id == f"{BED_ID}_L_foot_warming_timer" assert entry.unique_id == f"{BED_ID}_L_foot_warming_timer"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, NUMBER_DOMAIN,
SERVICE_SET_VALUE, SERVICE_SET_VALUE,
{ {
ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warming_timer", ATTR_ENTITY_ID: f"number.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warming_timer",

View File

@ -4,7 +4,10 @@ from unittest.mock import MagicMock
from asyncsleepiq import FootWarmingTemps from asyncsleepiq import FootWarmingTemps
from homeassistant.components.select import DOMAIN, SERVICE_SELECT_OPTION from homeassistant.components.select import (
DOMAIN as SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME, ATTR_FRIENDLY_NAME,
@ -37,7 +40,7 @@ async def test_split_foundation_preset(
mock_asyncsleepiq: MagicMock, mock_asyncsleepiq: MagicMock,
) -> None: ) -> None:
"""Test the SleepIQ select entity for split foundation presets.""" """Test the SleepIQ select entity for split foundation presets."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SELECT_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset_right" f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset_right"
@ -72,7 +75,7 @@ async def test_split_foundation_preset(
assert entry.unique_id == f"{BED_ID}_preset_L" assert entry.unique_id == f"{BED_ID}_preset_L"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SELECT_DOMAIN,
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION,
{ {
ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset_left", ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset_left",
@ -94,7 +97,7 @@ async def test_single_foundation_preset(
mock_asyncsleepiq_single_foundation: MagicMock, mock_asyncsleepiq_single_foundation: MagicMock,
) -> None: ) -> None:
"""Test the SleepIQ select entity for single foundation presets.""" """Test the SleepIQ select entity for single foundation presets."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SELECT_DOMAIN)
state = hass.states.get(f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset") state = hass.states.get(f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset")
assert state.state == PRESET_R_STATE assert state.state == PRESET_R_STATE
@ -111,7 +114,7 @@ async def test_single_foundation_preset(
assert entry.unique_id == f"{BED_ID}_preset" assert entry.unique_id == f"{BED_ID}_preset"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SELECT_DOMAIN,
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION,
{ {
ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset", ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_foundation_preset",
@ -135,7 +138,7 @@ async def test_foot_warmer(
mock_asyncsleepiq: MagicMock, mock_asyncsleepiq: MagicMock,
) -> None: ) -> None:
"""Test the SleepIQ select entity for foot warmers.""" """Test the SleepIQ select entity for foot warmers."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SELECT_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warmer" f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warmer"
@ -154,7 +157,7 @@ async def test_foot_warmer(
assert entry.unique_id == f"{SLEEPER_L_ID}_foot_warmer" assert entry.unique_id == f"{SLEEPER_L_ID}_foot_warmer"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SELECT_DOMAIN,
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION,
{ {
ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warmer", ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_foot_warmer",
@ -185,7 +188,7 @@ async def test_foot_warmer(
assert entry.unique_id == f"{SLEEPER_R_ID}_foot_warmer" assert entry.unique_id == f"{SLEEPER_R_ID}_foot_warmer"
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SELECT_DOMAIN,
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION,
{ {
ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_R_NAME_LOWER}_foot_warmer", ATTR_ENTITY_ID: f"select.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_R_NAME_LOWER}_foot_warmer",

View File

@ -1,6 +1,6 @@
"""The tests for SleepIQ sensor platform.""" """The tests for SleepIQ sensor platform."""
from homeassistant.components.sensor import DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -22,7 +22,7 @@ async def test_sleepnumber_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ sleepnumber for a bed with two sides.""" """Test the SleepIQ sleepnumber for a bed with two sides."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SENSOR_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_sleepnumber" f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_sleepnumber"
@ -61,7 +61,7 @@ async def test_pressure_sensors(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test the SleepIQ pressure for a bed with two sides.""" """Test the SleepIQ pressure for a bed with two sides."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SENSOR_DOMAIN)
state = hass.states.get( state = hass.states.get(
f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_pressure" f"sensor.sleepnumber_{BED_NAME_LOWER}_{SLEEPER_L_NAME_LOWER}_pressure"

View File

@ -1,7 +1,7 @@
"""The tests for SleepIQ switch platform.""" """The tests for SleepIQ switch platform."""
from homeassistant.components.sleepiq.coordinator import LONGER_UPDATE_INTERVAL from homeassistant.components.sleepiq.coordinator import LONGER_UPDATE_INTERVAL
from homeassistant.components.switch import DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
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.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -16,7 +16,7 @@ async def test_setup(
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_asyncsleepiq
) -> None: ) -> None:
"""Test for successfully setting up the SleepIQ platform.""" """Test for successfully setting up the SleepIQ platform."""
entry = await setup_platform(hass, DOMAIN) entry = await setup_platform(hass, SWITCH_DOMAIN)
assert len(entity_registry.entities) == 1 assert len(entity_registry.entities) == 1
@ -28,10 +28,10 @@ async def test_setup(
async def test_switch_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None: async def test_switch_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
"""Test button press.""" """Test button press."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, SWITCH_DOMAIN)
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SWITCH_DOMAIN,
"turn_off", "turn_off",
{ATTR_ENTITY_ID: f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode"}, {ATTR_ENTITY_ID: f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode"},
blocking=True, blocking=True,
@ -40,7 +40,7 @@ async def test_switch_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None
mock_asyncsleepiq.beds[BED_ID].set_pause_mode.assert_called_with(False) mock_asyncsleepiq.beds[BED_ID].set_pause_mode.assert_called_with(False)
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SWITCH_DOMAIN,
"turn_on", "turn_on",
{ATTR_ENTITY_ID: f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode"}, {ATTR_ENTITY_ID: f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode"},
blocking=True, blocking=True,
@ -51,7 +51,7 @@ async def test_switch_set_states(hass: HomeAssistant, mock_asyncsleepiq) -> None
async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None: async def test_switch_get_states(hass: HomeAssistant, mock_asyncsleepiq) -> None:
"""Test button press.""" """Test button press."""
await setup_platform(hass, DOMAIN) await setup_platform(hass, SWITCH_DOMAIN)
assert ( assert (
hass.states.get(f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode").state hass.states.get(f"switch.sleepnumber_{BED_NAME_LOWER}_pause_mode").state

View File

@ -5,7 +5,11 @@ from typing import Any
import pytest import pytest
from homeassistant import setup from homeassistant import setup
from homeassistant.components.cover import ATTR_POSITION, ATTR_TILT_POSITION, DOMAIN from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DOMAIN as COVER_DOMAIN,
)
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
@ -51,13 +55,13 @@ OPEN_CLOSE_COVER_CONFIG = {
} }
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "states"), ("config", "states"),
[ [
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -102,7 +106,7 @@ OPEN_CLOSE_COVER_CONFIG = {
), ),
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -152,13 +156,13 @@ async def test_template_state_text(
assert text in caplog.text assert text in caplog.text
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "entity", "set_state", "test_state", "attr"), ("config", "entity", "set_state", "test_state", "attr"),
[ [
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -178,7 +182,7 @@ async def test_template_state_text(
), ),
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -218,12 +222,12 @@ async def test_template_state_text_ignored_if_none_or_empty(
assert "ERROR" not in caplog.text assert "ERROR" not in caplog.text
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -241,12 +245,12 @@ async def test_template_state_boolean(hass: HomeAssistant, start_ha) -> None:
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -281,12 +285,12 @@ async def test_template_position(
assert "ValueError" not in caplog.text assert "ValueError" not in caplog.text
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -304,13 +308,13 @@ async def test_template_not_optimistic(hass: HomeAssistant, start_ha) -> None:
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "tilt_position"), ("config", "tilt_position"),
[ [
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -325,7 +329,7 @@ async def test_template_not_optimistic(hass: HomeAssistant, start_ha) -> None:
), ),
( (
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -348,12 +352,12 @@ async def test_template_tilt(
assert state.attributes.get("current_tilt_position") == tilt_position assert state.attributes.get("current_tilt_position") == tilt_position
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -365,7 +369,7 @@ async def test_template_tilt(
} }
}, },
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -391,18 +395,18 @@ async def test_template_out_of_bounds(hass: HomeAssistant, start_ha) -> None:
assert state.attributes.get("current_position") is None assert state.attributes.get("current_position") is None
@pytest.mark.parametrize(("count", "domain"), [(0, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(0, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": {"test_template_cover": {"value_template": "{{ 1 == 1 }}"}}, "covers": {"test_template_cover": {"value_template": "{{ 1 == 1 }}"}},
} }
}, },
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -428,12 +432,12 @@ async def test_template_open_or_position(
assert "Invalid config for 'cover' from integration 'template'" in caplog_setup_text assert "Invalid config for 'cover' from integration 'template'" in caplog_setup_text
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -453,7 +457,7 @@ async def test_open_action(
assert state.state == STATE_CLOSED assert state.state == STATE_CLOSED
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -462,12 +466,12 @@ async def test_open_action(
assert calls[0].data["caller"] == "cover.test_template_cover" assert calls[0].data["caller"] == "cover.test_template_cover"
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -494,12 +498,12 @@ async def test_close_stop_action(
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -554,7 +558,7 @@ async def test_set_position(
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
@ -565,7 +569,7 @@ async def test_set_position(
assert calls[-1].data["position"] == 100 assert calls[-1].data["position"] == 100
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
@ -576,7 +580,7 @@ async def test_set_position(
assert calls[-1].data["position"] == 0 assert calls[-1].data["position"] == 0
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
@ -587,7 +591,7 @@ async def test_set_position(
assert calls[-1].data["position"] == 100 assert calls[-1].data["position"] == 100
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
@ -598,7 +602,7 @@ async def test_set_position(
assert calls[-1].data["position"] == 0 assert calls[-1].data["position"] == 0
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 25}, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 25},
blocking=True, blocking=True,
@ -612,12 +616,12 @@ async def test_set_position(
assert calls[-1].data["position"] == 25 assert calls[-1].data["position"] == 25
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -658,7 +662,7 @@ async def test_set_tilt_position(
) -> None: ) -> None:
"""Test the set_tilt_position command.""" """Test the set_tilt_position command."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
service, service,
attr, attr,
blocking=True, blocking=True,
@ -671,12 +675,12 @@ async def test_set_tilt_position(
assert calls[-1].data["tilt_position"] == tilt_position assert calls[-1].data["tilt_position"] == tilt_position
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -695,7 +699,7 @@ async def test_set_position_optimistic(
assert state.attributes.get("current_position") is None assert state.attributes.get("current_position") is None
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 42}, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_POSITION: 42},
blocking=True, blocking=True,
@ -711,19 +715,19 @@ async def test_set_position_optimistic(
(SERVICE_TOGGLE, STATE_OPEN), (SERVICE_TOGGLE, STATE_OPEN),
): ):
await hass.services.async_call( await hass.services.async_call(
DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
assert state.state == test_state assert state.state == test_state
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -744,7 +748,7 @@ async def test_set_tilt_position_optimistic(
assert state.attributes.get("current_tilt_position") is None assert state.attributes.get("current_tilt_position") is None
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_TILT_POSITION, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42}, {ATTR_ENTITY_ID: ENTITY_COVER, ATTR_TILT_POSITION: 42},
blocking=True, blocking=True,
@ -760,19 +764,19 @@ async def test_set_tilt_position_optimistic(
(SERVICE_TOGGLE_COVER_TILT, 100.0), (SERVICE_TOGGLE_COVER_TILT, 100.0),
): ):
await hass.services.async_call( await hass.services.async_call(
DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True COVER_DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_COVER}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("cover.test_template_cover") state = hass.states.get("cover.test_template_cover")
assert state.attributes.get("current_tilt_position") == pos assert state.attributes.get("current_tilt_position") == pos
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -800,12 +804,12 @@ async def test_icon_template(hass: HomeAssistant, start_ha) -> None:
assert state.attributes["icon"] == "mdi:check" assert state.attributes["icon"] == "mdi:check"
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -835,12 +839,12 @@ async def test_entity_picture_template(hass: HomeAssistant, start_ha) -> None:
assert state.attributes["entity_picture"] == "/local/cover.png" assert state.attributes["entity_picture"] == "/local/cover.png"
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -868,12 +872,12 @@ async def test_availability_template(hass: HomeAssistant, start_ha) -> None:
assert hass.states.get("cover.test_template_cover").state != STATE_UNAVAILABLE assert hass.states.get("cover.test_template_cover").state != STATE_UNAVAILABLE
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -893,12 +897,12 @@ async def test_availability_without_availability_template(
assert state.state != STATE_UNAVAILABLE assert state.state != STATE_UNAVAILABLE
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -919,12 +923,12 @@ async def test_invalid_availability_template_keeps_component_available(
assert "UndefinedError: 'x' is undefined" in caplog_setup_text assert "UndefinedError: 'x' is undefined" in caplog_setup_text
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -943,12 +947,12 @@ async def test_device_class(hass: HomeAssistant, start_ha) -> None:
assert state.attributes.get("device_class") == "door" assert state.attributes.get("device_class") == "door"
@pytest.mark.parametrize(("count", "domain"), [(0, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(0, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover": { "test_template_cover": {
@ -967,12 +971,12 @@ async def test_invalid_device_class(hass: HomeAssistant, start_ha) -> None:
assert not state assert not state
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"test_template_cover_01": { "test_template_cover_01": {
@ -995,12 +999,12 @@ async def test_unique_id(hass: HomeAssistant, start_ha) -> None:
assert len(hass.states.async_all()) == 1 assert len(hass.states.async_all()) == 1
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"garage_door": { "garage_door": {
@ -1029,12 +1033,12 @@ async def test_state_gets_lowercased(hass: HomeAssistant, start_ha) -> None:
assert hass.states.get("cover.garage_door").state == STATE_CLOSED assert hass.states.get("cover.garage_door").state == STATE_CLOSED
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, COVER_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { COVER_DOMAIN: {
"platform": "template", "platform": "template",
"covers": { "covers": {
"office": { "office": {

View File

@ -11,7 +11,7 @@ from homeassistant.components.fan import (
ATTR_PRESET_MODE, ATTR_PRESET_MODE,
DIRECTION_FORWARD, DIRECTION_FORWARD,
DIRECTION_REVERSE, DIRECTION_REVERSE,
DOMAIN, DOMAIN as FAN_DOMAIN,
FanEntityFeature, FanEntityFeature,
NotValidPresetModeError, NotValidPresetModeError,
) )
@ -36,12 +36,12 @@ _OSC_INPUT = "input_select.osc"
_DIRECTION_INPUT_SELECT = "input_select.direction" _DIRECTION_INPUT_SELECT = "input_select.direction"
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -59,12 +59,12 @@ async def test_missing_optional_config(hass: HomeAssistant, start_ha) -> None:
_verify(hass, STATE_ON, None, None, None, None) _verify(hass, STATE_ON, None, None, None, None)
@pytest.mark.parametrize(("count", "domain"), [(0, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(0, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"platform": "template", "platform": "template",
@ -78,7 +78,7 @@ async def test_missing_optional_config(hass: HomeAssistant, start_ha) -> None:
} }
}, },
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"platform": "template", "platform": "template",
@ -92,7 +92,7 @@ async def test_missing_optional_config(hass: HomeAssistant, start_ha) -> None:
} }
}, },
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"platform": "template", "platform": "template",
@ -112,12 +112,12 @@ async def test_wrong_template_config(hass: HomeAssistant, start_ha) -> None:
assert hass.states.async_all("fan") == [] assert hass.states.async_all("fan") == []
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -173,13 +173,13 @@ async def test_templates_with_entities(hass: HomeAssistant, start_ha) -> None:
_verify(hass, STATE_OFF, 0, True, DIRECTION_FORWARD, None) _verify(hass, STATE_OFF, 0, True, DIRECTION_FORWARD, None)
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "entity", "tests"), ("config", "entity", "tests"),
[ [
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -203,7 +203,7 @@ async def test_templates_with_entities(hass: HomeAssistant, start_ha) -> None:
), ),
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -239,12 +239,12 @@ async def test_templates_with_entities2(
_verify(hass, STATE_ON, test_percentage, None, None, test_type) _verify(hass, STATE_ON, test_percentage, None, None, test_type)
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -272,13 +272,13 @@ async def test_availability_template_with_entities(
assert (hass.states.get(_TEST_FAN).state != STATE_UNAVAILABLE) == test_assert assert (hass.states.get(_TEST_FAN).state != STATE_UNAVAILABLE) == test_assert
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
("config", "states"), ("config", "states"),
[ [
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -293,7 +293,7 @@ async def test_availability_template_with_entities(
), ),
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -311,7 +311,7 @@ async def test_availability_template_with_entities(
), ),
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -329,7 +329,7 @@ async def test_availability_template_with_entities(
), ),
( (
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -354,12 +354,12 @@ async def test_template_with_unavailable_entities(
_verify(hass, states[0], states[1], states[2], states[3], None) _verify(hass, states[0], states[1], states[2], states[3], None)
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_fan": { "test_fan": {
@ -903,12 +903,12 @@ async def _register_components(
await hass.async_block_till_done() await hass.async_block_till_done()
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"test_template_fan_01": { "test_template_fan_01": {
@ -1024,12 +1024,12 @@ async def test_implemented_percentage(
assert attributes.get("supported_features") & FanEntityFeature.SET_SPEED assert attributes.get("supported_features") & FanEntityFeature.SET_SPEED
@pytest.mark.parametrize(("count", "domain"), [(1, DOMAIN)]) @pytest.mark.parametrize(("count", "domain"), [(1, FAN_DOMAIN)])
@pytest.mark.parametrize( @pytest.mark.parametrize(
"config", "config",
[ [
{ {
DOMAIN: { FAN_DOMAIN: {
"platform": "template", "platform": "template",
"fans": { "fans": {
"mechanical_ventilation": { "mechanical_ventilation": {

View File

@ -7,7 +7,7 @@ import requests
import requests_mock import requests_mock
import voluptuous as vol import voluptuous as vol
from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
import homeassistant.components.tomato.device_tracker as tomato import homeassistant.components.tomato.device_tracker as tomato
from homeassistant.const import ( from homeassistant.const import (
CONF_HOST, CONF_HOST,
@ -68,7 +68,7 @@ def mock_session_send():
def test_config_missing_optional_params(hass: HomeAssistant, mock_session_send) -> None: def test_config_missing_optional_params(hass: HomeAssistant, mock_session_send) -> None:
"""Test the setup without optional parameters.""" """Test the setup without optional parameters."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -94,7 +94,7 @@ def test_config_missing_optional_params(hass: HomeAssistant, mock_session_send)
def test_config_default_nonssl_port(hass: HomeAssistant, mock_session_send) -> None: def test_config_default_nonssl_port(hass: HomeAssistant, mock_session_send) -> None:
"""Test the setup without a default port set without ssl enabled.""" """Test the setup without a default port set without ssl enabled."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -113,7 +113,7 @@ def test_config_default_nonssl_port(hass: HomeAssistant, mock_session_send) -> N
def test_config_default_ssl_port(hass: HomeAssistant, mock_session_send) -> None: def test_config_default_ssl_port(hass: HomeAssistant, mock_session_send) -> None:
"""Test the setup without a default port set with ssl enabled.""" """Test the setup without a default port set with ssl enabled."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -135,7 +135,7 @@ def test_config_verify_ssl_but_no_ssl_enabled(
) -> None: ) -> None:
"""Test the setup with a string with ssl_verify but ssl not enabled.""" """Test the setup with a string with ssl_verify but ssl not enabled."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -169,7 +169,7 @@ def test_config_valid_verify_ssl_path(hass: HomeAssistant, mock_session_send) ->
Representing the absolute path to a CA certificate bundle. Representing the absolute path to a CA certificate bundle.
""" """
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -200,7 +200,7 @@ def test_config_valid_verify_ssl_path(hass: HomeAssistant, mock_session_send) ->
def test_config_valid_verify_ssl_bool(hass: HomeAssistant, mock_session_send) -> None: def test_config_valid_verify_ssl_bool(hass: HomeAssistant, mock_session_send) -> None:
"""Test the setup with a bool for ssl_verify.""" """Test the setup with a bool for ssl_verify."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -301,7 +301,7 @@ def test_config_errors() -> None:
def test_config_bad_credentials(hass: HomeAssistant, mock_exception_logger) -> None: def test_config_bad_credentials(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test the setup with bad credentials.""" """Test the setup with bad credentials."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -324,7 +324,7 @@ def test_config_bad_credentials(hass: HomeAssistant, mock_exception_logger) -> N
def test_bad_response(hass: HomeAssistant, mock_exception_logger) -> None: def test_bad_response(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test the setup with bad response from router.""" """Test the setup with bad response from router."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -347,7 +347,7 @@ def test_bad_response(hass: HomeAssistant, mock_exception_logger) -> None:
def test_scan_devices(hass: HomeAssistant, mock_exception_logger) -> None: def test_scan_devices(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test scanning for new devices.""" """Test scanning for new devices."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -366,7 +366,7 @@ def test_scan_devices(hass: HomeAssistant, mock_exception_logger) -> None:
def test_bad_connection(hass: HomeAssistant, mock_exception_logger) -> None: def test_bad_connection(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test the router with a connection error.""" """Test the router with a connection error."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -394,7 +394,7 @@ def test_bad_connection(hass: HomeAssistant, mock_exception_logger) -> None:
def test_router_timeout(hass: HomeAssistant, mock_exception_logger) -> None: def test_router_timeout(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test the router with a timeout error.""" """Test the router with a timeout error."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",
@ -422,7 +422,7 @@ def test_router_timeout(hass: HomeAssistant, mock_exception_logger) -> None:
def test_get_device_name(hass: HomeAssistant, mock_exception_logger) -> None: def test_get_device_name(hass: HomeAssistant, mock_exception_logger) -> None:
"""Test getting device names.""" """Test getting device names."""
config = { config = {
DOMAIN: tomato.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: tomato.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: tomato.DOMAIN, CONF_PLATFORM: tomato.DOMAIN,
CONF_HOST: "tomato-router", CONF_HOST: "tomato-router",

View File

@ -2,7 +2,7 @@
import requests_mock import requests_mock
from homeassistant.components.climate import DOMAIN from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.const import CONF_HOST, CONF_PLATFORM from homeassistant.const import CONF_HOST, CONF_PLATFORM
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -54,7 +54,7 @@ async def async_init_integration(
} }
for model in TEST_MODELS for model in TEST_MODELS
] ]
config = {DOMAIN: platform_config} config = {CLIMATE_DOMAIN: platform_config}
await async_setup_component(hass, DOMAIN, config) await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()

View File

@ -6,7 +6,7 @@ from unittest.mock import MagicMock, call, patch
import requests import requests
from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_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
@ -154,7 +154,7 @@ def mocked_requests(*args, **kwargs):
async def test_config(xiaomi_mock, hass: HomeAssistant) -> None: async def test_config(xiaomi_mock, hass: HomeAssistant) -> None:
"""Testing minimal configuration.""" """Testing minimal configuration."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: xiaomi.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: xiaomi.DOMAIN, CONF_PLATFORM: xiaomi.DOMAIN,
CONF_HOST: "192.168.0.1", CONF_HOST: "192.168.0.1",
@ -164,7 +164,7 @@ async def test_config(xiaomi_mock, hass: HomeAssistant) -> None:
} }
xiaomi.get_scanner(hass, config) xiaomi.get_scanner(hass, config)
assert xiaomi_mock.call_count == 1 assert xiaomi_mock.call_count == 1
assert xiaomi_mock.call_args == call(config[DOMAIN]) assert xiaomi_mock.call_args == call(config[DEVICE_TRACKER_DOMAIN])
call_arg = xiaomi_mock.call_args[0][0] call_arg = xiaomi_mock.call_args[0][0]
assert call_arg["username"] == "admin" assert call_arg["username"] == "admin"
assert call_arg["password"] == "passwordTest" assert call_arg["password"] == "passwordTest"
@ -179,7 +179,7 @@ async def test_config(xiaomi_mock, hass: HomeAssistant) -> None:
async def test_config_full(xiaomi_mock, hass: HomeAssistant) -> None: async def test_config_full(xiaomi_mock, hass: HomeAssistant) -> None:
"""Testing full configuration.""" """Testing full configuration."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: xiaomi.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: xiaomi.DOMAIN, CONF_PLATFORM: xiaomi.DOMAIN,
CONF_HOST: "192.168.0.1", CONF_HOST: "192.168.0.1",
@ -190,7 +190,7 @@ async def test_config_full(xiaomi_mock, hass: HomeAssistant) -> None:
} }
xiaomi.get_scanner(hass, config) xiaomi.get_scanner(hass, config)
assert xiaomi_mock.call_count == 1 assert xiaomi_mock.call_count == 1
assert xiaomi_mock.call_args == call(config[DOMAIN]) assert xiaomi_mock.call_args == call(config[DEVICE_TRACKER_DOMAIN])
call_arg = xiaomi_mock.call_args[0][0] call_arg = xiaomi_mock.call_args[0][0]
assert call_arg["username"] == "alternativeAdminName" assert call_arg["username"] == "alternativeAdminName"
assert call_arg["password"] == "passwordTest" assert call_arg["password"] == "passwordTest"
@ -203,7 +203,7 @@ async def test_config_full(xiaomi_mock, hass: HomeAssistant) -> None:
async def test_invalid_credential(mock_get, mock_post, hass: HomeAssistant) -> None: 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( DEVICE_TRACKER_DOMAIN: xiaomi.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: xiaomi.DOMAIN, CONF_PLATFORM: xiaomi.DOMAIN,
CONF_HOST: "192.168.0.1", CONF_HOST: "192.168.0.1",
@ -220,7 +220,7 @@ async def test_invalid_credential(mock_get, mock_post, hass: HomeAssistant) -> N
async def test_valid_credential(mock_get, mock_post, hass: HomeAssistant) -> None: async def test_valid_credential(mock_get, mock_post, hass: HomeAssistant) -> None:
"""Testing valid refresh.""" """Testing valid refresh."""
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: xiaomi.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: xiaomi.DOMAIN, CONF_PLATFORM: xiaomi.DOMAIN,
CONF_HOST: "192.168.0.1", CONF_HOST: "192.168.0.1",
@ -244,7 +244,7 @@ async def test_token_timed_out(mock_get, mock_post, hass: HomeAssistant) -> None
New token is requested and list is downloaded a second time. New token is requested and list is downloaded a second time.
""" """
config = { config = {
DOMAIN: xiaomi.PLATFORM_SCHEMA( DEVICE_TRACKER_DOMAIN: xiaomi.PLATFORM_SCHEMA(
{ {
CONF_PLATFORM: xiaomi.DOMAIN, CONF_PLATFORM: xiaomi.DOMAIN,
CONF_HOST: "192.168.0.1", CONF_HOST: "192.168.0.1",

View File

@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch
import pytest import pytest
from homeassistant.components.button import DOMAIN, SERVICE_PRESS from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.components.xiaomi_miio.const import ( from homeassistant.components.xiaomi_miio.const import (
CONF_FLOW_TYPE, CONF_FLOW_TYPE,
DOMAIN as XIAOMI_DOMAIN, DOMAIN as XIAOMI_DOMAIN,
@ -68,7 +68,7 @@ async def test_vacuum_button_press(hass: HomeAssistant) -> None:
pressed_at = dt_util.utcnow() pressed_at = dt_util.utcnow()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, BUTTON_DOMAIN,
SERVICE_PRESS, SERVICE_PRESS,
{ATTR_ENTITY_ID: entity_id + "_reset_side_brush"}, {ATTR_ENTITY_ID: entity_id + "_reset_side_brush"},
blocking=True, blocking=True,
@ -81,7 +81,7 @@ async def test_vacuum_button_press(hass: HomeAssistant) -> None:
async def setup_component(hass: HomeAssistant, entity_name: str) -> str: async def setup_component(hass: HomeAssistant, entity_name: str) -> str:
"""Set up vacuum component.""" """Set up vacuum component."""
entity_id = f"{DOMAIN}.{entity_name}" entity_id = f"{BUTTON_DOMAIN}.{entity_name}"
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=XIAOMI_DOMAIN, domain=XIAOMI_DOMAIN,

View File

@ -12,7 +12,7 @@ import pytest
from homeassistant.components.select import ( from homeassistant.components.select import (
ATTR_OPTION, ATTR_OPTION,
ATTR_OPTIONS, ATTR_OPTIONS,
DOMAIN, DOMAIN as SELECT_DOMAIN,
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION,
) )
from homeassistant.components.xiaomi_miio import UPDATE_INTERVAL from homeassistant.components.xiaomi_miio import UPDATE_INTERVAL
@ -143,7 +143,7 @@ async def test_select_coordinator_update(hass: HomeAssistant, setup_test) -> Non
async def setup_component(hass: HomeAssistant, entity_name: str) -> str: async def setup_component(hass: HomeAssistant, entity_name: str) -> str:
"""Set up component.""" """Set up component."""
entity_id = f"{DOMAIN}.{entity_name}" entity_id = f"{SELECT_DOMAIN}.{entity_name}"
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=XIAOMI_DOMAIN, domain=XIAOMI_DOMAIN,

View File

@ -12,7 +12,7 @@ from homeassistant.components.vacuum import (
ATTR_BATTERY_ICON, ATTR_BATTERY_ICON,
ATTR_FAN_SPEED, ATTR_FAN_SPEED,
ATTR_FAN_SPEED_LIST, ATTR_FAN_SPEED_LIST,
DOMAIN, DOMAIN as VACUUM_DOMAIN,
SERVICE_CLEAN_SPOT, SERVICE_CLEAN_SPOT,
SERVICE_LOCATE, SERVICE_LOCATE,
SERVICE_PAUSE, SERVICE_PAUSE,
@ -283,7 +283,7 @@ async def test_xiaomi_vacuum_services(
# Call services # Call services
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_START, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls( mock_mirobo_is_got_error.assert_has_calls(
[mock.call.resume_or_start()], any_order=True [mock.call.resume_or_start()], any_order=True
@ -292,42 +292,42 @@ async def test_xiaomi_vacuum_services(
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_PAUSE, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_PAUSE, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls([mock.call.pause()], any_order=True) mock_mirobo_is_got_error.assert_has_calls([mock.call.pause()], any_order=True)
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True) mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_STOP, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_STOP, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls([mock.call.stop()], any_order=True) mock_mirobo_is_got_error.assert_has_calls([mock.call.stop()], any_order=True)
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True) mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_RETURN_TO_BASE, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_RETURN_TO_BASE, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls([mock.call.home()], any_order=True) mock_mirobo_is_got_error.assert_has_calls([mock.call.home()], any_order=True)
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True) mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_LOCATE, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_LOCATE, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls([mock.call.find()], any_order=True) mock_mirobo_is_got_error.assert_has_calls([mock.call.find()], any_order=True)
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True) mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLEAN_SPOT, {"entity_id": entity_id}, blocking=True VACUUM_DOMAIN, SERVICE_CLEAN_SPOT, {"entity_id": entity_id}, blocking=True
) )
mock_mirobo_is_got_error.assert_has_calls([mock.call.spot()], any_order=True) mock_mirobo_is_got_error.assert_has_calls([mock.call.spot()], any_order=True)
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True) mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, VACUUM_DOMAIN,
SERVICE_SEND_COMMAND, SERVICE_SEND_COMMAND,
{"entity_id": entity_id, "command": "raw"}, {"entity_id": entity_id, "command": "raw"},
blocking=True, blocking=True,
@ -339,7 +339,7 @@ async def test_xiaomi_vacuum_services(
mock_mirobo_is_got_error.reset_mock() mock_mirobo_is_got_error.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, VACUUM_DOMAIN,
SERVICE_SEND_COMMAND, SERVICE_SEND_COMMAND,
{"entity_id": entity_id, "command": "raw", "params": {"k1": 2}}, {"entity_id": entity_id, "command": "raw", "params": {"k1": 2}},
blocking=True, blocking=True,
@ -498,7 +498,7 @@ async def test_xiaomi_vacuum_fanspeeds(
# Set speed service: # Set speed service:
await hass.services.async_call( await hass.services.async_call(
DOMAIN, VACUUM_DOMAIN,
SERVICE_SET_FAN_SPEED, SERVICE_SET_FAN_SPEED,
{"entity_id": entity_id, "fan_speed": 60}, {"entity_id": entity_id, "fan_speed": 60},
blocking=True, blocking=True,
@ -512,7 +512,7 @@ async def test_xiaomi_vacuum_fanspeeds(
fan_speed_dict = mock_mirobo_fanspeeds.fan_speed_presets() fan_speed_dict = mock_mirobo_fanspeeds.fan_speed_presets()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, VACUUM_DOMAIN,
SERVICE_SET_FAN_SPEED, SERVICE_SET_FAN_SPEED,
{"entity_id": entity_id, "fan_speed": "Medium"}, {"entity_id": entity_id, "fan_speed": "Medium"},
blocking=True, blocking=True,
@ -525,7 +525,7 @@ async def test_xiaomi_vacuum_fanspeeds(
assert "ERROR" not in caplog.text assert "ERROR" not in caplog.text
await hass.services.async_call( await hass.services.async_call(
DOMAIN, VACUUM_DOMAIN,
SERVICE_SET_FAN_SPEED, SERVICE_SET_FAN_SPEED,
{"entity_id": entity_id, "fan_speed": "invent"}, {"entity_id": entity_id, "fan_speed": "invent"},
blocking=True, blocking=True,
@ -535,7 +535,7 @@ async def test_xiaomi_vacuum_fanspeeds(
async def setup_component(hass: HomeAssistant, entity_name: str) -> str: async def setup_component(hass: HomeAssistant, entity_name: str) -> str:
"""Set up vacuum component.""" """Set up vacuum component."""
entity_id = f"{DOMAIN}.{entity_name}" entity_id = f"{VACUUM_DOMAIN}.{entity_name}"
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=XIAOMI_DOMAIN, domain=XIAOMI_DOMAIN,

View File

@ -9,7 +9,11 @@ from zigpy.profiles import zha
from zigpy.zcl.clusters import general from zigpy.zcl.clusters import general
import zigpy.zcl.foundation as zcl_f import zigpy.zcl.foundation as zcl_f
from homeassistant.components.button import DOMAIN, SERVICE_PRESS, ButtonDeviceClass from homeassistant.components.button import (
DOMAIN as BUTTON_DOMAIN,
SERVICE_PRESS,
ButtonDeviceClass,
)
from homeassistant.components.zha.helpers import ( from homeassistant.components.zha.helpers import (
ZHADeviceProxy, ZHADeviceProxy,
ZHAGatewayProxy, ZHAGatewayProxy,
@ -97,7 +101,7 @@ async def test_button(
return_value=[0x00, zcl_f.Status.SUCCESS], return_value=[0x00, zcl_f.Status.SUCCESS],
): ):
await hass.services.async_call( await hass.services.async_call(
DOMAIN, BUTTON_DOMAIN,
SERVICE_PRESS, SERVICE_PRESS,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,

View File

@ -15,7 +15,7 @@ from homeassistant.components.cover import (
ATTR_CURRENT_TILT_POSITION, ATTR_CURRENT_TILT_POSITION,
ATTR_POSITION, ATTR_POSITION,
ATTR_TILT_POSITION, ATTR_TILT_POSITION,
DOMAIN, DOMAIN as COVER_DOMAIN,
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
SERVICE_CLOSE_COVER_TILT, SERVICE_CLOSE_COVER_TILT,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
@ -68,7 +68,7 @@ async def test_window_cover(
# Test setting position # Test setting position
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 50}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 50},
blocking=True, blocking=True,
@ -89,7 +89,7 @@ async def test_window_cover(
# Test setting position # Test setting position
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_POSITION, SERVICE_SET_COVER_POSITION,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 0}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY, ATTR_POSITION: 0},
blocking=True, blocking=True,
@ -110,7 +110,7 @@ async def test_window_cover(
# Test opening # Test opening
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
blocking=True, blocking=True,
@ -131,7 +131,7 @@ async def test_window_cover(
# Test stop after opening # Test stop after opening
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_STOP_COVER, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
blocking=True, blocking=True,
@ -174,7 +174,7 @@ async def test_window_cover(
# Test closing # Test closing
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
blocking=True, blocking=True,
@ -194,7 +194,7 @@ async def test_window_cover(
# Test stop after closing # Test stop after closing
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_STOP_COVER, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: WINDOW_COVER_ENTITY}, {ATTR_ENTITY_ID: WINDOW_COVER_ENTITY},
blocking=True, blocking=True,
@ -249,7 +249,7 @@ async def test_fibaro_fgr222_shutter_cover(
# Test opening tilts # Test opening tilts
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER_TILT, SERVICE_OPEN_COVER_TILT,
{ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -271,7 +271,7 @@ async def test_fibaro_fgr222_shutter_cover(
# Test closing tilts # Test closing tilts
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER_TILT, SERVICE_CLOSE_COVER_TILT,
{ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -293,7 +293,7 @@ async def test_fibaro_fgr222_shutter_cover(
# Test setting tilt position # Test setting tilt position
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_TILT_POSITION, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY, ATTR_TILT_POSITION: 12}, {ATTR_ENTITY_ID: FIBARO_FGR_222_SHUTTER_COVER_ENTITY, ATTR_TILT_POSITION: 12},
blocking=True, blocking=True,
@ -350,7 +350,7 @@ async def test_fibaro_fgr223_shutter_cover(
# Test opening tilts # Test opening tilts
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER_TILT, SERVICE_OPEN_COVER_TILT,
{ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -370,7 +370,7 @@ async def test_fibaro_fgr223_shutter_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
# Test closing tilts # Test closing tilts
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER_TILT, SERVICE_CLOSE_COVER_TILT,
{ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -390,7 +390,7 @@ async def test_fibaro_fgr223_shutter_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
# Test setting tilt position # Test setting tilt position
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_TILT_POSITION, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY, ATTR_TILT_POSITION: 12}, {ATTR_ENTITY_ID: FIBARO_FGR_223_SHUTTER_COVER_ENTITY, ATTR_TILT_POSITION: 12},
blocking=True, blocking=True,
@ -446,7 +446,7 @@ async def test_aeotec_nano_shutter_cover(
# Test opening # Test opening
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -467,7 +467,7 @@ async def test_aeotec_nano_shutter_cover(
# Test stop after opening # Test stop after opening
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_STOP_COVER, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -511,7 +511,7 @@ async def test_aeotec_nano_shutter_cover(
# Test closing # Test closing
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -531,7 +531,7 @@ async def test_aeotec_nano_shutter_cover(
# Test stop after closing # Test stop after closing
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_STOP_COVER, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY}, {ATTR_ENTITY_ID: AEOTEC_SHUTTER_COVER_ENTITY},
blocking=True, blocking=True,
@ -583,7 +583,10 @@ async def test_motor_barrier_cover(
# Test open # Test open
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: GDC_COVER_ENTITY}, blocking=True COVER_DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: GDC_COVER_ENTITY},
blocking=True,
) )
assert len(client.async_send_command.call_args_list) == 1 assert len(client.async_send_command.call_args_list) == 1
@ -605,7 +608,10 @@ async def test_motor_barrier_cover(
# Test close # Test close
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: GDC_COVER_ENTITY}, blocking=True COVER_DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: GDC_COVER_ENTITY},
blocking=True,
) )
assert len(client.async_send_command.call_args_list) == 1 assert len(client.async_send_command.call_args_list) == 1
@ -846,7 +852,7 @@ async def test_iblinds_v3_cover(
assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0 assert state.attributes[ATTR_CURRENT_TILT_POSITION] == 0
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER_TILT, SERVICE_CLOSE_COVER_TILT,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
@ -867,7 +873,7 @@ async def test_iblinds_v3_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER_TILT, SERVICE_OPEN_COVER_TILT,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
@ -888,7 +894,7 @@ async def test_iblinds_v3_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_SET_COVER_TILT_POSITION, SERVICE_SET_COVER_TILT_POSITION,
{ATTR_ENTITY_ID: entity_id, ATTR_TILT_POSITION: 12}, {ATTR_ENTITY_ID: entity_id, ATTR_TILT_POSITION: 12},
blocking=True, blocking=True,
@ -909,7 +915,7 @@ async def test_iblinds_v3_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_STOP_COVER_TILT, SERVICE_STOP_COVER_TILT,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
@ -950,7 +956,7 @@ async def test_nice_ibt4zwave_cover(
assert state.attributes[ATTR_DEVICE_CLASS] == CoverDeviceClass.GATE assert state.attributes[ATTR_DEVICE_CLASS] == CoverDeviceClass.GATE
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
@ -970,7 +976,7 @@ async def test_nice_ibt4zwave_cover(
client.async_send_command.reset_mock() client.async_send_command.reset_mock()
await hass.services.async_call( await hass.services.async_call(
DOMAIN, COVER_DOMAIN,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,

View File

@ -6,7 +6,11 @@ from zwave_js_server.event import Event
from zwave_js_server.exceptions import FailedZWaveCommand from zwave_js_server.exceptions import FailedZWaveCommand
from zwave_js_server.model.node import Node from zwave_js_server.model.node import Node
from homeassistant.components.switch import DOMAIN, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.components.switch import (
DOMAIN as SWITCH_DOMAIN,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.components.zwave_js.helpers import ZwaveValueMatcher from homeassistant.components.zwave_js.helpers import ZwaveValueMatcher
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN, EntityCategory from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN, EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -95,7 +99,7 @@ async def test_barrier_signaling_switch(
# Test turning off # Test turning off
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {"entity_id": entity}, blocking=True SWITCH_DOMAIN, SERVICE_TURN_OFF, {"entity_id": entity}, blocking=True
) )
assert len(client.async_send_command.call_args_list) == 1 assert len(client.async_send_command.call_args_list) == 1
@ -120,7 +124,7 @@ async def test_barrier_signaling_switch(
# Test turning on # Test turning on
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {"entity_id": entity}, blocking=True SWITCH_DOMAIN, SERVICE_TURN_ON, {"entity_id": entity}, blocking=True
) )
# Note: the valueId's value is still 255 because we never # Note: the valueId's value is still 255 because we never
@ -250,7 +254,7 @@ async def test_config_parameter_switch(
# Test turning on # Test turning on
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {"entity_id": switch_entity_id}, blocking=True SWITCH_DOMAIN, SERVICE_TURN_ON, {"entity_id": switch_entity_id}, blocking=True
) )
assert len(client.async_send_command.call_args_list) == 1 assert len(client.async_send_command.call_args_list) == 1
@ -268,7 +272,7 @@ async def test_config_parameter_switch(
# Test turning off # Test turning off
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {"entity_id": switch_entity_id}, blocking=True SWITCH_DOMAIN, SERVICE_TURN_OFF, {"entity_id": switch_entity_id}, blocking=True
) )
assert len(client.async_send_command.call_args_list) == 1 assert len(client.async_send_command.call_args_list) == 1
@ -288,7 +292,10 @@ async def test_config_parameter_switch(
# Test turning off error raises proper exception # Test turning off error raises proper exception
with pytest.raises(HomeAssistantError) as err: with pytest.raises(HomeAssistantError) as err:
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {"entity_id": switch_entity_id}, blocking=True SWITCH_DOMAIN,
SERVICE_TURN_OFF,
{"entity_id": switch_entity_id},
blocking=True,
) )
assert str(err.value) == ( assert str(err.value) == (