Add device info for legacy Ecovacs bots (#122671)

* add device info

* add tests
pull/122732/head
Michael 2024-07-28 11:06:32 +02:00 committed by GitHub
parent 3ad2456dd9
commit 092ab823d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 2 deletions

View File

@ -26,6 +26,7 @@ from homeassistant.components.vacuum import (
from homeassistant.core import HomeAssistant, SupportsResponse
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import entity_platform
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.icon import icon_for_battery_level
from homeassistant.util import slugify
@ -75,6 +76,7 @@ class EcovacsLegacyVacuum(StateVacuumEntity):
"""Legacy Ecovacs vacuums."""
_attr_fan_speed_list = [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
_attr_has_entity_name = True
_attr_should_poll = False
_attr_supported_features = (
VacuumEntityFeature.BATTERY
@ -95,7 +97,16 @@ class EcovacsLegacyVacuum(StateVacuumEntity):
self.error: str | None = None
self._attr_unique_id = vacuum["did"]
self._attr_name = vacuum.get("nick", vacuum["did"])
if (name := vacuum.get("nick")) is None:
name = vacuum.get("name", vacuum["did"])
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, vacuum["did"])},
model=vacuum.get("deviceName"),
name=name,
serial_number=vacuum["did"],
)
async def async_added_to_hass(self) -> None:
"""Set up the event listeners now that hass is ready."""

View File

@ -117,6 +117,27 @@ def mock_mqtt_client(mock_authenticator: Mock) -> Generator[Mock]:
yield client
@pytest.fixture
def mock_vacbot(device_fixture: str) -> Generator[Mock]:
"""Mock the legacy VacBot."""
with patch(
"homeassistant.components.ecovacs.controller.VacBot",
autospec=True,
) as mock:
vacbot = mock.return_value
vacbot.vacuum = load_json_object_fixture(
f"devices/{device_fixture}/device.json", DOMAIN
)
vacbot.statusEvents = Mock()
vacbot.batteryEvents = Mock()
vacbot.lifespanEvents = Mock()
vacbot.errorEvents = Mock()
vacbot.battery_status = None
vacbot.fan_speed = None
vacbot.components = {}
yield vacbot
@pytest.fixture
def mock_device_execute() -> Generator[AsyncMock]:
"""Mock the device execute function."""

View File

@ -0,0 +1,23 @@
{
"did": "E1234567890000000003",
"name": "E1234567890000000003",
"class": "123",
"resource": "atom",
"company": "eco-legacy",
"deviceName": "DEEBOT Slim2 Series",
"icon": "https://portal-ww.ecouser.net/api/pim/file/get/5d2c150dba13eb00013feaae",
"ota": false,
"UILogicId": "ECO_INTL_123",
"materialNo": "110-1639-0102",
"pid": "5cae9b201285190001685977",
"product_category": "DEEBOT",
"model": "Slim2",
"updateInfo": {
"needUpdate": false,
"changeLog": ""
},
"nick": null,
"homeSort": 9999,
"status": 2,
"otaUpgrade": {}
}

View File

@ -129,12 +129,15 @@ async def test_devices_in_dr(
assert device_entry == snapshot(name=device.device_info["did"])
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration")
@pytest.mark.usefixtures(
"entity_registry_enabled_by_default", "mock_vacbot", "init_integration"
)
@pytest.mark.parametrize(
("device_fixture", "entities"),
[
("yna5x1", 26),
("5xu9h3", 24),
("123", 1),
],
)
async def test_all_entities_loaded(