Skip to content

Commit

Permalink
Add diagnostics for IPP (#113205)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington authored and frenck committed Mar 14, 2024
1 parent cda9bf7 commit 297c7c1
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
28 changes: 28 additions & 0 deletions homeassistant/components/ipp/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Diagnostics support for Internet Printing Protocol (IPP)."""

from __future__ import annotations

from typing import Any

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .coordinator import IPPDataUpdateCoordinator


async def async_get_config_entry_diagnostics(
hass: HomeAssistant, config_entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: IPPDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]

return {
"entry": {
"data": {
**config_entry.data,
},
"unique_id": config_entry.unique_id,
},
"data": coordinator.data.as_dict(),
}
100 changes: 100 additions & 0 deletions tests/components/ipp/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# serializer version: 1
# name: test_diagnostics
dict({
'data': dict({
'info': dict({
'command_set': 'ESCPL2,BDC,D4,D4PX,ESCPR7,END4,GENEP,URF',
'location': None,
'manufacturer': 'TEST',
'model': 'HA-1000 Series',
'more_info': 'http://192.168.1.31:80/PRESENTATION/BONJOUR',
'name': 'Test HA-1000 Series',
'printer_info': 'Test HA-1000 Series',
'printer_name': 'Test Printer',
'printer_uri_supported': list([
'ipps://192.168.1.31:631/ipp/print',
'ipp://192.168.1.31:631/ipp/print',
]),
'serial': '555534593035345555',
'uptime': 30,
'uuid': 'cfe92100-67c4-11d4-a45f-f8d027761251',
'version': '20.23.06HA',
}),
'markers': list([
dict({
'color': '#000000',
'high_level': 100,
'level': 58,
'low_level': 10,
'marker_id': 0,
'marker_type': 'ink-cartridge',
'name': 'Black ink',
}),
dict({
'color': '#00FFFF',
'high_level': 100,
'level': 91,
'low_level': 10,
'marker_id': 2,
'marker_type': 'ink-cartridge',
'name': 'Cyan ink',
}),
dict({
'color': '#FF00FF',
'high_level': 100,
'level': 73,
'low_level': 10,
'marker_id': 4,
'marker_type': 'ink-cartridge',
'name': 'Magenta ink',
}),
dict({
'color': '#000000',
'high_level': 100,
'level': 98,
'low_level': 10,
'marker_id': 1,
'marker_type': 'ink-cartridge',
'name': 'Photo black ink',
}),
dict({
'color': '#FFFF00',
'high_level': 100,
'level': 95,
'low_level': 10,
'marker_id': 3,
'marker_type': 'ink-cartridge',
'name': 'Yellow ink',
}),
]),
'state': dict({
'message': None,
'printer_state': 'idle',
'reasons': None,
}),
'uris': list([
dict({
'authentication': None,
'security': 'tls',
'uri': 'ipps://192.168.1.31:631/ipp/print',
}),
dict({
'authentication': None,
'security': None,
'uri': 'ipp://192.168.1.31:631/ipp/print',
}),
]),
}),
'entry': dict({
'data': dict({
'base_path': '/ipp/print',
'host': '192.168.1.31',
'port': 631,
'ssl': False,
'uuid': 'cfe92100-67c4-11d4-a45f-f8d027761251',
'verify_ssl': True,
}),
'unique_id': 'cfe92100-67c4-11d4-a45f-f8d027761251',
}),
})
# ---
22 changes: 22 additions & 0 deletions tests/components/ipp/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Tests for the diagnostics data provided by the Internet Printing Protocol (IPP) integration."""

from syrupy import SnapshotAssertion

from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator


async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics for config entry."""
assert (
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
== snapshot
)

0 comments on commit 297c7c1

Please sign in to comment.