Add AsusWRT model and firmware information for device (#51102)

This commit is contained in:
ollo69 2021-05-26 18:46:06 +02:00 committed by GitHub
parent 5ac81ccb4c
commit daff62f42d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -195,6 +195,8 @@ class AsusWrtRouter:
self._api: AsusWrt = None
self._protocol = entry.data[CONF_PROTOCOL]
self._host = entry.data[CONF_HOST]
self._model = "Asus Router"
self._sw_v = None
self._devices: dict[str, Any] = {}
self._connected_devices = 0
@ -224,6 +226,14 @@ class AsusWrtRouter:
if not self._api.is_connected:
raise ConfigEntryNotReady
# System
model = await _get_nvram_info(self._api, "MODEL")
if model:
self._model = model["model"]
firmware = await _get_nvram_info(self._api, "FIRMWARE")
if firmware:
self._sw_v = f"{firmware['firmver']} (build {firmware['buildno']})"
# Load tracked entities from registry
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
track_entries = (
@ -373,8 +383,9 @@ class AsusWrtRouter:
return {
"identifiers": {(DOMAIN, "AsusWRT")},
"name": self._host,
"model": "Asus Router",
"model": self._model,
"manufacturer": "Asus",
"sw_version": self._sw_v,
}
@property
@ -408,6 +419,17 @@ class AsusWrtRouter:
return self._api
async def _get_nvram_info(api: AsusWrt, info_type):
"""Get AsusWrt router info from nvram."""
info = {}
try:
info = await api.async_get_nvram(info_type)
except OSError as exc:
_LOGGER.warning("Error calling method async_get_nvram(%s): %s", info_type, exc)
return info
def get_api(conf: dict, options: dict | None = None) -> AsusWrt:
"""Get the AsusWrt API."""
opt = options or {}

View File

@ -56,6 +56,13 @@ def mock_controller_connect(mock_devices):
service_mock.return_value.connection.async_connect = AsyncMock()
service_mock.return_value.is_connected = True
service_mock.return_value.connection.disconnect = Mock()
service_mock.return_value.async_get_nvram = AsyncMock(
return_value={
"model": "abcd",
"firmver": "efg",
"buildno": "123",
}
)
service_mock.return_value.async_get_connected_devices = AsyncMock(
return_value=mock_devices
)