mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Suggest area for NUT based on device location (#129770)
This commit is contained in:
parent
6897b24c10
commit
9c8d8fef16
@ -132,6 +132,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: NutConfigEntry) -> bool:
|
||||
model=data.device_info.model,
|
||||
sw_version=data.device_info.firmware,
|
||||
serial_number=data.device_info.serial,
|
||||
suggested_area=data.device_info.device_location,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
@ -211,6 +212,7 @@ class NUTDeviceInfo:
|
||||
model: str | None = None
|
||||
firmware: str | None = None
|
||||
serial: str | None = None
|
||||
device_location: str | None = None
|
||||
|
||||
|
||||
class PyNUTData:
|
||||
@ -271,7 +273,8 @@ class PyNUTData:
|
||||
model = _model_from_status(self._status)
|
||||
firmware = _firmware_from_status(self._status)
|
||||
serial = _serial_from_status(self._status)
|
||||
return NUTDeviceInfo(manufacturer, model, firmware, serial)
|
||||
device_location: str | None = self._status.get("device.location")
|
||||
return NUTDeviceInfo(manufacturer, model, firmware, serial, device_location)
|
||||
|
||||
async def _async_get_status(self) -> dict[str, str]:
|
||||
"""Get the ups status from NUT."""
|
||||
|
@ -120,3 +120,30 @@ async def test_serial_number(hass: HomeAssistant) -> None:
|
||||
|
||||
assert device_entry is not None
|
||||
assert device_entry.serial_number == mock_serial_number
|
||||
|
||||
|
||||
async def test_device_location(hass: HomeAssistant) -> None:
|
||||
"""Test for suggested location on device."""
|
||||
mock_serial_number = "A00000000000"
|
||||
mock_device_location = "XYZ Location"
|
||||
await async_init_integration(
|
||||
hass,
|
||||
username="someuser",
|
||||
password="somepassword",
|
||||
list_vars={
|
||||
"ups.serial": mock_serial_number,
|
||||
"device.location": mock_device_location,
|
||||
},
|
||||
list_ups={"ups1": "UPS 1"},
|
||||
list_commands_return_value=[],
|
||||
)
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
assert device_registry is not None
|
||||
|
||||
device_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, mock_serial_number)}
|
||||
)
|
||||
|
||||
assert device_entry is not None
|
||||
assert device_entry.suggested_area == mock_device_location
|
||||
|
Loading…
x
Reference in New Issue
Block a user