mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Add diagnostics to Paperless-ngx (#145465)
* Add diagnostics to Paperless-ngx * Add diagnostics to Paperless-ngx
This commit is contained in:
parent
c3d318ff51
commit
3f99a0bb65
18
homeassistant/components/paperless_ngx/diagnostics.py
Normal file
18
homeassistant/components/paperless_ngx/diagnostics.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"""Diagnostics support for Paperless-ngx."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import asdict
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import PaperlessConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: PaperlessConfigEntry,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
return {"data": asdict(entry.runtime_data.data)}
|
@ -43,7 +43,7 @@ rules:
|
|||||||
|
|
||||||
# Gold
|
# Gold
|
||||||
devices: done
|
devices: done
|
||||||
diagnostics: todo
|
diagnostics: done
|
||||||
discovery-update-info:
|
discovery-update-info:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: Paperless does not support discovery.
|
comment: Paperless does not support discovery.
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_config_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'data': dict({
|
||||||
|
'character_count': 99999,
|
||||||
|
'correspondent_count': 99,
|
||||||
|
'current_asn': 99,
|
||||||
|
'document_file_type_counts': list([
|
||||||
|
dict({
|
||||||
|
'mime_type': 'application/pdf',
|
||||||
|
'mime_type_count': 998,
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'mime_type': 'image/png',
|
||||||
|
'mime_type_count': 1,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'document_type_count': 99,
|
||||||
|
'documents_inbox': 9,
|
||||||
|
'documents_total': 999,
|
||||||
|
'inbox_tag': 9,
|
||||||
|
'inbox_tags': list([
|
||||||
|
9,
|
||||||
|
]),
|
||||||
|
'storage_path_count': 9,
|
||||||
|
'tag_count': 99,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
@ -1,5 +1,5 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_correspondents-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_correspondents-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -35,7 +35,7 @@
|
|||||||
'unit_of_measurement': 'correspondents',
|
'unit_of_measurement': 'correspondents',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_correspondents-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_correspondents-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Correspondents',
|
'friendly_name': 'Paperless-ngx Correspondents',
|
||||||
@ -50,7 +50,7 @@
|
|||||||
'state': '99',
|
'state': '99',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_document_types-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_document_types-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -86,7 +86,7 @@
|
|||||||
'unit_of_measurement': 'document types',
|
'unit_of_measurement': 'document types',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_document_types-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_document_types-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Document types',
|
'friendly_name': 'Paperless-ngx Document types',
|
||||||
@ -101,7 +101,7 @@
|
|||||||
'state': '99',
|
'state': '99',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_documents_in_inbox-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_documents_in_inbox-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -137,7 +137,7 @@
|
|||||||
'unit_of_measurement': 'documents',
|
'unit_of_measurement': 'documents',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_documents_in_inbox-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_documents_in_inbox-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Documents in inbox',
|
'friendly_name': 'Paperless-ngx Documents in inbox',
|
||||||
@ -152,7 +152,7 @@
|
|||||||
'state': '9',
|
'state': '9',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_tags-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_tags-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -188,7 +188,7 @@
|
|||||||
'unit_of_measurement': 'tags',
|
'unit_of_measurement': 'tags',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_tags-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_tags-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Tags',
|
'friendly_name': 'Paperless-ngx Tags',
|
||||||
@ -203,7 +203,7 @@
|
|||||||
'state': '99',
|
'state': '99',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_total_characters-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_total_characters-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -239,7 +239,7 @@
|
|||||||
'unit_of_measurement': 'characters',
|
'unit_of_measurement': 'characters',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_total_characters-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_total_characters-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Total characters',
|
'friendly_name': 'Paperless-ngx Total characters',
|
||||||
@ -254,7 +254,7 @@
|
|||||||
'state': '99999',
|
'state': '99999',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_total_documents-entry]
|
# name: test_sensor_platform[sensor.paperless_ngx_total_documents-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@ -290,7 +290,7 @@
|
|||||||
'unit_of_measurement': 'documents',
|
'unit_of_measurement': 'documents',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_sensor_platfom[sensor.paperless_ngx_total_documents-state]
|
# name: test_sensor_platform[sensor.paperless_ngx_total_documents-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'friendly_name': 'Paperless-ngx Total documents',
|
'friendly_name': 'Paperless-ngx Total documents',
|
||||||
|
28
tests/components/paperless_ngx/test_diagnostics.py
Normal file
28
tests/components/paperless_ngx/test_diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Tests for Paperless-ngx sensor platform."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import setup_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
async def test_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_paperless: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test generating diagnostics for a device entry."""
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
assert (
|
||||||
|
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||||
|
== snapshot
|
||||||
|
)
|
@ -28,7 +28,7 @@ from tests.common import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_platfom(
|
async def test_sensor_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user