mirror of
https://github.com/home-assistant/core.git
synced 2026-02-21 05:09:21 +00:00
Compare commits
2 Commits
matter_cle
...
govee_init
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2229bfbdf | ||
|
|
0996ad4d1d |
@@ -15,7 +15,7 @@ from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from .const import DISCOVERY_TIMEOUT
|
||||
from .const import DISCOVERY_TIMEOUT, DOMAIN
|
||||
from .coordinator import GoveeLocalApiCoordinator, GoveeLocalConfigEntry
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.LIGHT]
|
||||
@@ -52,7 +52,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoveeLocalConfigEntry) -
|
||||
_LOGGER.error("Start failed, errno: %d", ex.errno)
|
||||
return False
|
||||
_LOGGER.error("Port %s already in use", LISTENING_PORT)
|
||||
raise ConfigEntryNotReady from ex
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="port_in_use",
|
||||
translation_placeholders={"port": LISTENING_PORT},
|
||||
) from ex
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
@@ -61,7 +65,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoveeLocalConfigEntry) -
|
||||
while not coordinator.devices:
|
||||
await asyncio.sleep(delay=1)
|
||||
except TimeoutError as ex:
|
||||
raise ConfigEntryNotReady from ex
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN, translation_key="no_devices_found"
|
||||
) from ex
|
||||
|
||||
entry.runtime_data = coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
@@ -33,5 +33,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"no_devices_found": {
|
||||
"message": "[%key:common::config_flow::abort::no_devices_found%]"
|
||||
},
|
||||
"port_in_use": {
|
||||
"message": "Port {port} is already in use"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,14 +329,14 @@ class IDriveE2BackupAgent(BackupAgent):
|
||||
return self._backup_cache
|
||||
|
||||
backups = {}
|
||||
response = await cast(Any, self._client).list_objects_v2(Bucket=self._bucket)
|
||||
|
||||
# Filter for metadata files only
|
||||
metadata_files = [
|
||||
obj
|
||||
for obj in response.get("Contents", [])
|
||||
if obj["Key"].endswith(".metadata.json")
|
||||
]
|
||||
paginator = self._client.get_paginator("list_objects_v2")
|
||||
metadata_files: list[dict[str, Any]] = []
|
||||
async for page in paginator.paginate(Bucket=self._bucket):
|
||||
metadata_files.extend(
|
||||
obj
|
||||
for obj in page.get("Contents", [])
|
||||
if obj["Key"].endswith(".metadata.json")
|
||||
)
|
||||
|
||||
for metadata_file in metadata_files:
|
||||
try:
|
||||
|
||||
@@ -10,7 +10,6 @@ from chip.clusters import Objects as clusters
|
||||
from matter_server.client.models import device_types
|
||||
|
||||
from homeassistant.components.vacuum import (
|
||||
Segment,
|
||||
StateVacuumEntity,
|
||||
StateVacuumEntityDescription,
|
||||
VacuumActivity,
|
||||
@@ -71,7 +70,6 @@ class MatterVacuum(MatterEntity, StateVacuumEntity):
|
||||
"""Representation of a Matter Vacuum cleaner entity."""
|
||||
|
||||
_last_accepted_commands: list[int] | None = None
|
||||
_last_service_area_feature_map: int | None = None
|
||||
_supported_run_modes: (
|
||||
dict[int, clusters.RvcRunMode.Structs.ModeOptionStruct] | None
|
||||
) = None
|
||||
@@ -138,16 +136,6 @@ class MatterVacuum(MatterEntity, StateVacuumEntity):
|
||||
"No supported run mode found to start the vacuum cleaner."
|
||||
)
|
||||
|
||||
# Reset selected areas to an unconstrained selection to ensure start
|
||||
# performs a full clean and does not reuse a previous area-targeted
|
||||
# selection.
|
||||
if VacuumEntityFeature.CLEAN_AREA in self.supported_features:
|
||||
# Matter ServiceArea: an empty NewAreas list means unconstrained
|
||||
# operation (full clean).
|
||||
await self.send_device_command(
|
||||
clusters.ServiceArea.Commands.SelectAreas(newAreas=[])
|
||||
)
|
||||
|
||||
await self.send_device_command(
|
||||
clusters.RvcRunMode.Commands.ChangeToMode(newMode=mode.mode)
|
||||
)
|
||||
@@ -156,66 +144,6 @@ class MatterVacuum(MatterEntity, StateVacuumEntity):
|
||||
"""Pause the cleaning task."""
|
||||
await self.send_device_command(clusters.RvcOperationalState.Commands.Pause())
|
||||
|
||||
@property
|
||||
def _current_segments(self) -> list[Segment]:
|
||||
"""Return the current cleanable segments reported by the device."""
|
||||
supported_areas: list[clusters.ServiceArea.Structs.AreaStruct] = (
|
||||
self.get_matter_attribute_value(
|
||||
clusters.ServiceArea.Attributes.SupportedAreas
|
||||
)
|
||||
)
|
||||
|
||||
segments: list[Segment] = []
|
||||
for area in supported_areas:
|
||||
area_name = None
|
||||
if area.areaInfo and area.areaInfo.locationInfo:
|
||||
area_name = area.areaInfo.locationInfo.locationName
|
||||
|
||||
if area_name:
|
||||
segments.append(
|
||||
Segment(
|
||||
id=str(area.areaID),
|
||||
name=area_name,
|
||||
)
|
||||
)
|
||||
|
||||
return segments
|
||||
|
||||
async def async_get_segments(self) -> list[Segment]:
|
||||
"""Get the segments that can be cleaned.
|
||||
|
||||
Returns a list of segments containing their ids and names.
|
||||
"""
|
||||
return self._current_segments
|
||||
|
||||
async def async_clean_segments(self, segment_ids: list[str], **kwargs: Any) -> None:
|
||||
"""Clean the specified segments.
|
||||
|
||||
Args:
|
||||
segment_ids: List of segment IDs to clean.
|
||||
**kwargs: Additional arguments (unused).
|
||||
|
||||
"""
|
||||
# Convert string IDs to integers
|
||||
area_ids = [int(segment_id) for segment_id in segment_ids]
|
||||
|
||||
# Ensure a CLEANING run mode is available before changing device state
|
||||
mode = self._get_run_mode_by_tag(ModeTag.CLEANING)
|
||||
if mode is None:
|
||||
raise HomeAssistantError(
|
||||
"No supported run mode found to start the vacuum cleaner."
|
||||
)
|
||||
|
||||
# Send the SelectAreas command to the vacuum
|
||||
await self.send_device_command(
|
||||
clusters.ServiceArea.Commands.SelectAreas(newAreas=area_ids)
|
||||
)
|
||||
|
||||
# Start cleaning using ChangeToMode with CLEANING tag
|
||||
await self.send_device_command(
|
||||
clusters.RvcRunMode.Commands.ChangeToMode(newMode=mode.mode)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_from_device(self) -> None:
|
||||
"""Update from device."""
|
||||
@@ -248,34 +176,16 @@ class MatterVacuum(MatterEntity, StateVacuumEntity):
|
||||
state = VacuumActivity.CLEANING
|
||||
self._attr_activity = state
|
||||
|
||||
if (
|
||||
VacuumEntityFeature.CLEAN_AREA in self.supported_features
|
||||
and self.registry_entry is not None
|
||||
and (last_seen_segments := self.last_seen_segments) is not None
|
||||
and self._current_segments != last_seen_segments
|
||||
):
|
||||
self.async_create_segments_issue()
|
||||
|
||||
@callback
|
||||
def _calculate_features(self) -> None:
|
||||
"""Calculate features for HA Vacuum platform."""
|
||||
accepted_operational_commands: list[int] = self.get_matter_attribute_value(
|
||||
clusters.RvcOperationalState.Attributes.AcceptedCommandList
|
||||
)
|
||||
service_area_feature_map: int | None = self.get_matter_attribute_value(
|
||||
clusters.ServiceArea.Attributes.FeatureMap
|
||||
)
|
||||
|
||||
# In principle the feature set should not change, except for accepted
|
||||
# commands and service area feature map.
|
||||
if (
|
||||
self._last_accepted_commands == accepted_operational_commands
|
||||
and self._last_service_area_feature_map == service_area_feature_map
|
||||
):
|
||||
# in principle the feature set should not change, except for the accepted commands
|
||||
if self._last_accepted_commands == accepted_operational_commands:
|
||||
return
|
||||
|
||||
self._last_accepted_commands = accepted_operational_commands
|
||||
self._last_service_area_feature_map = service_area_feature_map
|
||||
supported_features: VacuumEntityFeature = VacuumEntityFeature(0)
|
||||
supported_features |= VacuumEntityFeature.START
|
||||
supported_features |= VacuumEntityFeature.STATE
|
||||
@@ -302,12 +212,6 @@ class MatterVacuum(MatterEntity, StateVacuumEntity):
|
||||
in accepted_operational_commands
|
||||
):
|
||||
supported_features |= VacuumEntityFeature.RETURN_HOME
|
||||
# Check if Map feature is enabled for clean area support
|
||||
if (
|
||||
service_area_feature_map is not None
|
||||
and service_area_feature_map & clusters.ServiceArea.Bitmaps.Feature.kMaps
|
||||
):
|
||||
supported_features |= VacuumEntityFeature.CLEAN_AREA
|
||||
|
||||
self._attr_supported_features = supported_features
|
||||
|
||||
@@ -324,10 +228,6 @@ DISCOVERY_SCHEMAS = [
|
||||
clusters.RvcRunMode.Attributes.CurrentMode,
|
||||
clusters.RvcOperationalState.Attributes.OperationalState,
|
||||
),
|
||||
optional_attributes=(
|
||||
clusters.ServiceArea.Attributes.FeatureMap,
|
||||
clusters.ServiceArea.Attributes.SupportedAreas,
|
||||
),
|
||||
device_type=(device_types.RoboticVacuumCleaner,),
|
||||
allow_none_value=True,
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import AsyncIterator, Generator
|
||||
import json
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -53,9 +53,11 @@ def mock_client(agent_backup: AgentBackup) -> Generator[AsyncMock]:
|
||||
client = create_client.return_value
|
||||
|
||||
tar_file, metadata_file = suggested_filenames(agent_backup)
|
||||
client.list_objects_v2.return_value = {
|
||||
"Contents": [{"Key": tar_file}, {"Key": metadata_file}]
|
||||
}
|
||||
# Mock the paginator for list_objects_v2
|
||||
client.get_paginator = MagicMock()
|
||||
client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
{"Contents": [{"Key": tar_file}, {"Key": metadata_file}]}
|
||||
]
|
||||
client.create_multipart_upload.return_value = {"UploadId": "upload_id"}
|
||||
client.upload_part.return_value = {"ETag": "etag"}
|
||||
client.list_buckets.return_value = {
|
||||
|
||||
@@ -179,7 +179,9 @@ async def test_agents_get_backup_does_not_throw_on_not_found(
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test agent get backup does not throw on a backup not found."""
|
||||
mock_client.list_objects_v2.return_value = {"Contents": []}
|
||||
mock_client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
{"Contents": []}
|
||||
]
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json_auto_id({"type": "backup/details", "backup_id": "random"})
|
||||
@@ -202,18 +204,20 @@ async def test_agents_list_backups_with_corrupted_metadata(
|
||||
agent = IDriveE2BackupAgent(hass, mock_config_entry)
|
||||
|
||||
# Set up mock responses for both valid and corrupted metadata files
|
||||
mock_client.list_objects_v2.return_value = {
|
||||
"Contents": [
|
||||
{
|
||||
"Key": "valid_backup.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
},
|
||||
{
|
||||
"Key": "corrupted_backup.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
},
|
||||
]
|
||||
}
|
||||
mock_client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
{
|
||||
"Contents": [
|
||||
{
|
||||
"Key": "valid_backup.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
},
|
||||
{
|
||||
"Key": "corrupted_backup.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
# Mock responses for get_object calls
|
||||
valid_metadata = json.dumps(agent_backup.as_dict())
|
||||
@@ -270,7 +274,9 @@ async def test_agents_delete_not_throwing_on_not_found(
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test agent delete backup does not throw on a backup not found."""
|
||||
mock_client.list_objects_v2.return_value = {"Contents": []}
|
||||
mock_client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
{"Contents": []}
|
||||
]
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
@@ -284,7 +290,7 @@ async def test_agents_delete_not_throwing_on_not_found(
|
||||
|
||||
assert response["success"]
|
||||
assert response["result"] == {"agent_errors": {}}
|
||||
assert mock_client.delete_object.call_count == 0
|
||||
assert mock_client.delete_objects.call_count == 0
|
||||
|
||||
|
||||
async def test_agents_upload(
|
||||
@@ -490,20 +496,27 @@ async def test_cache_expiration(
|
||||
metadata_content = json.dumps(agent_backup.as_dict())
|
||||
mock_body = AsyncMock()
|
||||
mock_body.read.return_value = metadata_content.encode()
|
||||
mock_client.list_objects_v2.return_value = {
|
||||
"Contents": [
|
||||
{"Key": "test.metadata.json", "LastModified": "2023-01-01T00:00:00+00:00"}
|
||||
]
|
||||
}
|
||||
mock_client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
{
|
||||
"Contents": [
|
||||
{
|
||||
"Key": "test.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
mock_client.get_object.return_value = {"Body": mock_body}
|
||||
|
||||
# First call should query IDrive e2
|
||||
await agent.async_list_backups()
|
||||
assert mock_client.list_objects_v2.call_count == 1
|
||||
assert mock_client.get_paginator.call_count == 1
|
||||
assert mock_client.get_object.call_count == 1
|
||||
|
||||
# Second call should use cache
|
||||
await agent.async_list_backups()
|
||||
assert mock_client.list_objects_v2.call_count == 1
|
||||
assert mock_client.get_paginator.call_count == 1
|
||||
assert mock_client.get_object.call_count == 1
|
||||
|
||||
# Set cache to expire
|
||||
@@ -511,7 +524,7 @@ async def test_cache_expiration(
|
||||
|
||||
# Third call should query IDrive e2 again
|
||||
await agent.async_list_backups()
|
||||
assert mock_client.list_objects_v2.call_count == 2
|
||||
assert mock_client.get_paginator.call_count == 2
|
||||
assert mock_client.get_object.call_count == 2
|
||||
|
||||
|
||||
@@ -526,3 +539,88 @@ async def test_listeners_get_cleaned_up(hass: HomeAssistant) -> None:
|
||||
remove_listener()
|
||||
|
||||
assert DATA_BACKUP_AGENT_LISTENERS not in hass.data
|
||||
|
||||
|
||||
async def test_list_backups_with_pagination(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test listing backups when paginating through multiple pages."""
|
||||
# Create agent
|
||||
agent = IDriveE2BackupAgent(hass, mock_config_entry)
|
||||
|
||||
# Create two different backups
|
||||
backup1 = AgentBackup(
|
||||
backup_id="backup1",
|
||||
date="2023-01-01T00:00:00+00:00",
|
||||
addons=[],
|
||||
database_included=False,
|
||||
extra_metadata={},
|
||||
folders=[],
|
||||
homeassistant_included=False,
|
||||
homeassistant_version=None,
|
||||
name="Backup 1",
|
||||
protected=False,
|
||||
size=0,
|
||||
)
|
||||
backup2 = AgentBackup(
|
||||
backup_id="backup2",
|
||||
date="2023-01-02T00:00:00+00:00",
|
||||
addons=[],
|
||||
database_included=False,
|
||||
extra_metadata={},
|
||||
folders=[],
|
||||
homeassistant_included=False,
|
||||
homeassistant_version=None,
|
||||
name="Backup 2",
|
||||
protected=False,
|
||||
size=0,
|
||||
)
|
||||
|
||||
# Setup two pages of results
|
||||
page1 = {
|
||||
"Contents": [
|
||||
{
|
||||
"Key": "backup1.metadata.json",
|
||||
"LastModified": "2023-01-01T00:00:00+00:00",
|
||||
},
|
||||
{"Key": "backup1.tar", "LastModified": "2023-01-01T00:00:00+00:00"},
|
||||
]
|
||||
}
|
||||
page2 = {
|
||||
"Contents": [
|
||||
{
|
||||
"Key": "backup2.metadata.json",
|
||||
"LastModified": "2023-01-02T00:00:00+00:00",
|
||||
},
|
||||
{"Key": "backup2.tar", "LastModified": "2023-01-02T00:00:00+00:00"},
|
||||
]
|
||||
}
|
||||
|
||||
# Setup mock client
|
||||
mock_client = mock_config_entry.runtime_data
|
||||
mock_client.get_paginator.return_value.paginate.return_value.__aiter__.return_value = [
|
||||
page1,
|
||||
page2,
|
||||
]
|
||||
|
||||
# Mock get_object responses based on the key
|
||||
async def mock_get_object(**kwargs):
|
||||
"""Mock get_object with different responses based on the key."""
|
||||
key = kwargs.get("Key", "")
|
||||
if "backup1" in key:
|
||||
mock_body = AsyncMock()
|
||||
mock_body.read.return_value = json.dumps(backup1.as_dict()).encode()
|
||||
return {"Body": mock_body}
|
||||
# backup2
|
||||
mock_body = AsyncMock()
|
||||
mock_body.read.return_value = json.dumps(backup2.as_dict()).encode()
|
||||
return {"Body": mock_body}
|
||||
|
||||
mock_client.get_object.side_effect = mock_get_object
|
||||
|
||||
# List backups and verify we got both
|
||||
backups = await agent.async_list_backups()
|
||||
assert len(backups) == 2
|
||||
backup_ids = {backup.backup_id for backup in backups}
|
||||
assert backup_ids == {"backup1", "backup2"}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
'platform': 'matter',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <VacuumEntityFeature: 29212>,
|
||||
'supported_features': <VacuumEntityFeature: 12828>,
|
||||
'translation_key': 'vacuum',
|
||||
'unique_id': '00000000000004D2-000000000000002F-MatterNodeDevice-1-MatterVacuumCleaner-84-1',
|
||||
'unit_of_measurement': None,
|
||||
@@ -39,7 +39,7 @@
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'ecodeebot',
|
||||
'supported_features': <VacuumEntityFeature: 29212>,
|
||||
'supported_features': <VacuumEntityFeature: 12828>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'vacuum.ecodeebot',
|
||||
@@ -79,7 +79,7 @@
|
||||
'platform': 'matter',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <VacuumEntityFeature: 29212>,
|
||||
'supported_features': <VacuumEntityFeature: 12828>,
|
||||
'translation_key': 'vacuum',
|
||||
'unique_id': '00000000000004D2-0000000000000028-MatterNodeDevice-1-MatterVacuumCleaner-84-1',
|
||||
'unit_of_measurement': None,
|
||||
@@ -89,7 +89,7 @@
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': '2BAVS-AB6031X-44PE',
|
||||
'supported_features': <VacuumEntityFeature: 29212>,
|
||||
'supported_features': <VacuumEntityFeature: 12828>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'vacuum.2bavs_ab6031x_44pe',
|
||||
@@ -129,7 +129,7 @@
|
||||
'platform': 'matter',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <VacuumEntityFeature: 28700>,
|
||||
'supported_features': <VacuumEntityFeature: 12316>,
|
||||
'translation_key': 'vacuum',
|
||||
'unique_id': '00000000000004D2-0000000000000042-MatterNodeDevice-1-MatterVacuumCleaner-84-1',
|
||||
'unit_of_measurement': None,
|
||||
@@ -139,7 +139,7 @@
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Mock Vacuum',
|
||||
'supported_features': <VacuumEntityFeature: 28700>,
|
||||
'supported_features': <VacuumEntityFeature: 12316>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'vacuum.mock_vacuum',
|
||||
@@ -179,7 +179,7 @@
|
||||
'platform': 'matter',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': <VacuumEntityFeature: 28700>,
|
||||
'supported_features': <VacuumEntityFeature: 12316>,
|
||||
'translation_key': 'vacuum',
|
||||
'unique_id': '00000000000004D2-0000000000000061-MatterNodeDevice-1-MatterVacuumCleaner-84-1',
|
||||
'unit_of_measurement': None,
|
||||
@@ -189,7 +189,7 @@
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'K11+',
|
||||
'supported_features': <VacuumEntityFeature: 28700>,
|
||||
'supported_features': <VacuumEntityFeature: 12316>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'vacuum.k11',
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
"""Test Matter vacuum."""
|
||||
|
||||
from unittest.mock import MagicMock, call, patch
|
||||
from unittest.mock import MagicMock, call
|
||||
|
||||
from chip.clusters import Objects as clusters
|
||||
from matter_server.client.models.node import MatterNode
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.vacuum import DOMAIN as VACUUM_DOMAIN, VacuumEntityFeature
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
@@ -72,13 +71,8 @@ async def test_vacuum_actions(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert matter_client.send_device_command.call_count == 2
|
||||
assert matter_client.send_device_command.call_args_list[0] == call(
|
||||
node_id=matter_node.node_id,
|
||||
endpoint_id=1,
|
||||
command=clusters.ServiceArea.Commands.SelectAreas(newAreas=[]),
|
||||
)
|
||||
assert matter_client.send_device_command.call_args_list[1] == call(
|
||||
assert matter_client.send_device_command.call_count == 1
|
||||
assert matter_client.send_device_command.call_args == call(
|
||||
node_id=matter_node.node_id,
|
||||
endpoint_id=1,
|
||||
command=clusters.RvcRunMode.Commands.ChangeToMode(newMode=1),
|
||||
@@ -295,100 +289,5 @@ async def test_vacuum_actions_no_supported_run_modes(
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
component = hass.data["vacuum"]
|
||||
entity = component.get_entity(entity_id)
|
||||
assert entity is not None
|
||||
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="No supported run mode found to start the vacuum cleaner",
|
||||
):
|
||||
await entity.async_clean_segments(["7"])
|
||||
|
||||
# Ensure no commands were sent to the device
|
||||
assert matter_client.send_device_command.call_count == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("node_fixture", ["mock_vacuum_cleaner"])
|
||||
async def test_vacuum_clean_area(
|
||||
hass: HomeAssistant,
|
||||
matter_client: MagicMock,
|
||||
matter_node: MatterNode,
|
||||
) -> None:
|
||||
"""Test vacuum clean_area action."""
|
||||
# Fetch translations
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
entity_id = "vacuum.mock_vacuum"
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
|
||||
# Verify CLEAN_AREA feature is supported
|
||||
# Get the entity component to access entity
|
||||
component = hass.data["vacuum"]
|
||||
entity = component.get_entity(entity_id)
|
||||
assert entity is not None
|
||||
assert VacuumEntityFeature.CLEAN_AREA in entity.supported_features
|
||||
|
||||
# Get segments from the entity
|
||||
segments = await entity.async_get_segments()
|
||||
assert len(segments) == 3
|
||||
assert segments[0].id == "7"
|
||||
assert segments[0].name == "My Location A"
|
||||
assert segments[1].id == "1234567"
|
||||
assert segments[1].name == "My Location B"
|
||||
assert segments[2].id == "2290649224"
|
||||
assert segments[2].name == "My Location C"
|
||||
|
||||
# Test clean_segments method directly
|
||||
await entity.async_clean_segments(["7", "1234567"])
|
||||
|
||||
# Verify both commands were sent: SelectAreas followed by ChangeToMode
|
||||
assert matter_client.send_device_command.call_count == 2
|
||||
|
||||
# First call: SelectAreas with the area IDs
|
||||
assert matter_client.send_device_command.call_args_list[0] == call(
|
||||
node_id=matter_node.node_id,
|
||||
endpoint_id=1,
|
||||
command=clusters.ServiceArea.Commands.SelectAreas(newAreas=[7, 1234567]),
|
||||
)
|
||||
|
||||
# Second call: ChangeToMode to start cleaning (mode 1 is the CLEANING mode)
|
||||
assert matter_client.send_device_command.call_args_list[1] == call(
|
||||
node_id=matter_node.node_id,
|
||||
endpoint_id=1,
|
||||
command=clusters.RvcRunMode.Commands.ChangeToMode(newMode=1),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("node_fixture", ["mock_vacuum_cleaner"])
|
||||
async def test_vacuum_create_segments_issue_when_segments_changed(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
matter_client: MagicMock,
|
||||
matter_node: MatterNode,
|
||||
) -> None:
|
||||
"""Test segments issue callback is triggered when segments changed."""
|
||||
entity_id = "vacuum.mock_vacuum"
|
||||
component = hass.data["vacuum"]
|
||||
entity = component.get_entity(entity_id)
|
||||
assert entity is not None
|
||||
|
||||
entity_registry.async_update_entity_options(
|
||||
entity_id,
|
||||
VACUUM_DOMAIN,
|
||||
{
|
||||
"last_seen_segments": [
|
||||
{
|
||||
"id": "7",
|
||||
"name": "Old location A",
|
||||
"group": None,
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
with patch.object(entity, "async_create_segments_issue") as mock_create_issue:
|
||||
set_node_attribute(matter_node, 1, 97, 4, 0x02)
|
||||
await trigger_subscription_callback(hass, matter_client)
|
||||
|
||||
assert mock_create_issue.call_count >= 1
|
||||
|
||||
Reference in New Issue
Block a user