mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +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
|
||||
comment: |
|
||||
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
|
||||
so we also test that the flow is able to recover
|
||||
config-flow: done
|
||||
|
@ -9,10 +9,9 @@ from pylitterbot import Account, FeederRobot, LitterRobot3, LitterRobot4, Robot
|
||||
from pylitterbot.exceptions import InvalidCommandException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import litterrobot
|
||||
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
|
||||
|
||||
@ -119,8 +118,8 @@ async def setup_integration(
|
||||
) -> MockConfigEntry:
|
||||
"""Load a Litter-Robot platform with the provided coordinator."""
|
||||
entry = MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
domain=DOMAIN,
|
||||
data=CONFIG[DOMAIN],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
|
@ -5,7 +5,7 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN as PLATFORM_DOMAIN,
|
||||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorDeviceClass,
|
||||
)
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS
|
||||
@ -21,7 +21,7 @@ async def test_binary_sensors(
|
||||
mock_account: MagicMock,
|
||||
) -> None:
|
||||
"""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")
|
||||
assert state.state == "off"
|
||||
|
@ -6,7 +6,6 @@ from pylitterbot import Account
|
||||
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import litterrobot
|
||||
from homeassistant.const import CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
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:
|
||||
"""Test we handle already configured."""
|
||||
MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
domain=DOMAIN,
|
||||
data=CONFIG[DOMAIN],
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
data=CONFIG[DOMAIN],
|
||||
)
|
||||
|
||||
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:
|
||||
"""Test the reauth flow."""
|
||||
entry = MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
domain=DOMAIN,
|
||||
data=CONFIG[DOMAIN],
|
||||
)
|
||||
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["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["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:
|
||||
"""Test the reauth flow fails and recovers."""
|
||||
entry = MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
domain=DOMAIN,
|
||||
data=CONFIG[DOMAIN],
|
||||
)
|
||||
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["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
|
||||
@ -185,7 +184,7 @@ async def test_step_reauth_failed(hass: HomeAssistant, mock_account: Account) ->
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
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["reason"] == "reauth_successful"
|
||||
|
@ -5,7 +5,6 @@ from unittest.mock import MagicMock, patch
|
||||
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import litterrobot
|
||||
from homeassistant.components.vacuum import (
|
||||
DOMAIN as VACUUM_DOMAIN,
|
||||
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.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 tests.common import MockConfigEntry
|
||||
@ -57,8 +56,8 @@ async def test_entry_not_setup(
|
||||
) -> None:
|
||||
"""Test being able to handle config entry not setup."""
|
||||
entry = MockConfigEntry(
|
||||
domain=litterrobot.DOMAIN,
|
||||
data=CONFIG[litterrobot.DOMAIN],
|
||||
domain=DOMAIN,
|
||||
data=CONFIG[DOMAIN],
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
@ -91,7 +90,7 @@ async def test_device_remove_devices(
|
||||
|
||||
dead_device_entry = device_registry.async_get_or_create(
|
||||
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)
|
||||
assert response["success"]
|
||||
|
@ -8,7 +8,7 @@ import pytest
|
||||
from homeassistant.components.select import (
|
||||
ATTR_OPTION,
|
||||
ATTR_OPTIONS,
|
||||
DOMAIN as PLATFORM_DOMAIN,
|
||||
DOMAIN as SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
)
|
||||
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
|
||||
) -> None:
|
||||
"""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)
|
||||
assert select
|
||||
@ -41,7 +41,7 @@ async def test_wait_time_select(
|
||||
data[ATTR_OPTION] = wait_time
|
||||
|
||||
await hass.services.async_call(
|
||||
PLATFORM_DOMAIN,
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
data,
|
||||
blocking=True,
|
||||
@ -52,7 +52,7 @@ async def test_wait_time_select(
|
||||
|
||||
async def test_invalid_wait_time_select(hass: HomeAssistant, mock_account) -> None:
|
||||
"""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)
|
||||
assert select
|
||||
@ -61,7 +61,7 @@ async def test_invalid_wait_time_select(hass: HomeAssistant, mock_account) -> No
|
||||
|
||||
with pytest.raises(ServiceValidationError):
|
||||
await hass.services.async_call(
|
||||
PLATFORM_DOMAIN,
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
data,
|
||||
blocking=True,
|
||||
@ -75,7 +75,7 @@ async def test_panel_brightness_select(
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""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)
|
||||
assert select
|
||||
@ -94,7 +94,7 @@ async def test_panel_brightness_select(
|
||||
data[ATTR_OPTION] = option
|
||||
|
||||
await hass.services.async_call(
|
||||
PLATFORM_DOMAIN,
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
data,
|
||||
blocking=True,
|
||||
|
@ -8,10 +8,9 @@ from unittest.mock import MagicMock
|
||||
from pylitterbot import Robot
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.litterrobot import DOMAIN
|
||||
from homeassistant.components.litterrobot.vacuum import SERVICE_SET_SLEEP_MODE
|
||||
from homeassistant.components.vacuum import (
|
||||
DOMAIN as PLATFORM_DOMAIN,
|
||||
DOMAIN as VACUUM_DOMAIN,
|
||||
SERVICE_START,
|
||||
SERVICE_STOP,
|
||||
VacuumActivity,
|
||||
@ -20,7 +19,7 @@ from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
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
|
||||
|
||||
VACUUM_UNIQUE_ID = "LR3C012345-litter_box"
|
||||
@ -36,15 +35,15 @@ async def test_vacuum(
|
||||
"""Tests the vacuum entity was set up."""
|
||||
|
||||
entity_registry.async_get_or_create(
|
||||
PLATFORM_DOMAIN,
|
||||
VACUUM_DOMAIN,
|
||||
DOMAIN,
|
||||
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)
|
||||
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 hass.services.has_service(DOMAIN, SERVICE_SET_SLEEP_MODE)
|
||||
|
||||
@ -62,7 +61,7 @@ async def test_no_robots(
|
||||
mock_account_with_no_robots: MagicMock,
|
||||
) -> None:
|
||||
"""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)
|
||||
|
||||
@ -76,7 +75,7 @@ async def test_vacuum_with_error(
|
||||
hass: HomeAssistant, mock_account_with_error: MagicMock
|
||||
) -> None:
|
||||
"""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)
|
||||
assert vacuum
|
||||
@ -101,7 +100,7 @@ async def test_activities(
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""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._update_data(robot_data, partial=True)
|
||||
|
||||
@ -134,7 +133,7 @@ async def test_commands(
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""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)
|
||||
assert vacuum
|
||||
@ -145,7 +144,7 @@ async def test_commands(
|
||||
issues = extra.get("issues", set())
|
||||
|
||||
await hass.services.async_call(
|
||||
COMPONENT_SERVICE_DOMAIN.get(service, PLATFORM_DOMAIN),
|
||||
COMPONENT_SERVICE_DOMAIN.get(service, VACUUM_DOMAIN),
|
||||
service,
|
||||
data,
|
||||
blocking=True,
|
||||
|
Loading…
x
Reference in New Issue
Block a user