mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add device info to Nextcloud integration (#90328)
* add device_info * use entry_id as identifier + device name * use shorthand attributes * remove model from device info Co-authored-by: Franck Nijhof <frenck@frenck.nl> --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
1c465b5ad0
commit
e4bb339a1e
@ -25,7 +25,7 @@ async def async_setup_entry(
|
|||||||
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
NextcloudBinarySensor(coordinator, name)
|
NextcloudBinarySensor(coordinator, name, entry)
|
||||||
for name in coordinator.data
|
for name in coordinator.data
|
||||||
if name in BINARY_SENSORS
|
if name in BINARY_SENSORS
|
||||||
]
|
]
|
||||||
|
@ -1,23 +1,31 @@
|
|||||||
"""Base entity for the Nextcloud integration."""
|
"""Base entity for the Nextcloud integration."""
|
||||||
|
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
from .coordinator import NextcloudDataUpdateCoordinator
|
from .coordinator import NextcloudDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class NextcloudEntity(CoordinatorEntity[NextcloudDataUpdateCoordinator]):
|
class NextcloudEntity(CoordinatorEntity[NextcloudDataUpdateCoordinator]):
|
||||||
"""Base Nextcloud entity."""
|
"""Base Nextcloud entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
_attr_icon = "mdi:cloud"
|
_attr_icon = "mdi:cloud"
|
||||||
|
|
||||||
def __init__(self, coordinator: NextcloudDataUpdateCoordinator, item: str) -> None:
|
def __init__(
|
||||||
|
self, coordinator: NextcloudDataUpdateCoordinator, item: str, entry: ConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Initialize the Nextcloud sensor."""
|
"""Initialize the Nextcloud sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.item = item
|
self.item = item
|
||||||
self._attr_name = item
|
self._attr_name = item
|
||||||
|
self._attr_unique_id = f"{coordinator.url}#{item}"
|
||||||
@property
|
self._attr_device_info = DeviceInfo(
|
||||||
def unique_id(self) -> str:
|
name="Nextcloud",
|
||||||
"""Return the unique ID for this sensor."""
|
identifiers={(DOMAIN, entry.entry_id)},
|
||||||
return f"{self.coordinator.url}#{self.item}"
|
sw_version=coordinator.data.get("nextcloud_system_version"),
|
||||||
|
configuration_url=coordinator.url,
|
||||||
|
)
|
||||||
|
@ -65,7 +65,7 @@ async def async_setup_entry(
|
|||||||
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
NextcloudSensor(coordinator, name)
|
NextcloudSensor(coordinator, name, entry)
|
||||||
for name in coordinator.data
|
for name in coordinator.data
|
||||||
if name in SENSORS
|
if name in SENSORS
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user