Add device_info to Glances entities (#73047)

pull/73921/head
avee87 2022-06-25 00:23:26 +01:00 committed by GitHub
parent a267045a31
commit ad3bd6773c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DATA_UPDATED, DOMAIN, SENSOR_TYPES, GlancesSensorEntityDescription
@ -30,6 +31,7 @@ async def async_setup_entry(
name,
disk["mnt_point"],
description,
config_entry.entry_id,
)
)
elif description.type == "sensors":
@ -42,11 +44,16 @@ async def async_setup_entry(
name,
sensor["label"],
description,
config_entry.entry_id,
)
)
elif description.type == "raid":
for raid_device in client.api.data[description.type]:
dev.append(GlancesSensor(client, name, raid_device, description))
dev.append(
GlancesSensor(
client, name, raid_device, description, config_entry.entry_id
)
)
elif client.api.data[description.type]:
dev.append(
GlancesSensor(
@ -54,6 +61,7 @@ async def async_setup_entry(
name,
"",
description,
config_entry.entry_id,
)
)
@ -71,6 +79,7 @@ class GlancesSensor(SensorEntity):
name,
sensor_name_prefix,
description: GlancesSensorEntityDescription,
config_entry_id: str,
):
"""Initialize the sensor."""
self.glances_data = glances_data
@ -80,6 +89,11 @@ class GlancesSensor(SensorEntity):
self.entity_description = description
self._attr_name = f"{name} {sensor_name_prefix} {description.name_suffix}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, config_entry_id)},
manufacturer="Glances",
name=name,
)
@property
def unique_id(self):