mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Standardize DOMAIN usage in litterrobot tests (#136290)
* Standardize DOMAIN usage in litterrobot tests * Fix additional DOMAIN references in tests * Make platform domain usage more clear in tests
This commit is contained in:
parent
75bdcee3e4
commit
90bd783fff
@ -27,7 +27,6 @@ rules:
|
|||||||
status: todo
|
status: todo
|
||||||
comment: |
|
comment: |
|
||||||
Fix stale title and docstring
|
Fix stale title and docstring
|
||||||
Replace litterrobot.DOMAIN references to DOMAIN (after correctly importing)
|
|
||||||
Make sure every test ends in either ABORT or CREATE_ENTRY
|
Make sure every test ends in either ABORT or CREATE_ENTRY
|
||||||
so we also test that the flow is able to recover
|
so we also test that the flow is able to recover
|
||||||
config-flow: done
|
config-flow: done
|
||||||
|
@ -9,10 +9,9 @@ from pylitterbot import Account, FeederRobot, LitterRobot3, LitterRobot4, Robot
|
|||||||
from pylitterbot.exceptions import InvalidCommandException
|
from pylitterbot.exceptions import InvalidCommandException
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import litterrobot
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import CONFIG, FEEDER_ROBOT_DATA, ROBOT_4_DATA, ROBOT_DATA
|
from .common import CONFIG, DOMAIN, FEEDER_ROBOT_DATA, ROBOT_4_DATA, ROBOT_DATA
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -119,8 +118,8 @@ async def setup_integration(
|
|||||||
) -> MockConfigEntry:
|
) -> MockConfigEntry:
|
||||||
"""Load a Litter-Robot platform with the provided coordinator."""
|
"""Load a Litter-Robot platform with the provided coordinator."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=litterrobot.DOMAIN,
|
domain=DOMAIN,
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from unittest.mock import MagicMock
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_DEVICE_CLASS
|
from homeassistant.const import ATTR_DEVICE_CLASS
|
||||||
@ -21,7 +21,7 @@ async def test_binary_sensors(
|
|||||||
mock_account: MagicMock,
|
mock_account: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests binary sensors."""
|
"""Tests binary sensors."""
|
||||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account, BINARY_SENSOR_DOMAIN)
|
||||||
|
|
||||||
state = hass.states.get("binary_sensor.test_sleeping")
|
state = hass.states.get("binary_sensor.test_sleeping")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
@ -6,7 +6,6 @@ from pylitterbot import Account
|
|||||||
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import litterrobot
|
|
||||||
from homeassistant.const import CONF_PASSWORD
|
from homeassistant.const import CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -49,14 +48,14 @@ async def test_form(hass: HomeAssistant, mock_account) -> None:
|
|||||||
async def test_already_configured(hass: HomeAssistant) -> None:
|
async def test_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle already configured."""
|
"""Test we handle already configured."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain=litterrobot.DOMAIN,
|
domain=DOMAIN,
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_USER},
|
context={"source": config_entries.SOURCE_USER},
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
@ -119,8 +118,8 @@ async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
|||||||
async def test_step_reauth(hass: HomeAssistant, mock_account: Account) -> None:
|
async def test_step_reauth(hass: HomeAssistant, mock_account: Account) -> None:
|
||||||
"""Test the reauth flow."""
|
"""Test the reauth flow."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=litterrobot.DOMAIN,
|
domain=DOMAIN,
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -141,7 +140,7 @@ async def test_step_reauth(hass: HomeAssistant, mock_account: Account) -> None:
|
|||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_PASSWORD: CONFIG[litterrobot.DOMAIN][CONF_PASSWORD]},
|
user_input={CONF_PASSWORD: CONFIG[DOMAIN][CONF_PASSWORD]},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
@ -151,8 +150,8 @@ async def test_step_reauth(hass: HomeAssistant, mock_account: Account) -> None:
|
|||||||
async def test_step_reauth_failed(hass: HomeAssistant, mock_account: Account) -> None:
|
async def test_step_reauth_failed(hass: HomeAssistant, mock_account: Account) -> None:
|
||||||
"""Test the reauth flow fails and recovers."""
|
"""Test the reauth flow fails and recovers."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=litterrobot.DOMAIN,
|
domain=DOMAIN,
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -167,7 +166,7 @@ async def test_step_reauth_failed(hass: HomeAssistant, mock_account: Account) ->
|
|||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_PASSWORD: CONFIG[litterrobot.DOMAIN][CONF_PASSWORD]},
|
user_input={CONF_PASSWORD: CONFIG[DOMAIN][CONF_PASSWORD]},
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
@ -185,7 +184,7 @@ async def test_step_reauth_failed(hass: HomeAssistant, mock_account: Account) ->
|
|||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
user_input={CONF_PASSWORD: CONFIG[litterrobot.DOMAIN][CONF_PASSWORD]},
|
user_input={CONF_PASSWORD: CONFIG[DOMAIN][CONF_PASSWORD]},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
@ -5,7 +5,6 @@ from unittest.mock import MagicMock, patch
|
|||||||
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import litterrobot
|
|
||||||
from homeassistant.components.vacuum import (
|
from homeassistant.components.vacuum import (
|
||||||
DOMAIN as VACUUM_DOMAIN,
|
DOMAIN as VACUUM_DOMAIN,
|
||||||
SERVICE_START,
|
SERVICE_START,
|
||||||
@ -17,7 +16,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .common import CONFIG, VACUUM_ENTITY_ID
|
from .common import CONFIG, DOMAIN, VACUUM_ENTITY_ID
|
||||||
from .conftest import setup_integration
|
from .conftest import setup_integration
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
@ -57,8 +56,8 @@ async def test_entry_not_setup(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test being able to handle config entry not setup."""
|
"""Test being able to handle config entry not setup."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=litterrobot.DOMAIN,
|
domain=DOMAIN,
|
||||||
data=CONFIG[litterrobot.DOMAIN],
|
data=CONFIG[DOMAIN],
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ async def test_device_remove_devices(
|
|||||||
|
|
||||||
dead_device_entry = device_registry.async_get_or_create(
|
dead_device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
identifiers={(litterrobot.DOMAIN, "test-serial", "remove-serial")},
|
identifiers={(DOMAIN, "test-serial", "remove-serial")},
|
||||||
)
|
)
|
||||||
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
response = await client.remove_device(dead_device_entry.id, config_entry.entry_id)
|
||||||
assert response["success"]
|
assert response["success"]
|
||||||
|
@ -8,7 +8,7 @@ import pytest
|
|||||||
from homeassistant.components.select import (
|
from homeassistant.components.select import (
|
||||||
ATTR_OPTION,
|
ATTR_OPTION,
|
||||||
ATTR_OPTIONS,
|
ATTR_OPTIONS,
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, EntityCategory
|
from homeassistant.const import ATTR_ENTITY_ID, EntityCategory
|
||||||
@ -26,7 +26,7 @@ async def test_wait_time_select(
|
|||||||
hass: HomeAssistant, mock_account, entity_registry: er.EntityRegistry
|
hass: HomeAssistant, mock_account, entity_registry: er.EntityRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests the wait time select entity."""
|
"""Tests the wait time select entity."""
|
||||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account, SELECT_DOMAIN)
|
||||||
|
|
||||||
select = hass.states.get(SELECT_ENTITY_ID)
|
select = hass.states.get(SELECT_ENTITY_ID)
|
||||||
assert select
|
assert select
|
||||||
@ -41,7 +41,7 @@ async def test_wait_time_select(
|
|||||||
data[ATTR_OPTION] = wait_time
|
data[ATTR_OPTION] = wait_time
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
data,
|
data,
|
||||||
blocking=True,
|
blocking=True,
|
||||||
@ -52,7 +52,7 @@ async def test_wait_time_select(
|
|||||||
|
|
||||||
async def test_invalid_wait_time_select(hass: HomeAssistant, mock_account) -> None:
|
async def test_invalid_wait_time_select(hass: HomeAssistant, mock_account) -> None:
|
||||||
"""Tests the wait time select entity with invalid value."""
|
"""Tests the wait time select entity with invalid value."""
|
||||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account, SELECT_DOMAIN)
|
||||||
|
|
||||||
select = hass.states.get(SELECT_ENTITY_ID)
|
select = hass.states.get(SELECT_ENTITY_ID)
|
||||||
assert select
|
assert select
|
||||||
@ -61,7 +61,7 @@ async def test_invalid_wait_time_select(hass: HomeAssistant, mock_account) -> No
|
|||||||
|
|
||||||
with pytest.raises(ServiceValidationError):
|
with pytest.raises(ServiceValidationError):
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
data,
|
data,
|
||||||
blocking=True,
|
blocking=True,
|
||||||
@ -75,7 +75,7 @@ async def test_panel_brightness_select(
|
|||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests the wait time select entity."""
|
"""Tests the wait time select entity."""
|
||||||
await setup_integration(hass, mock_account_with_litterrobot_4, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account_with_litterrobot_4, SELECT_DOMAIN)
|
||||||
|
|
||||||
select = hass.states.get(PANEL_BRIGHTNESS_ENTITY_ID)
|
select = hass.states.get(PANEL_BRIGHTNESS_ENTITY_ID)
|
||||||
assert select
|
assert select
|
||||||
@ -94,7 +94,7 @@ async def test_panel_brightness_select(
|
|||||||
data[ATTR_OPTION] = option
|
data[ATTR_OPTION] = option
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN,
|
SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
data,
|
data,
|
||||||
blocking=True,
|
blocking=True,
|
||||||
|
@ -8,10 +8,9 @@ from unittest.mock import MagicMock
|
|||||||
from pylitterbot import Robot
|
from pylitterbot import Robot
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.litterrobot import DOMAIN
|
|
||||||
from homeassistant.components.litterrobot.vacuum import SERVICE_SET_SLEEP_MODE
|
from homeassistant.components.litterrobot.vacuum import SERVICE_SET_SLEEP_MODE
|
||||||
from homeassistant.components.vacuum import (
|
from homeassistant.components.vacuum import (
|
||||||
DOMAIN as PLATFORM_DOMAIN,
|
DOMAIN as VACUUM_DOMAIN,
|
||||||
SERVICE_START,
|
SERVICE_START,
|
||||||
SERVICE_STOP,
|
SERVICE_STOP,
|
||||||
VacuumActivity,
|
VacuumActivity,
|
||||||
@ -20,7 +19,7 @@ from homeassistant.const import ATTR_ENTITY_ID
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||||
|
|
||||||
from .common import VACUUM_ENTITY_ID
|
from .common import DOMAIN, VACUUM_ENTITY_ID
|
||||||
from .conftest import setup_integration
|
from .conftest import setup_integration
|
||||||
|
|
||||||
VACUUM_UNIQUE_ID = "LR3C012345-litter_box"
|
VACUUM_UNIQUE_ID = "LR3C012345-litter_box"
|
||||||
@ -36,15 +35,15 @@ async def test_vacuum(
|
|||||||
"""Tests the vacuum entity was set up."""
|
"""Tests the vacuum entity was set up."""
|
||||||
|
|
||||||
entity_registry.async_get_or_create(
|
entity_registry.async_get_or_create(
|
||||||
PLATFORM_DOMAIN,
|
VACUUM_DOMAIN,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
VACUUM_UNIQUE_ID,
|
VACUUM_UNIQUE_ID,
|
||||||
suggested_object_id=VACUUM_ENTITY_ID.replace(PLATFORM_DOMAIN, ""),
|
suggested_object_id=VACUUM_ENTITY_ID.replace(VACUUM_DOMAIN, ""),
|
||||||
)
|
)
|
||||||
ent_reg_entry = entity_registry.async_get(VACUUM_ENTITY_ID)
|
ent_reg_entry = entity_registry.async_get(VACUUM_ENTITY_ID)
|
||||||
assert ent_reg_entry.unique_id == VACUUM_UNIQUE_ID
|
assert ent_reg_entry.unique_id == VACUUM_UNIQUE_ID
|
||||||
|
|
||||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account, VACUUM_DOMAIN)
|
||||||
assert len(entity_registry.entities) == 1
|
assert len(entity_registry.entities) == 1
|
||||||
assert hass.services.has_service(DOMAIN, SERVICE_SET_SLEEP_MODE)
|
assert hass.services.has_service(DOMAIN, SERVICE_SET_SLEEP_MODE)
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ async def test_no_robots(
|
|||||||
mock_account_with_no_robots: MagicMock,
|
mock_account_with_no_robots: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests the vacuum entity was set up."""
|
"""Tests the vacuum entity was set up."""
|
||||||
entry = await setup_integration(hass, mock_account_with_no_robots, PLATFORM_DOMAIN)
|
entry = await setup_integration(hass, mock_account_with_no_robots, VACUUM_DOMAIN)
|
||||||
|
|
||||||
assert not hass.services.has_service(DOMAIN, SERVICE_SET_SLEEP_MODE)
|
assert not hass.services.has_service(DOMAIN, SERVICE_SET_SLEEP_MODE)
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ async def test_vacuum_with_error(
|
|||||||
hass: HomeAssistant, mock_account_with_error: MagicMock
|
hass: HomeAssistant, mock_account_with_error: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Tests a vacuum entity with an error."""
|
"""Tests a vacuum entity with an error."""
|
||||||
await setup_integration(hass, mock_account_with_error, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account_with_error, VACUUM_DOMAIN)
|
||||||
|
|
||||||
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
||||||
assert vacuum
|
assert vacuum
|
||||||
@ -101,7 +100,7 @@ async def test_activities(
|
|||||||
expected_state: str,
|
expected_state: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sending commands to the switch."""
|
"""Test sending commands to the switch."""
|
||||||
await setup_integration(hass, mock_account_with_litterrobot_4, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account_with_litterrobot_4, VACUUM_DOMAIN)
|
||||||
robot: Robot = mock_account_with_litterrobot_4.robots[0]
|
robot: Robot = mock_account_with_litterrobot_4.robots[0]
|
||||||
robot._update_data(robot_data, partial=True)
|
robot._update_data(robot_data, partial=True)
|
||||||
|
|
||||||
@ -134,7 +133,7 @@ async def test_commands(
|
|||||||
issue_registry: ir.IssueRegistry,
|
issue_registry: ir.IssueRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sending commands to the vacuum."""
|
"""Test sending commands to the vacuum."""
|
||||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
await setup_integration(hass, mock_account, VACUUM_DOMAIN)
|
||||||
|
|
||||||
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
vacuum = hass.states.get(VACUUM_ENTITY_ID)
|
||||||
assert vacuum
|
assert vacuum
|
||||||
@ -145,7 +144,7 @@ async def test_commands(
|
|||||||
issues = extra.get("issues", set())
|
issues = extra.get("issues", set())
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COMPONENT_SERVICE_DOMAIN.get(service, PLATFORM_DOMAIN),
|
COMPONENT_SERVICE_DOMAIN.get(service, VACUUM_DOMAIN),
|
||||||
service,
|
service,
|
||||||
data,
|
data,
|
||||||
blocking=True,
|
blocking=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user