Fix glances raid plugin data (#94597)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
e5c1ce65df
commit
239f5fe56b
3 changed files with 87 additions and 27 deletions
|
@ -223,13 +223,6 @@ SENSOR_TYPES = {
|
|||
icon="mdi:docker",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
("raid", "used"): GlancesSensorEntityDescription(
|
||||
key="used",
|
||||
type="raid",
|
||||
name_suffix="Raid used",
|
||||
icon="mdi:harddisk",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
("raid", "available"): GlancesSensorEntityDescription(
|
||||
key="available",
|
||||
type="raid",
|
||||
|
@ -237,6 +230,13 @@ SENSOR_TYPES = {
|
|||
icon="mdi:harddisk",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
("raid", "used"): GlancesSensorEntityDescription(
|
||||
key="used",
|
||||
type="raid",
|
||||
name_suffix="Raid used",
|
||||
icon="mdi:harddisk",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
@ -269,36 +269,36 @@ async def async_setup_entry(
|
|||
if sensor_type in ["fs", "sensors", "raid"]:
|
||||
for sensor_label, params in sensors.items():
|
||||
for param in params:
|
||||
sensor_description = SENSOR_TYPES[(sensor_type, param)]
|
||||
if sensor_description := SENSOR_TYPES.get((sensor_type, param)):
|
||||
_migrate_old_unique_ids(
|
||||
hass,
|
||||
f"{coordinator.host}-{name} {sensor_label} {sensor_description.name_suffix}",
|
||||
f"{sensor_label}-{sensor_description.key}",
|
||||
)
|
||||
entities.append(
|
||||
GlancesSensor(
|
||||
coordinator,
|
||||
name,
|
||||
sensor_label,
|
||||
sensor_description,
|
||||
)
|
||||
)
|
||||
else:
|
||||
for sensor in sensors:
|
||||
if sensor_description := SENSOR_TYPES.get((sensor_type, sensor)):
|
||||
_migrate_old_unique_ids(
|
||||
hass,
|
||||
f"{coordinator.host}-{name} {sensor_label} {sensor_description.name_suffix}",
|
||||
f"{sensor_label}-{sensor_description.key}",
|
||||
f"{coordinator.host}-{name} {sensor_description.name_suffix}",
|
||||
f"-{sensor_description.key}",
|
||||
)
|
||||
entities.append(
|
||||
GlancesSensor(
|
||||
coordinator,
|
||||
name,
|
||||
sensor_label,
|
||||
"",
|
||||
sensor_description,
|
||||
)
|
||||
)
|
||||
else:
|
||||
for sensor in sensors:
|
||||
sensor_description = SENSOR_TYPES[(sensor_type, sensor)]
|
||||
_migrate_old_unique_ids(
|
||||
hass,
|
||||
f"{coordinator.host}-{name} {sensor_description.name_suffix}",
|
||||
f"-{sensor_description.key}",
|
||||
)
|
||||
entities.append(
|
||||
GlancesSensor(
|
||||
coordinator,
|
||||
name,
|
||||
"",
|
||||
sensor_description,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
|
@ -137,6 +137,40 @@ MOCK_DATA = {
|
|||
"os_version": "5.15.6-200.fc35.x86_64",
|
||||
"hr_name": "Fedora Linux 35 64bit",
|
||||
},
|
||||
"raid": {
|
||||
"md3": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdh1": "2", "sdi1": "0"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
"md1": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdg": "0", "sde": "1"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
"md4": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdf1": "1", "sdb1": "0"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
"md0": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdc": "2", "sdd": "3"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
},
|
||||
"uptime": "3 days, 10:25:20",
|
||||
}
|
||||
|
||||
|
@ -156,4 +190,22 @@ HA_SENSOR_DATA: dict[str, Any] = {
|
|||
"memory_free": 2745.0,
|
||||
},
|
||||
"docker": {"docker_active": 2, "docker_cpu_use": 77.2, "docker_memory_use": 1149.6},
|
||||
"raid": {
|
||||
"md3": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdh1": "2", "sdi1": "0"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
"md1": {
|
||||
"status": "active",
|
||||
"type": "raid1",
|
||||
"components": {"sdg": "0", "sde": "1"},
|
||||
"available": "2",
|
||||
"used": "2",
|
||||
"config": "UU",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -35,6 +35,14 @@ async def test_sensor_states(hass: HomeAssistant) -> None:
|
|||
assert state.state == HA_SENSOR_DATA["docker"]["docker_cpu_use"]
|
||||
if state := hass.states.get("sensor.0_0_0_0_docker_memory_use"):
|
||||
assert state.state == HA_SENSOR_DATA["docker"]["docker_memory_use"]
|
||||
if state := hass.states.get("sensor.0_0_0_0_md3_available"):
|
||||
assert state.state == HA_SENSOR_DATA["raid"]["md3"]["available"]
|
||||
if state := hass.states.get("sensor.0_0_0_0_md3_used"):
|
||||
assert state.state == HA_SENSOR_DATA["raid"]["md3"]["used"]
|
||||
if state := hass.states.get("sensor.0_0_0_0_md1_available"):
|
||||
assert state.state == HA_SENSOR_DATA["raid"]["md1"]["available"]
|
||||
if state := hass.states.get("sensor.0_0_0_0_md1_used"):
|
||||
assert state.state == HA_SENSOR_DATA["raid"]["md1"]["used"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Add table
Reference in a new issue