diff --git a/homeassistant/components/hp_printer/diagnostics.py b/homeassistant/components/hp_printer/diagnostics.py index e97bb1352345..c104446f1cc6 100644 --- a/homeassistant/components/hp_printer/diagnostics.py +++ b/homeassistant/components/hp_printer/diagnostics.py @@ -11,11 +11,16 @@ from .coordinator import HpPrinterConfigEntry TO_REDACT = { CONF_HOST, + "friendly_name", + # Job log entries: the print driver's user and document name. + "name", "printer_id", "serial_number", "ssid_prefix", "supply_serial_number", "unique_id", + "user_id", + "uuid", } diff --git a/homeassistant/components/hp_printer/manifest.json b/homeassistant/components/hp_printer/manifest.json index ea084a67ed90..5821f9bdeee7 100644 --- a/homeassistant/components/hp_printer/manifest.json +++ b/homeassistant/components/hp_printer/manifest.json @@ -10,5 +10,5 @@ "iot_class": "local_polling", "loggers": ["aiohpprinter"], "quality_scale": "bronze", - "requirements": ["aiohpprinter==3.1.1"] + "requirements": ["aiohpprinter==3.7.0"] } diff --git a/homeassistant/components/hp_printer/sensor.py b/homeassistant/components/hp_printer/sensor.py index 240b81480a88..0a965103b12a 100644 --- a/homeassistant/components/hp_printer/sensor.py +++ b/homeassistant/components/hp_printer/sensor.py @@ -43,10 +43,20 @@ SENSORS: tuple[HpPrinterSensorEntityDescription, ...] = ( key="status", translation_key="status", device_class=SensorDeviceClass.ENUM, - options=[status.value for status in HpDeviceStatus], + # The printer's own "unknown" status maps to Home Assistant's unknown state. + options=[ + status.value + for status in HpDeviceStatus + if status is not HpDeviceStatus.UNKNOWN + ], # Unknown statuses are reported as None, which must not hide the sensor. always_create=True, - value_fn=lambda data: data.status.status if data.status else None, + value_fn=lambda data: ( + status + if data.status + and (status := data.status.status) is not HpDeviceStatus.UNKNOWN + else None + ), ), HpPrinterSensorEntityDescription( key="total_pages", diff --git a/homeassistant/components/hp_printer/strings.json b/homeassistant/components/hp_printer/strings.json index 9d1c0f01880d..01c607b9ad32 100644 --- a/homeassistant/components/hp_printer/strings.json +++ b/homeassistant/components/hp_printer/strings.json @@ -97,12 +97,15 @@ "name": "Status", "state": { "cancel_job": "Canceling job", + "close_door_or_cover": "Close door or cover", "copying": "Copying", "in_power_save": "Power save", + "initializing": "Initializing", "off": "[%key:common::state::off%]", "processing": "Printing", "ready": "Ready", "scan_processing": "Scanning", + "shutting_down": "Shutting down", "tray_empty": "Paper tray empty" } }, diff --git a/requirements_all.txt b/requirements_all.txt index 3dfe4cdbf4bd..a947fd9170fd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -316,7 +316,7 @@ aiohomekit==4.0.1 aiohortos==0.3.1 # homeassistant.components.hp_printer -aiohpprinter==3.1.1 +aiohpprinter==3.7.0 # homeassistant.components.mcp_server aiohttp_sse==2.2.0 diff --git a/tests/components/hp_printer/conftest.py b/tests/components/hp_printer/conftest.py index 2a26eed2bd14..a9f2b014b712 100644 --- a/tests/components/hp_printer/conftest.py +++ b/tests/components/hp_printer/conftest.py @@ -8,10 +8,12 @@ from aiohpprinter import ( HpConsumable, HpCopyUsage, HpFaxUsage, + HpJob, HpPrinterData, HpPrinterDevice, HpPrinterStatus, HpPrinterUsage, + HpProductLogs, HpScannerUsage, ) import pytest @@ -45,6 +47,8 @@ def mock_device() -> HpPrinterDevice: product_number="226Y0B", manufacturer_name="HP", manufactured_at=datetime(2023, 3, 13), + uuid="1c852a4d-b800-1f08-abcd-0123456789ab", + friendly_name="Office printer", ) @@ -120,6 +124,16 @@ def mock_data(mock_device: HpPrinterDevice) -> HpPrinterData: color_impressions=18, ), fax_usage=HpFaxUsage(total_impressions=0), + logs=HpProductLogs( + jobs=[ + HpJob( + application_id="Microsoft Word", + user_id="jane.doe", + name="Quarterly report.docx", + total_impressions=3, + ) + ] + ), ) diff --git a/tests/components/hp_printer/snapshots/test_diagnostics.ambr b/tests/components/hp_printer/snapshots/test_diagnostics.ambr index 66ef26858a0b..15749231bbd4 100644 --- a/tests/components/hp_printer/snapshots/test_diagnostics.ambr +++ b/tests/components/hp_printer/snapshots/test_diagnostics.ambr @@ -11,13 +11,17 @@ 'consumable_type': 'ink', 'counterfeit_refilled_count': None, 'estimated_pages_remaining': None, + 'family_name': None, 'genuine_refilled_count': None, 'installed_at': None, + 'low_threshold': None, 'manufactured_at': None, 'manufacturer_name': None, 'marker_color': 'Cyan', 'max_capacity': None, + 'measured_quantity_state': None, 'percentage_level_remaining': 40.0, + 'previous_cartridge': None, 'product_number': None, 'raw_percentage_level_remaining': None, 'selectibility_number': None, @@ -36,13 +40,17 @@ 'consumable_type': 'printhead', 'counterfeit_refilled_count': None, 'estimated_pages_remaining': None, + 'family_name': None, 'genuine_refilled_count': None, 'installed_at': None, + 'low_threshold': None, 'manufactured_at': None, 'manufacturer_name': None, 'marker_color': None, 'max_capacity': None, + 'measured_quantity_state': None, 'percentage_level_remaining': None, + 'previous_cartridge': None, 'product_number': None, 'raw_percentage_level_remaining': None, 'selectibility_number': None, @@ -61,13 +69,17 @@ 'consumable_type': 'ink', 'counterfeit_refilled_count': None, 'estimated_pages_remaining': 550, + 'family_name': None, 'genuine_refilled_count': None, 'installed_at': None, + 'low_threshold': None, 'manufactured_at': None, 'manufacturer_name': None, 'marker_color': 'Black', 'max_capacity': None, + 'measured_quantity_state': None, 'percentage_level_remaining': 80.0, + 'previous_cartridge': None, 'product_number': None, 'raw_percentage_level_remaining': None, 'selectibility_number': None, @@ -86,13 +98,17 @@ 'consumable_type': 'ink', 'counterfeit_refilled_count': None, 'estimated_pages_remaining': None, + 'family_name': None, 'genuine_refilled_count': None, 'installed_at': None, + 'low_threshold': None, 'manufactured_at': None, 'manufacturer_name': None, 'marker_color': 'Magenta', 'max_capacity': None, + 'measured_quantity_state': None, 'percentage_level_remaining': 40.0, + 'previous_cartridge': None, 'product_number': None, 'raw_percentage_level_remaining': None, 'selectibility_number': None, @@ -111,13 +127,17 @@ 'consumable_type': 'ink', 'counterfeit_refilled_count': None, 'estimated_pages_remaining': None, + 'family_name': None, 'genuine_refilled_count': None, 'installed_at': None, + 'low_threshold': None, 'manufactured_at': None, 'manufacturer_name': None, 'marker_color': 'Yellow', 'max_capacity': None, + 'measured_quantity_state': None, 'percentage_level_remaining': 40.0, + 'previous_cartridge': None, 'product_number': None, 'raw_percentage_level_remaining': None, 'selectibility_number': None, @@ -139,13 +159,24 @@ 'total_impressions': 20, }), 'device': dict({ + 'admin_password_set': None, + 'duplex_unit': None, + 'firmware_date': None, + 'firmware_revision': None, + 'friendly_name': '**REDACTED**', + 'language_pack_version': None, 'make_and_model': 'HP OfficeJet Pro 9020 series', 'make_and_model_family': 'HP OfficeJet Pro 9020 series', 'manufactured_at': '2023-03-13T00:00:00', 'manufacturer_name': 'HP', + 'power_save': None, + 'power_save_timeout': None, 'product_number': '226Y0B', 'serial_number': '**REDACTED**', + 'service_id': None, + 'shutdown_delay': None, 'sku_identifier': '9022e', + 'uuid': '**REDACTED**', }), 'eprint': None, 'fax_usage': dict({ @@ -154,6 +185,24 @@ 'images_received_from_pc': None, 'total_impressions': 0, }), + 'genuine_supplies_only': None, + 'io_config': None, + 'logs': dict({ + 'error_log': None, + 'events': list([ + ]), + 'jobs': list([ + dict({ + 'application_id': 'Microsoft Word', + 'color_impressions': None, + 'monochrome_impressions': None, + 'name': '**REDACTED**', + 'submitted_at': None, + 'total_impressions': 3, + 'user_id': '**REDACTED**', + }), + ]), + }), 'online': True, 'printer_usage': dict({ 'color_impressions': 649, @@ -161,9 +210,12 @@ 'jam_events': 2, 'mispick_events': 24, 'monochrome_impressions': 226, + 'original_hp_color_impressions': None, + 'original_hp_monochrome_impressions': None, 'simplex_sheets': 697, 'total_impressions': 875, }), + 'scan_usage': None, 'scanner_usage': dict({ 'adf_images': 2947, 'duplex_sheets': 589, @@ -174,6 +226,7 @@ }), 'status': dict({ 'device_status': 'inpowersave', + 'message': None, }), 'wifi': None, }), diff --git a/tests/components/hp_printer/snapshots/test_sensor.ambr b/tests/components/hp_printer/snapshots/test_sensor.ambr index d3970586a998..de9ef0a8b72f 100644 --- a/tests/components/hp_printer/snapshots/test_sensor.ambr +++ b/tests/components/hp_printer/snapshots/test_sensor.ambr @@ -1030,12 +1030,15 @@ 'capabilities': dict({ : list([ 'cancel_job', + 'close_door_or_cover', 'copying', + 'initializing', 'in_power_save', 'off', 'processing', 'ready', 'scan_processing', + 'shutting_down', 'tray_empty', ]), }), @@ -1076,12 +1079,15 @@ : 'HP OfficeJet Pro 9020 series Status', : list([ 'cancel_job', + 'close_door_or_cover', 'copying', + 'initializing', 'in_power_save', 'off', 'processing', 'ready', 'scan_processing', + 'shutting_down', 'tray_empty', ]), }), diff --git a/tests/components/hp_printer/test_sensor.py b/tests/components/hp_printer/test_sensor.py index 329510d25c0d..431281795e35 100644 --- a/tests/components/hp_printer/test_sensor.py +++ b/tests/components/hp_printer/test_sensor.py @@ -77,6 +77,9 @@ async def test_sensors_added_when_data_appears( "status", [ pytest.param(HpPrinterStatus(device_status="somethingnew"), id="unknown"), + pytest.param( + HpPrinterStatus(device_status="unknown"), id="reported_as_unknown" + ), pytest.param(HpPrinterStatus(device_status=None), id="missing"), pytest.param(None, id="no_status"), ],