mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Add AsusWRT model and firmware information for device (#51102)
This commit is contained in:
parent
5ac81ccb4c
commit
daff62f42d
@ -195,6 +195,8 @@ class AsusWrtRouter:
|
|||||||
self._api: AsusWrt = None
|
self._api: AsusWrt = None
|
||||||
self._protocol = entry.data[CONF_PROTOCOL]
|
self._protocol = entry.data[CONF_PROTOCOL]
|
||||||
self._host = entry.data[CONF_HOST]
|
self._host = entry.data[CONF_HOST]
|
||||||
|
self._model = "Asus Router"
|
||||||
|
self._sw_v = None
|
||||||
|
|
||||||
self._devices: dict[str, Any] = {}
|
self._devices: dict[str, Any] = {}
|
||||||
self._connected_devices = 0
|
self._connected_devices = 0
|
||||||
@ -224,6 +226,14 @@ class AsusWrtRouter:
|
|||||||
if not self._api.is_connected:
|
if not self._api.is_connected:
|
||||||
raise ConfigEntryNotReady
|
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
|
# Load tracked entities from registry
|
||||||
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
|
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
|
||||||
track_entries = (
|
track_entries = (
|
||||||
@ -373,8 +383,9 @@ class AsusWrtRouter:
|
|||||||
return {
|
return {
|
||||||
"identifiers": {(DOMAIN, "AsusWRT")},
|
"identifiers": {(DOMAIN, "AsusWRT")},
|
||||||
"name": self._host,
|
"name": self._host,
|
||||||
"model": "Asus Router",
|
"model": self._model,
|
||||||
"manufacturer": "Asus",
|
"manufacturer": "Asus",
|
||||||
|
"sw_version": self._sw_v,
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -408,6 +419,17 @@ class AsusWrtRouter:
|
|||||||
return self._api
|
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:
|
def get_api(conf: dict, options: dict | None = None) -> AsusWrt:
|
||||||
"""Get the AsusWrt API."""
|
"""Get the AsusWrt API."""
|
||||||
opt = options or {}
|
opt = options or {}
|
||||||
|
@ -56,6 +56,13 @@ def mock_controller_connect(mock_devices):
|
|||||||
service_mock.return_value.connection.async_connect = AsyncMock()
|
service_mock.return_value.connection.async_connect = AsyncMock()
|
||||||
service_mock.return_value.is_connected = True
|
service_mock.return_value.is_connected = True
|
||||||
service_mock.return_value.connection.disconnect = Mock()
|
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(
|
service_mock.return_value.async_get_connected_devices = AsyncMock(
|
||||||
return_value=mock_devices
|
return_value=mock_devices
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user