Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions homeassistant/components/vera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device info requires a config entry to be used. Please submit this PR after the config entries PR.

https://developers.home-assistant.io/docs/en/device_registry_index.html#defining-devices

"""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."""
Expand Down
1 change: 1 addition & 0 deletions tests/components/vera/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
Expand Down
22 changes: 22 additions & 0 deletions tests/components/vera/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CONF_LIGHTS,
DOMAIN,
VERA_DEVICES,
VeraDevice as VeraDeviceEntity,
)
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -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,
}