Systemmonitor always load imported disks (#106546)
* Systemmonitor always load legacy disks * loaded_resources
This commit is contained in:
parent
df894acefa
commit
fa34cbc414
1 changed files with 30 additions and 0 deletions
|
@ -389,6 +389,7 @@ async def async_setup_entry(
|
||||||
entities = []
|
entities = []
|
||||||
sensor_registry: dict[tuple[str, str], SensorData] = {}
|
sensor_registry: dict[tuple[str, str], SensorData] = {}
|
||||||
legacy_resources: list[str] = entry.options.get("resources", [])
|
legacy_resources: list[str] = entry.options.get("resources", [])
|
||||||
|
loaded_resources: list[str] = []
|
||||||
disk_arguments = await hass.async_add_executor_job(get_all_disk_mounts)
|
disk_arguments = await hass.async_add_executor_job(get_all_disk_mounts)
|
||||||
network_arguments = await hass.async_add_executor_job(get_all_network_interfaces)
|
network_arguments = await hass.async_add_executor_job(get_all_network_interfaces)
|
||||||
cpu_temperature = await hass.async_add_executor_job(_read_cpu_temperature)
|
cpu_temperature = await hass.async_add_executor_job(_read_cpu_temperature)
|
||||||
|
@ -404,6 +405,7 @@ async def async_setup_entry(
|
||||||
is_enabled = check_legacy_resource(
|
is_enabled = check_legacy_resource(
|
||||||
f"{_type}_{argument}", legacy_resources
|
f"{_type}_{argument}", legacy_resources
|
||||||
)
|
)
|
||||||
|
loaded_resources.append(f"{_type}_{argument}")
|
||||||
entities.append(
|
entities.append(
|
||||||
SystemMonitorSensor(
|
SystemMonitorSensor(
|
||||||
sensor_registry,
|
sensor_registry,
|
||||||
|
@ -423,6 +425,7 @@ async def async_setup_entry(
|
||||||
is_enabled = check_legacy_resource(
|
is_enabled = check_legacy_resource(
|
||||||
f"{_type}_{argument}", legacy_resources
|
f"{_type}_{argument}", legacy_resources
|
||||||
)
|
)
|
||||||
|
loaded_resources.append(f"{_type}_{argument}")
|
||||||
entities.append(
|
entities.append(
|
||||||
SystemMonitorSensor(
|
SystemMonitorSensor(
|
||||||
sensor_registry,
|
sensor_registry,
|
||||||
|
@ -446,6 +449,7 @@ async def async_setup_entry(
|
||||||
sensor_registry[(_type, argument)] = SensorData(
|
sensor_registry[(_type, argument)] = SensorData(
|
||||||
argument, None, None, None, None
|
argument, None, None, None, None
|
||||||
)
|
)
|
||||||
|
loaded_resources.append(f"{_type}_{argument}")
|
||||||
entities.append(
|
entities.append(
|
||||||
SystemMonitorSensor(
|
SystemMonitorSensor(
|
||||||
sensor_registry,
|
sensor_registry,
|
||||||
|
@ -459,6 +463,7 @@ async def async_setup_entry(
|
||||||
|
|
||||||
sensor_registry[(_type, "")] = SensorData("", None, None, None, None)
|
sensor_registry[(_type, "")] = SensorData("", None, None, None, None)
|
||||||
is_enabled = check_legacy_resource(f"{_type}_", legacy_resources)
|
is_enabled = check_legacy_resource(f"{_type}_", legacy_resources)
|
||||||
|
loaded_resources.append(f"{_type}_")
|
||||||
entities.append(
|
entities.append(
|
||||||
SystemMonitorSensor(
|
SystemMonitorSensor(
|
||||||
sensor_registry,
|
sensor_registry,
|
||||||
|
@ -469,6 +474,31 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Ensure legacy imported disk_* resources are loaded if they are not part
|
||||||
|
# of mount points automatically discovered
|
||||||
|
for resource in legacy_resources:
|
||||||
|
if resource.startswith("disk_"):
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Check resource %s already loaded in %s", resource, loaded_resources
|
||||||
|
)
|
||||||
|
if resource not in loaded_resources:
|
||||||
|
split_index = resource.rfind("_")
|
||||||
|
_type = resource[:split_index]
|
||||||
|
argument = resource[split_index + 1 :]
|
||||||
|
_LOGGER.debug("Loading legacy %s with argument %s", _type, argument)
|
||||||
|
sensor_registry[(_type, argument)] = SensorData(
|
||||||
|
argument, None, None, None, None
|
||||||
|
)
|
||||||
|
entities.append(
|
||||||
|
SystemMonitorSensor(
|
||||||
|
sensor_registry,
|
||||||
|
SENSOR_TYPES[_type],
|
||||||
|
entry.entry_id,
|
||||||
|
argument,
|
||||||
|
True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
scan_interval = DEFAULT_SCAN_INTERVAL
|
scan_interval = DEFAULT_SCAN_INTERVAL
|
||||||
await async_setup_sensor_registry_updates(hass, sensor_registry, scan_interval)
|
await async_setup_sensor_registry_updates(hass, sensor_registry, scan_interval)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
Loading…
Add table
Reference in a new issue