mirror of
https://github.com/home-assistant/core.git
synced 2026-11-05 13:11:29 -04:00
Add Ecovacs button entities (#109189)
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
# serializer version: 1
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_relocate:entity-registry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.ozmo_950_relocate',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Relocate',
|
||||
'platform': 'ecovacs',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'relocate',
|
||||
'unique_id': 'E1234567890000000001_relocate',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_relocate:state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ozmo 950 Relocate',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.ozmo_950_relocate',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2024-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_brush_lifespan:entity-registry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.ozmo_950_reset_brush_lifespan',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Reset brush lifespan',
|
||||
'platform': 'ecovacs',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'reset_lifespan_brush',
|
||||
'unique_id': 'E1234567890000000001_reset_lifespan_brush',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_brush_lifespan:state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ozmo 950 Reset brush lifespan',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.ozmo_950_reset_brush_lifespan',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2024-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_filter_lifespan:entity-registry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.ozmo_950_reset_filter_lifespan',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Reset filter lifespan',
|
||||
'platform': 'ecovacs',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'reset_lifespan_filter',
|
||||
'unique_id': 'E1234567890000000001_reset_lifespan_filter',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_filter_lifespan:state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ozmo 950 Reset filter lifespan',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.ozmo_950_reset_filter_lifespan',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2024-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_side_brush_lifespan:entity-registry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'button',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'button.ozmo_950_reset_side_brush_lifespan',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Reset side brush lifespan',
|
||||
'platform': 'ecovacs',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'reset_lifespan_side_brush',
|
||||
'unique_id': 'E1234567890000000001_reset_lifespan_side_brush',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_buttons[yna5x1][button.ozmo_950_reset_side_brush_lifespan:state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ozmo 950 Reset side brush lifespan',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'button.ozmo_950_reset_side_brush_lifespan',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2024-01-01T00:00:00+00:00',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,110 @@
|
||||
"""Tests for Ecovacs sensors."""
|
||||
|
||||
from deebot_client.command import Command
|
||||
from deebot_client.commands.json import ResetLifeSpan, SetRelocationState
|
||||
from deebot_client.events import LifeSpan
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.button.const import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.components.ecovacs.const import DOMAIN
|
||||
from homeassistant.components.ecovacs.controller import EcovacsController
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.usefixtures("init_integration"),
|
||||
pytest.mark.freeze_time("2024-01-01 00:00:00"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platforms() -> Platform | list[Platform]:
|
||||
"""Platforms, which should be loaded during the test."""
|
||||
return Platform.BUTTON
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.parametrize(
|
||||
("device_fixture", "entities"),
|
||||
[
|
||||
(
|
||||
"yna5x1",
|
||||
[
|
||||
("button.ozmo_950_relocate", SetRelocationState()),
|
||||
("button.ozmo_950_reset_brush_lifespan", ResetLifeSpan(LifeSpan.BRUSH)),
|
||||
(
|
||||
"button.ozmo_950_reset_filter_lifespan",
|
||||
ResetLifeSpan(LifeSpan.FILTER),
|
||||
),
|
||||
(
|
||||
"button.ozmo_950_reset_side_brush_lifespan",
|
||||
ResetLifeSpan(LifeSpan.SIDE_BRUSH),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
ids=["yna5x1"],
|
||||
)
|
||||
async def test_buttons(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
controller: EcovacsController,
|
||||
entities: list[tuple[str, Command]],
|
||||
) -> None:
|
||||
"""Test that sensor entity snapshots match."""
|
||||
assert sorted(hass.states.async_entity_ids()) == [e[0] for e in entities]
|
||||
device = controller.devices[0]
|
||||
for entity_id, command in entities:
|
||||
assert (state := hass.states.get(entity_id)), f"State of {entity_id} is missing"
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
device._execute_command.reset_mock()
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
device._execute_command.assert_called_with(command)
|
||||
|
||||
assert (state := hass.states.get(entity_id)), f"State of {entity_id} is missing"
|
||||
assert state.state == "2024-01-01T00:00:00+00:00"
|
||||
assert snapshot(name=f"{entity_id}:state") == state
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot(name=f"{entity_id}:entity-registry") == entity_entry
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert device_entry.identifiers == {(DOMAIN, device.device_info.did)}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_fixture", "entity_ids"),
|
||||
[
|
||||
(
|
||||
"yna5x1",
|
||||
[
|
||||
"button.ozmo_950_reset_brush_lifespan",
|
||||
"button.ozmo_950_reset_filter_lifespan",
|
||||
"button.ozmo_950_reset_side_brush_lifespan",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_disabled_by_default_buttons(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, entity_ids: list[str]
|
||||
) -> None:
|
||||
"""Test the disabled by default buttons."""
|
||||
for entity_id in entity_ids:
|
||||
assert not hass.states.get(entity_id)
|
||||
|
||||
assert (
|
||||
entry := entity_registry.async_get(entity_id)
|
||||
), f"Entity registry entry for {entity_id} is missing"
|
||||
assert entry.disabled
|
||||
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
|
||||
@@ -116,7 +116,7 @@ async def test_devices_in_dr(
|
||||
@pytest.mark.parametrize(
|
||||
("device_fixture", "entities"),
|
||||
[
|
||||
("yna5x1", 17),
|
||||
("yna5x1", 21),
|
||||
],
|
||||
)
|
||||
async def test_all_entities_loaded(
|
||||
|
||||
Reference in New Issue
Block a user