Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glances raid plugin data #94597

Merged
merged 6 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 26 additions & 26 deletions homeassistant/components/glances/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ class GlancesSensorEntityDescription(
icon="mdi:docker",
state_class=SensorStateClass.MEASUREMENT,
),
("raid", "used"): GlancesSensorEntityDescription(
key="used",
("raid", "available"): GlancesSensorEntityDescription(
key="available",
type="raid",
name_suffix="Raid used",
name_suffix="Raid available",
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
("raid", "available"): GlancesSensorEntityDescription(
key="available",
("raid", "used"): GlancesSensorEntityDescription(
key="used",
type="raid",
name_suffix="Raid available",
name_suffix="Raid used",
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
Expand Down Expand Up @@ -269,36 +269,36 @@ def _migrate_old_unique_ids(
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)

Expand Down
52 changes: 52 additions & 0 deletions tests/components/glances/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,40 @@
"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",
}

Expand All @@ -156,4 +190,22 @@
"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",
},
},
}
8 changes: 8 additions & 0 deletions tests/components/glances/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down