Skip to content

Commit

Permalink
Add device info to Nextcloud integration (home-assistant#90328)
Browse files Browse the repository at this point in the history
* add device_info

* use entry_id as identifier + device name

* use shorthand attributes

* remove model from device info

Co-authored-by: Franck Nijhof <[email protected]>

---------

Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
mib1185 and frenck authored Mar 28, 2023
1 parent 1c465b5 commit e4bb339
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/nextcloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def async_setup_entry(
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities(
[
NextcloudBinarySensor(coordinator, name)
NextcloudBinarySensor(coordinator, name, entry)
for name in coordinator.data
if name in BINARY_SENSORS
]
Expand Down
20 changes: 14 additions & 6 deletions homeassistant/components/nextcloud/entity.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
"""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 .const import DOMAIN
from .coordinator import NextcloudDataUpdateCoordinator


class NextcloudEntity(CoordinatorEntity[NextcloudDataUpdateCoordinator]):
"""Base Nextcloud entity."""

_attr_has_entity_name = True
_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."""
super().__init__(coordinator)
self.item = item
self._attr_name = item

@property
def unique_id(self) -> str:
"""Return the unique ID for this sensor."""
return f"{self.coordinator.url}#{self.item}"
self._attr_unique_id = f"{coordinator.url}#{item}"
self._attr_device_info = DeviceInfo(
name="Nextcloud",
identifiers={(DOMAIN, entry.entry_id)},
sw_version=coordinator.data.get("nextcloud_system_version"),
configuration_url=coordinator.url,
)
2 changes: 1 addition & 1 deletion homeassistant/components/nextcloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def async_setup_entry(
coordinator: NextcloudDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities(
[
NextcloudSensor(coordinator, name)
NextcloudSensor(coordinator, name, entry)
for name in coordinator.data
if name in SENSORS
]
Expand Down

0 comments on commit e4bb339

Please sign in to comment.