diff --git a/homeassistant/components/ecovacs/vacuum.py b/homeassistant/components/ecovacs/vacuum.py index 401274609d8..16cf5687720 100644 --- a/homeassistant/components/ecovacs/vacuum.py +++ b/homeassistant/components/ecovacs/vacuum.py @@ -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.""" diff --git a/tests/components/ecovacs/conftest.py b/tests/components/ecovacs/conftest.py index 59721b65563..e53cfcc8a3d 100644 --- a/tests/components/ecovacs/conftest.py +++ b/tests/components/ecovacs/conftest.py @@ -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.""" diff --git a/tests/components/ecovacs/fixtures/devices/123/device.json b/tests/components/ecovacs/fixtures/devices/123/device.json new file mode 100644 index 00000000000..07bdf01b156 --- /dev/null +++ b/tests/components/ecovacs/fixtures/devices/123/device.json @@ -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": {} +} diff --git a/tests/components/ecovacs/test_init.py b/tests/components/ecovacs/test_init.py index 27d00a2d023..c0c475217c1 100644 --- a/tests/components/ecovacs/test_init.py +++ b/tests/components/ecovacs/test_init.py @@ -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(