mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Add device info for legacy Ecovacs bots (#122671)
* add device info * add tests
This commit is contained in:
parent
3ad2456dd9
commit
092ab823d1
@ -26,6 +26,7 @@ from homeassistant.components.vacuum import (
|
|||||||
from homeassistant.core import HomeAssistant, SupportsResponse
|
from homeassistant.core import HomeAssistant, SupportsResponse
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
@ -75,6 +76,7 @@ class EcovacsLegacyVacuum(StateVacuumEntity):
|
|||||||
"""Legacy Ecovacs vacuums."""
|
"""Legacy Ecovacs vacuums."""
|
||||||
|
|
||||||
_attr_fan_speed_list = [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
|
_attr_fan_speed_list = [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
|
||||||
|
_attr_has_entity_name = True
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
VacuumEntityFeature.BATTERY
|
VacuumEntityFeature.BATTERY
|
||||||
@ -95,7 +97,16 @@ class EcovacsLegacyVacuum(StateVacuumEntity):
|
|||||||
|
|
||||||
self.error: str | None = None
|
self.error: str | None = None
|
||||||
self._attr_unique_id = vacuum["did"]
|
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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Set up the event listeners now that hass is ready."""
|
"""Set up the event listeners now that hass is ready."""
|
||||||
|
@ -117,6 +117,27 @@ def mock_mqtt_client(mock_authenticator: Mock) -> Generator[Mock]:
|
|||||||
yield client
|
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
|
@pytest.fixture
|
||||||
def mock_device_execute() -> Generator[AsyncMock]:
|
def mock_device_execute() -> Generator[AsyncMock]:
|
||||||
"""Mock the device execute function."""
|
"""Mock the device execute function."""
|
||||||
|
23
tests/components/ecovacs/fixtures/devices/123/device.json
Normal file
23
tests/components/ecovacs/fixtures/devices/123/device.json
Normal 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": {}
|
||||||
|
}
|
@ -129,12 +129,15 @@ async def test_devices_in_dr(
|
|||||||
assert device_entry == snapshot(name=device.device_info["did"])
|
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(
|
@pytest.mark.parametrize(
|
||||||
("device_fixture", "entities"),
|
("device_fixture", "entities"),
|
||||||
[
|
[
|
||||||
("yna5x1", 26),
|
("yna5x1", 26),
|
||||||
("5xu9h3", 24),
|
("5xu9h3", 24),
|
||||||
|
("123", 1),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_all_entities_loaded(
|
async def test_all_entities_loaded(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user