diff --git a/homeassistant/components/vera/__init__.py b/homeassistant/components/vera/__init__.py index 1c9d412d974ddd..285924d9ab6d71 100644 --- a/homeassistant/components/vera/__init__.py +++ b/homeassistant/components/vera/__init__.py @@ -84,6 +84,10 @@ def stop_subscription(event): hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_subscription) try: + # Load controller information like serial number. + controller.refresh_data() + + # Get devices. all_devices = controller.get_devices() all_scenes = controller.get_scenes() @@ -171,6 +175,19 @@ def should_poll(self): """Get polling requirement from vera device.""" return self.vera_device.should_poll + @property + def device_info(self): + """Return information about the device.""" + unique_id = f"{self.controller.serial_number}_{self.vera_device.vera_device_id}" + return { + "name": self._name, + "model": "Unknown", + "manufacturer": "Unknown", + "connections": {("serial_id", unique_id)}, + "identifiers": {unique_id}, + "battery": self.vera_device.battery_level, + } + @property def device_state_attributes(self): """Return the state attributes of the device.""" diff --git a/tests/components/vera/common.py b/tests/components/vera/common.py index bd87e8bc9f2f0f..7f55eb8de25d28 100644 --- a/tests/components/vera/common.py +++ b/tests/components/vera/common.py @@ -35,6 +35,7 @@ async def configure_component( controller = MagicMock(spec=VeraController) # type: VeraController controller.base_url = controller_url + controller.serial_number = "1111" controller.register = MagicMock() controller.get_devices = MagicMock(return_value=devices or ()) controller.get_scenes = MagicMock(return_value=scenes or ()) diff --git a/tests/components/vera/test_init.py b/tests/components/vera/test_init.py index 9ff6cb4058b3c0..3e36b8b545940e 100644 --- a/tests/components/vera/test_init.py +++ b/tests/components/vera/test_init.py @@ -21,6 +21,7 @@ CONF_LIGHTS, DOMAIN, VERA_DEVICES, + VeraDevice as VeraDeviceEntity, ) from homeassistant.core import HomeAssistant @@ -76,3 +77,24 @@ def setup_callback(controller: VeraController, hass_config: dict) -> None: assert_hass_vera_devices(hass, "lock", 1) assert_hass_vera_devices(hass, "climate", 1) assert_hass_vera_devices(hass, "cover", 1) + + +def test_vera_device_entity(): + """Test function.""" + controller = MagicMock(spec=VeraController) # type: VeraController + controller.serial_number = "SN" + device = MagicMock(spec=VeraDevice) # type: VeraDevice + device.name = "first device" + device.device_id = "1" + device.vera_device_id = "1" + device.battery_level = 23 + + entity = VeraDeviceEntity(device, controller) + assert entity.device_info == { + "name": device.name, + "model": "Unknown", + "manufacturer": "Unknown", + "connections": {("serial_id", "SN_1")}, + "identifiers": {"SN_1"}, + "battery": 23, + }