mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Address late review for Nextcloud (#99226)
This commit is contained in:
parent
0da94c20b0
commit
d5adf33225
@ -41,7 +41,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
for entity in entities:
|
||||
old_uid_start = f"{entry.data[CONF_URL]}#nextcloud_"
|
||||
new_uid_start = f"{entry.data[CONF_URL]}#"
|
||||
new_uid_start = f"{entry.entry_id}#"
|
||||
if entity.unique_id.startswith(old_uid_start):
|
||||
new_uid = entity.unique_id.replace(old_uid_start, new_uid_start)
|
||||
_LOGGER.debug("migrate unique id '%s' to '%s'", entity.unique_id, new_uid)
|
||||
|
@ -23,7 +23,7 @@ class NextcloudEntity(CoordinatorEntity[NextcloudDataUpdateCoordinator]):
|
||||
) -> None:
|
||||
"""Initialize the Nextcloud sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = f"{coordinator.url}#{description.key}"
|
||||
self._attr_unique_id = f"{entry.entry_id}#{description.key}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url=coordinator.url,
|
||||
identifiers={(DOMAIN, entry.entry_id)},
|
||||
|
@ -1,8 +1,10 @@
|
||||
"""Summary data from Nextcoud."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from typing import Final, cast
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
@ -18,7 +20,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util.dt import utc_from_timestamp
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import NextcloudDataUpdateCoordinator
|
||||
@ -26,32 +28,42 @@ from .entity import NextcloudEntity
|
||||
|
||||
UNIT_OF_LOAD: Final[str] = "load"
|
||||
|
||||
SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
SensorEntityDescription(
|
||||
|
||||
@dataclass
|
||||
class NextcloudSensorEntityDescription(SensorEntityDescription):
|
||||
"""Describes Nextcloud sensor entity."""
|
||||
|
||||
value_fn: Callable[
|
||||
[str | int | float], str | int | float | datetime
|
||||
] = lambda value: value
|
||||
|
||||
|
||||
SENSORS: Final[list[NextcloudSensorEntityDescription]] = [
|
||||
NextcloudSensorEntityDescription(
|
||||
key="activeUsers_last1hour",
|
||||
translation_key="nextcloud_activeusers_last1hour",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:account-multiple",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="activeUsers_last24hours",
|
||||
translation_key="nextcloud_activeusers_last24hours",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:account-multiple",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="activeUsers_last5minutes",
|
||||
translation_key="nextcloud_activeusers_last5minutes",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:account-multiple",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_expunges",
|
||||
translation_key="nextcloud_cache_expunges",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_mem_size",
|
||||
translation_key="nextcloud_cache_mem_size",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -60,56 +72,57 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_memory_type",
|
||||
translation_key="nextcloud_cache_memory_type",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_num_entries",
|
||||
translation_key="nextcloud_cache_num_entries",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_num_hits",
|
||||
translation_key="nextcloud_cache_num_hits",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_num_inserts",
|
||||
translation_key="nextcloud_cache_num_inserts",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_num_misses",
|
||||
translation_key="nextcloud_cache_num_misses",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_num_slots",
|
||||
translation_key="nextcloud_cache_num_slots",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_start_time",
|
||||
translation_key="nextcloud_cache_start_time",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda val: utc_from_timestamp(float(val)),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="cache_ttl",
|
||||
translation_key="nextcloud_cache_ttl",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="database_size",
|
||||
translation_key="nextcloud_database_size",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -118,19 +131,19 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="database_type",
|
||||
translation_key="nextcloud_database_type",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:database",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="database_version",
|
||||
translation_key="nextcloud_database_version",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:database",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="interned_strings_usage_buffer_size",
|
||||
translation_key="nextcloud_interned_strings_usage_buffer_size",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -140,7 +153,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="interned_strings_usage_free_memory",
|
||||
translation_key="nextcloud_interned_strings_usage_free_memory",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -150,13 +163,13 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="interned_strings_usage_number_of_strings",
|
||||
translation_key="nextcloud_interned_strings_usage_number_of_strings",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="interned_strings_usage_used_memory",
|
||||
translation_key="nextcloud_interned_strings_usage_used_memory",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -166,7 +179,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="jit_buffer_free",
|
||||
translation_key="nextcloud_jit_buffer_free",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -176,7 +189,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="jit_buffer_size",
|
||||
translation_key="nextcloud_jit_buffer_size",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -186,93 +199,94 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="jit_kind",
|
||||
translation_key="nextcloud_jit_kind",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="jit_opt_flags",
|
||||
translation_key="nextcloud_jit_opt_flags",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="jit_opt_level",
|
||||
translation_key="nextcloud_jit_opt_level",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_blacklist_miss_ratio",
|
||||
translation_key="nextcloud_opcache_statistics_blacklist_miss_ratio",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_blacklist_misses",
|
||||
translation_key="nextcloud_opcache_statistics_blacklist_misses",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_hash_restarts",
|
||||
translation_key="nextcloud_opcache_statistics_hash_restarts",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_hits",
|
||||
translation_key="nextcloud_opcache_statistics_hits",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_last_restart_time",
|
||||
translation_key="nextcloud_opcache_statistics_last_restart_time",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda val: utc_from_timestamp(float(val)),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_manual_restarts",
|
||||
translation_key="nextcloud_opcache_statistics_manual_restarts",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_max_cached_keys",
|
||||
translation_key="nextcloud_opcache_statistics_max_cached_keys",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_misses",
|
||||
translation_key="nextcloud_opcache_statistics_misses",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_num_cached_keys",
|
||||
translation_key="nextcloud_opcache_statistics_num_cached_keys",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_num_cached_scripts",
|
||||
translation_key="nextcloud_opcache_statistics_num_cached_scripts",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_oom_restarts",
|
||||
translation_key="nextcloud_opcache_statistics_oom_restarts",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_opcache_hit_rate",
|
||||
translation_key="nextcloud_opcache_statistics_opcache_hit_rate",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
@ -280,14 +294,15 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="opcache_statistics_start_time",
|
||||
translation_key="nextcloud_opcache_statistics_start_time",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda val: utc_from_timestamp(float(val)),
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_opcache_memory_usage_current_wasted_percentage",
|
||||
translation_key="nextcloud_server_php_opcache_memory_usage_current_wasted_percentage",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
@ -296,7 +311,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_opcache_memory_usage_free_memory",
|
||||
translation_key="nextcloud_server_php_opcache_memory_usage_free_memory",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -307,7 +322,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_opcache_memory_usage_used_memory",
|
||||
translation_key="nextcloud_server_php_opcache_memory_usage_used_memory",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -318,7 +333,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_opcache_memory_usage_wasted_memory",
|
||||
translation_key="nextcloud_server_php_opcache_memory_usage_wasted_memory",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -329,7 +344,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_max_execution_time",
|
||||
translation_key="nextcloud_server_php_max_execution_time",
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
@ -337,7 +352,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
icon="mdi:language-php",
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_memory_limit",
|
||||
translation_key="nextcloud_server_php_memory_limit",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -347,7 +362,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_upload_max_filesize",
|
||||
translation_key="nextcloud_server_php_upload_max_filesize",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -357,62 +372,62 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_php_version",
|
||||
translation_key="nextcloud_server_php_version",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
icon="mdi:language-php",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="server_webserver",
|
||||
translation_key="nextcloud_server_webserver",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_fed_shares_sent",
|
||||
translation_key="nextcloud_shares_num_fed_shares_sent",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_fed_shares_received",
|
||||
translation_key="nextcloud_shares_num_fed_shares_received",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares",
|
||||
translation_key="nextcloud_shares_num_shares",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_groups",
|
||||
translation_key="nextcloud_shares_num_shares_groups",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_link",
|
||||
translation_key="nextcloud_shares_num_shares_link",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_link_no_password",
|
||||
translation_key="nextcloud_shares_num_shares_link_no_password",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_mail",
|
||||
translation_key="nextcloud_shares_num_shares_mail",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_room",
|
||||
translation_key="nextcloud_shares_num_shares_room",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="server_num_shares_user",
|
||||
NextcloudSensorEntityDescription(
|
||||
key="shares_num_shares_user",
|
||||
translation_key="nextcloud_shares_num_shares_user",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="sma_avail_mem",
|
||||
translation_key="nextcloud_sma_avail_mem",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -422,13 +437,13 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="sma_num_seg",
|
||||
translation_key="nextcloud_sma_num_seg",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="sma_seg_size",
|
||||
translation_key="nextcloud_sma_seg_size",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -438,64 +453,64 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=1,
|
||||
suggested_unit_of_measurement=UnitOfInformation.MEGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_files",
|
||||
translation_key="nextcloud_storage_num_files",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_storages",
|
||||
translation_key="nextcloud_storage_num_storages",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_storages_home",
|
||||
translation_key="nextcloud_storage_num_storages_home",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_storages_local",
|
||||
translation_key="nextcloud_storage_num_storages_local",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_storages_other",
|
||||
translation_key="nextcloud_storage_num_storages_other",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="storage_num_users",
|
||||
translation_key="nextcloud_storage_num_users",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_apps_num_installed",
|
||||
translation_key="nextcloud_system_apps_num_installed",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_apps_num_updates_available",
|
||||
translation_key="nextcloud_system_apps_num_updates_available",
|
||||
icon="mdi:update",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_cpuload_1",
|
||||
translation_key="nextcloud_system_cpuload_1",
|
||||
native_unit_of_measurement=UNIT_OF_LOAD,
|
||||
icon="mdi:chip",
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_cpuload_5",
|
||||
translation_key="nextcloud_system_cpuload_5",
|
||||
native_unit_of_measurement=UNIT_OF_LOAD,
|
||||
icon="mdi:chip",
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_cpuload_15",
|
||||
translation_key="nextcloud_system_cpuload_15",
|
||||
native_unit_of_measurement=UNIT_OF_LOAD,
|
||||
icon="mdi:chip",
|
||||
suggested_display_precision=2,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_freespace",
|
||||
translation_key="nextcloud_system_freespace",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -504,7 +519,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=2,
|
||||
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_mem_free",
|
||||
translation_key="nextcloud_system_mem_free",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -513,7 +528,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=2,
|
||||
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_mem_total",
|
||||
translation_key="nextcloud_system_mem_total",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -522,25 +537,25 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=2,
|
||||
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_memcache.distributed",
|
||||
translation_key="nextcloud_system_memcache_distributed",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_memcache.local",
|
||||
translation_key="nextcloud_system_memcache_local",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_memcache.locking",
|
||||
translation_key="nextcloud_system_memcache_locking",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_swap_total",
|
||||
translation_key="nextcloud_system_swap_total",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -549,7 +564,7 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=2,
|
||||
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_swap_free",
|
||||
translation_key="nextcloud_system_swap_free",
|
||||
device_class=SensorDeviceClass.DATA_SIZE,
|
||||
@ -558,11 +573,11 @@ SENSORS: Final[list[SensorEntityDescription]] = [
|
||||
suggested_display_precision=2,
|
||||
suggested_unit_of_measurement=UnitOfInformation.GIGABYTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_theme",
|
||||
translation_key="nextcloud_system_theme",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
NextcloudSensorEntityDescription(
|
||||
key="system_version",
|
||||
translation_key="nextcloud_system_version",
|
||||
),
|
||||
@ -586,13 +601,10 @@ async def async_setup_entry(
|
||||
class NextcloudSensor(NextcloudEntity, SensorEntity):
|
||||
"""Represents a Nextcloud sensor."""
|
||||
|
||||
entity_description: NextcloudSensorEntityDescription
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType | datetime:
|
||||
def native_value(self) -> str | int | float | datetime:
|
||||
"""Return the state for this sensor."""
|
||||
val = self.coordinator.data.get(self.entity_description.key)
|
||||
if (
|
||||
getattr(self.entity_description, "device_class", None)
|
||||
== SensorDeviceClass.TIMESTAMP
|
||||
):
|
||||
return datetime.fromtimestamp(cast(int, val), tz=UTC)
|
||||
return val
|
||||
return self.entity_description.value_fn(val) # type: ignore[arg-type]
|
||||
|
Loading…
x
Reference in New Issue
Block a user