mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Netgear add CPU and Memory utilization sensors (#72667)
This commit is contained in:
parent
d323508f79
commit
f2809262d5
@ -18,6 +18,7 @@ from .const import (
|
|||||||
KEY_COORDINATOR_LINK,
|
KEY_COORDINATOR_LINK,
|
||||||
KEY_COORDINATOR_SPEED,
|
KEY_COORDINATOR_SPEED,
|
||||||
KEY_COORDINATOR_TRAFFIC,
|
KEY_COORDINATOR_TRAFFIC,
|
||||||
|
KEY_COORDINATOR_UTIL,
|
||||||
KEY_ROUTER,
|
KEY_ROUTER,
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
)
|
)
|
||||||
@ -84,6 +85,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
"""Fetch data from the router."""
|
"""Fetch data from the router."""
|
||||||
return await router.async_get_speed_test()
|
return await router.async_get_speed_test()
|
||||||
|
|
||||||
|
async def async_update_utilization() -> dict[str, Any] | None:
|
||||||
|
"""Fetch data from the router."""
|
||||||
|
return await router.async_get_utilization()
|
||||||
|
|
||||||
async def async_check_link_status() -> dict[str, Any] | None:
|
async def async_check_link_status() -> dict[str, Any] | None:
|
||||||
"""Fetch data from the router."""
|
"""Fetch data from the router."""
|
||||||
return await router.async_get_link_status()
|
return await router.async_get_link_status()
|
||||||
@ -110,6 +115,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
update_method=async_update_speed_test,
|
update_method=async_update_speed_test,
|
||||||
update_interval=SPEED_TEST_INTERVAL,
|
update_interval=SPEED_TEST_INTERVAL,
|
||||||
)
|
)
|
||||||
|
coordinator_utilization = DataUpdateCoordinator(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name=f"{router.device_name} Utilization",
|
||||||
|
update_method=async_update_utilization,
|
||||||
|
update_interval=SCAN_INTERVAL,
|
||||||
|
)
|
||||||
coordinator_link = DataUpdateCoordinator(
|
coordinator_link = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
@ -121,6 +133,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
if router.track_devices:
|
if router.track_devices:
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
await coordinator_traffic_meter.async_config_entry_first_refresh()
|
await coordinator_traffic_meter.async_config_entry_first_refresh()
|
||||||
|
await coordinator_utilization.async_config_entry_first_refresh()
|
||||||
await coordinator_link.async_config_entry_first_refresh()
|
await coordinator_link.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = {
|
hass.data[DOMAIN][entry.entry_id] = {
|
||||||
@ -128,6 +141,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
KEY_COORDINATOR: coordinator,
|
KEY_COORDINATOR: coordinator,
|
||||||
KEY_COORDINATOR_TRAFFIC: coordinator_traffic_meter,
|
KEY_COORDINATOR_TRAFFIC: coordinator_traffic_meter,
|
||||||
KEY_COORDINATOR_SPEED: coordinator_speed_test,
|
KEY_COORDINATOR_SPEED: coordinator_speed_test,
|
||||||
|
KEY_COORDINATOR_UTIL: coordinator_utilization,
|
||||||
KEY_COORDINATOR_LINK: coordinator_link,
|
KEY_COORDINATOR_LINK: coordinator_link,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ KEY_ROUTER = "router"
|
|||||||
KEY_COORDINATOR = "coordinator"
|
KEY_COORDINATOR = "coordinator"
|
||||||
KEY_COORDINATOR_TRAFFIC = "coordinator_traffic"
|
KEY_COORDINATOR_TRAFFIC = "coordinator_traffic"
|
||||||
KEY_COORDINATOR_SPEED = "coordinator_speed"
|
KEY_COORDINATOR_SPEED = "coordinator_speed"
|
||||||
|
KEY_COORDINATOR_UTIL = "coordinator_utilization"
|
||||||
KEY_COORDINATOR_LINK = "coordinator_link"
|
KEY_COORDINATOR_LINK = "coordinator_link"
|
||||||
|
|
||||||
DEFAULT_CONSIDER_HOME = timedelta(seconds=180)
|
DEFAULT_CONSIDER_HOME = timedelta(seconds=180)
|
||||||
|
@ -240,6 +240,11 @@ class NetgearRouter:
|
|||||||
self._api.allow_block_device, mac, allow_block
|
self._api.allow_block_device, mac, allow_block
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def async_get_utilization(self) -> dict[str, Any] | None:
|
||||||
|
"""Get the system information about utilization of the router."""
|
||||||
|
async with self._api_lock:
|
||||||
|
return await self.hass.async_add_executor_job(self._api.get_system_info)
|
||||||
|
|
||||||
async def async_reboot(self) -> None:
|
async def async_reboot(self) -> None:
|
||||||
"""Reboot the router."""
|
"""Reboot the router."""
|
||||||
async with self._api_lock:
|
async with self._api_lock:
|
||||||
|
@ -12,6 +12,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -32,6 +33,7 @@ from .const import (
|
|||||||
KEY_COORDINATOR_LINK,
|
KEY_COORDINATOR_LINK,
|
||||||
KEY_COORDINATOR_SPEED,
|
KEY_COORDINATOR_SPEED,
|
||||||
KEY_COORDINATOR_TRAFFIC,
|
KEY_COORDINATOR_TRAFFIC,
|
||||||
|
KEY_COORDINATOR_UTIL,
|
||||||
KEY_ROUTER,
|
KEY_ROUTER,
|
||||||
)
|
)
|
||||||
from .router import NetgearDeviceEntity, NetgearRouter, NetgearRouterEntity
|
from .router import NetgearDeviceEntity, NetgearRouter, NetgearRouterEntity
|
||||||
@ -245,6 +247,25 @@ SENSOR_SPEED_TYPES = [
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
SENSOR_UTILIZATION = [
|
||||||
|
NetgearSensorEntityDescription(
|
||||||
|
key="NewCPUUtilization",
|
||||||
|
name="CPU Utilization",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
icon="mdi:cpu-64-bit",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
NetgearSensorEntityDescription(
|
||||||
|
key="NewMemoryUtilization",
|
||||||
|
name="Memory Utilization",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
icon="mdi:memory",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
SENSOR_LINK_TYPES = [
|
SENSOR_LINK_TYPES = [
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewEthernetLinkStatus",
|
key="NewEthernetLinkStatus",
|
||||||
@ -263,6 +284,7 @@ async def async_setup_entry(
|
|||||||
coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR]
|
coordinator = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR]
|
||||||
coordinator_traffic = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_TRAFFIC]
|
coordinator_traffic = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_TRAFFIC]
|
||||||
coordinator_speed = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_SPEED]
|
coordinator_speed = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_SPEED]
|
||||||
|
coordinator_utilization = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_UTIL]
|
||||||
coordinator_link = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_LINK]
|
coordinator_link = hass.data[DOMAIN][entry.entry_id][KEY_COORDINATOR_LINK]
|
||||||
|
|
||||||
# Router entities
|
# Router entities
|
||||||
@ -278,6 +300,11 @@ async def async_setup_entry(
|
|||||||
NetgearRouterSensorEntity(coordinator_speed, router, description)
|
NetgearRouterSensorEntity(coordinator_speed, router, description)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for description in SENSOR_UTILIZATION:
|
||||||
|
router_entities.append(
|
||||||
|
NetgearRouterSensorEntity(coordinator_utilization, router, description)
|
||||||
|
)
|
||||||
|
|
||||||
for description in SENSOR_LINK_TYPES:
|
for description in SENSOR_LINK_TYPES:
|
||||||
router_entities.append(
|
router_entities.append(
|
||||||
NetgearRouterSensorEntity(coordinator_link, router, description)
|
NetgearRouterSensorEntity(coordinator_link, router, description)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user