mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add model_id to rainforest_raven device info (#128652)
* Remove single-use rainforest properties * Add model_id
This commit is contained in:
parent
d4c9841e44
commit
356e09091d
@ -81,20 +81,6 @@ class RAVEnDataCoordinator(DataUpdateCoordinator):
|
||||
update_interval=timedelta(seconds=30),
|
||||
)
|
||||
|
||||
@property
|
||||
def device_fw_version(self) -> str | None:
|
||||
"""Return the firmware version of the device."""
|
||||
if self._device_info:
|
||||
return self._device_info.fw_version
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_hw_version(self) -> str | None:
|
||||
"""Return the hardware version of the device."""
|
||||
if self._device_info:
|
||||
return self._device_info.hw_version
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_mac_address(self) -> str | None:
|
||||
"""Return the MAC address of the device."""
|
||||
@ -102,36 +88,20 @@ class RAVEnDataCoordinator(DataUpdateCoordinator):
|
||||
return self._device_info.device_mac_id.hex()
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_manufacturer(self) -> str | None:
|
||||
"""Return the manufacturer of the device."""
|
||||
if self._device_info:
|
||||
return self._device_info.manufacturer
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_model(self) -> str | None:
|
||||
"""Return the model of the device."""
|
||||
if self._device_info:
|
||||
return self._device_info.model_id
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_name(self) -> str:
|
||||
"""Return the product name of the device."""
|
||||
return "RAVEn Device"
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return device info."""
|
||||
if self._device_info and self.device_mac_address:
|
||||
if (device_info := self._device_info) and (
|
||||
mac_address := self.device_mac_address
|
||||
):
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device_mac_address)},
|
||||
manufacturer=self.device_manufacturer,
|
||||
model=self.device_model,
|
||||
name=self.device_name,
|
||||
sw_version=self.device_fw_version,
|
||||
hw_version=self.device_hw_version,
|
||||
identifiers={(DOMAIN, mac_address)},
|
||||
manufacturer=device_info.manufacturer,
|
||||
model=device_info.model_id,
|
||||
model_id=device_info.model_id,
|
||||
name="RAVEn Device",
|
||||
sw_version=device_info.fw_version,
|
||||
hw_version=device_info.hw_version,
|
||||
)
|
||||
return None
|
||||
|
||||
|
39
tests/components/rainforest_raven/snapshots/test_init.ambr
Normal file
39
tests/components/rainforest_raven/snapshots/test_init.ambr
Normal file
@ -0,0 +1,39 @@
|
||||
# serializer version: 1
|
||||
# name: test_device_registry[None-0]
|
||||
list([
|
||||
])
|
||||
# ---
|
||||
# name: test_device_registry[device_info0-1]
|
||||
list([
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': '2.7.3',
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'rainforest_raven',
|
||||
'abcdef0123456789',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': 'Rainforest Automation, Inc.',
|
||||
'model': 'Z105-2-EMU2-LEDD_JM',
|
||||
'model_id': 'Z105-2-EMU2-LEDD_JM',
|
||||
'name': 'RAVEn Device',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '2.0.0 (7400)',
|
||||
'via_device_id': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
@ -15,32 +15,6 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from . import create_mock_entry
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_device")
|
||||
async def test_coordinator_device_info(hass: HomeAssistant) -> None:
|
||||
"""Test reporting device information from the coordinator."""
|
||||
entry = create_mock_entry()
|
||||
entry._async_set_state(hass, ConfigEntryState.SETUP_IN_PROGRESS, None)
|
||||
coordinator = RAVEnDataCoordinator(hass, entry)
|
||||
|
||||
assert coordinator.device_fw_version is None
|
||||
assert coordinator.device_hw_version is None
|
||||
assert coordinator.device_info is None
|
||||
assert coordinator.device_mac_address is None
|
||||
assert coordinator.device_manufacturer is None
|
||||
assert coordinator.device_model is None
|
||||
assert coordinator.device_name == "RAVEn Device"
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
assert coordinator.device_fw_version == "2.0.0 (7400)"
|
||||
assert coordinator.device_hw_version == "2.7.3"
|
||||
assert coordinator.device_info
|
||||
assert coordinator.device_mac_address
|
||||
assert coordinator.device_manufacturer == "Rainforest Automation, Inc."
|
||||
assert coordinator.device_model == "Z105-2-EMU2-LEDD_JM"
|
||||
assert coordinator.device_name == "RAVEn Device"
|
||||
|
||||
|
||||
async def test_coordinator_cache_device(
|
||||
hass: HomeAssistant, mock_device: AsyncMock
|
||||
) -> None:
|
||||
|
@ -1,8 +1,18 @@
|
||||
"""Tests for the Rainforest RAVEn component initialisation."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aioraven.data import DeviceInfo as RAVenDeviceInfo
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.rainforest_raven.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import create_mock_entry
|
||||
from .const import DEVICE_INFO
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -18,4 +28,30 @@ async def test_load_unload_entry(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_entry.state is ConfigEntryState.NOT_LOADED
|
||||
assert not hass.data.get(DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("device_info", "device_count"),
|
||||
[(DEVICE_INFO, 1), (None, 0)],
|
||||
)
|
||||
async def test_device_registry(
|
||||
hass: HomeAssistant,
|
||||
mock_device: AsyncMock,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
device_info: RAVenDeviceInfo | None,
|
||||
device_count: int,
|
||||
) -> None:
|
||||
"""Test device registry, including if get_device_info returns None."""
|
||||
mock_device.get_device_info.return_value = device_info
|
||||
entry = create_mock_entry()
|
||||
entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert len(hass.states.async_all()) == 5
|
||||
|
||||
entries = dr.async_entries_for_config_entry(device_registry, entry.entry_id)
|
||||
assert len(entries) == device_count
|
||||
assert entries == snapshot
|
||||
|
Loading…
x
Reference in New Issue
Block a user