diff --git a/homeassistant/components/brother/icons.json b/homeassistant/components/brother/icons.json index f06c3c4994df..b9df702a39ac 100644 --- a/homeassistant/components/brother/icons.json +++ b/homeassistant/components/brother/icons.json @@ -40,6 +40,9 @@ "cyan_toner_remaining": { "default": "mdi:printer-3d-nozzle" }, + "device_status": { + "default": "mdi:printer-check" + }, "drum_page_counter": { "default": "mdi:chart-donut" }, @@ -55,6 +58,9 @@ "fuser_remaining_life": { "default": "mdi:water-outline" }, + "ink_capture_box_remaining_life": { + "default": "mdi:tray-full" + }, "laser_remaining_life": { "default": "mdi:spotlight-beam" }, @@ -82,6 +88,9 @@ "pf_kit_mp_remaining_life": { "default": "mdi:printer-3d" }, + "printer_status": { + "default": "mdi:printer" + }, "status": { "default": "mdi:printer" }, diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index 21e46444c894..dd8c2d2dd75f 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -46,6 +46,26 @@ SENSOR_TYPES: tuple[BrotherSensorEntityDescription, ...] = ( key="status", translation_key="status", value=lambda data: data.status, + entity_registry_enabled_default=False, + ), + BrotherSensorEntityDescription( + key="printer_status", + translation_key="printer_status", + device_class=SensorDeviceClass.ENUM, + options=["idle", "other", "printing", "warmup"], + value=lambda data: ( + None if data.printer_status == "unknown" else data.printer_status + ), + ), + BrotherSensorEntityDescription( + key="device_status", + translation_key="device_status", + device_class=SensorDeviceClass.ENUM, + entity_category=EntityCategory.DIAGNOSTIC, + options=["down", "running", "testing", "warning"], + value=lambda data: ( + None if data.device_status == "unknown" else data.device_status + ), ), BrotherSensorEntityDescription( key="page_counter", @@ -281,6 +301,14 @@ SENSOR_TYPES: tuple[BrotherSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, value=lambda data: data.yellow_ink_remaining, ), + BrotherSensorEntityDescription( + key="ink_capture_box_remaining_life", + translation_key="ink_capture_box_remaining_life", + native_unit_of_measurement=PERCENTAGE, + state_class=SensorStateClass.MEASUREMENT, + entity_category=EntityCategory.DIAGNOSTIC, + value=lambda data: data.ink_capture_box_remaining_life, + ), BrotherSensorEntityDescription( key="uptime", entity_registry_enabled_default=False, diff --git a/homeassistant/components/brother/strings.json b/homeassistant/components/brother/strings.json index f52615d0242f..9fad21a72309 100644 --- a/homeassistant/components/brother/strings.json +++ b/homeassistant/components/brother/strings.json @@ -129,6 +129,15 @@ "cyan_toner_remaining": { "name": "Cyan toner remaining" }, + "device_status": { + "name": "Device status", + "state": { + "down": "Down", + "running": "Running", + "testing": "Testing", + "warning": "Warning" + } + }, "drum_page_counter": { "name": "Drum page counter", "unit_of_measurement": "[%key:component::brother::entity::sensor::page_counter::unit_of_measurement%]" @@ -147,6 +156,9 @@ "fuser_remaining_life": { "name": "Fuser remaining lifetime" }, + "ink_capture_box_remaining_life": { + "name": "Ink capture box remaining lifetime" + }, "laser_remaining_life": { "name": "Laser remaining lifetime" }, @@ -177,6 +189,15 @@ "pf_kit_mp_remaining_life": { "name": "PF Kit MP remaining lifetime" }, + "printer_status": { + "name": "Printer status", + "state": { + "idle": "Idle", + "other": "Other", + "printing": "Printing", + "warmup": "Warming up" + } + }, "status": { "name": "Status" }, diff --git a/tests/components/brother/conftest.py b/tests/components/brother/conftest.py index 9fd226df8a7b..34032462de7e 100644 --- a/tests/components/brother/conftest.py +++ b/tests/components/brother/conftest.py @@ -41,6 +41,7 @@ BROTHER_DATA = BrotherSensors( cyan_toner_remaining=10, cyan_toner_status=1, cyan_toner=10, + device_status="running", drum_counter=986, drum_remaining_life=92, drum_remaining_pages=11014, @@ -49,6 +50,7 @@ BROTHER_DATA = BrotherSensors( fuser_remaining_life=97, fuser_unit_remaining_pages=None, image_counter=None, + ink_capture_box_remaining_life=75, laser_remaining_life=None, laser_unit_remaining_pages=48389, magenta_counter=None, @@ -66,6 +68,8 @@ BROTHER_DATA = BrotherSensors( pf_kit_1_remaining_pages=48741, pf_kit_mp_remaining_life=None, pf_kit_mp_remaining_pages=None, + printer_errors=None, + printer_status="idle", status="waiting", uptime=datetime(2024, 3, 3, 15, 4, 24, tzinfo=UTC), yellow_counter=None, diff --git a/tests/components/brother/snapshots/test_diagnostics.ambr b/tests/components/brother/snapshots/test_diagnostics.ambr index d5b827fd9ee3..78c3a35dbefb 100644 --- a/tests/components/brother/snapshots/test_diagnostics.ambr +++ b/tests/components/brother/snapshots/test_diagnostics.ambr @@ -26,7 +26,7 @@ 'cyan_toner': 10, 'cyan_toner_remaining': 10, 'cyan_toner_status': 1, - 'device_status': None, + 'device_status': 'running', 'drum_counter': 986, 'drum_remaining_life': 92, 'drum_remaining_pages': 11014, @@ -35,7 +35,7 @@ 'fuser_remaining_life': 97, 'fuser_unit_remaining_pages': None, 'image_counter': None, - 'ink_capture_box_remaining_life': None, + 'ink_capture_box_remaining_life': 75, 'laser_remaining_life': None, 'laser_unit_remaining_pages': 48389, 'magenta_counter': None, @@ -54,7 +54,7 @@ 'pf_kit_mp_remaining_life': None, 'pf_kit_mp_remaining_pages': None, 'printer_errors': None, - 'printer_status': None, + 'printer_status': 'idle', 'status': 'waiting', 'uptime': '2024-03-03T15:04:24+00:00', 'yellow_counter': None, diff --git a/tests/components/brother/snapshots/test_sensor.ambr b/tests/components/brother/snapshots/test_sensor.ambr index 877b22fccaa6..6558b0c282e4 100644 --- a/tests/components/brother/snapshots/test_sensor.ambr +++ b/tests/components/brother/snapshots/test_sensor.ambr @@ -593,6 +593,70 @@ 'state': '10', }) # --- +# name: test_sensors[sensor.hl_l2340dw_device_status-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'down', + 'running', + 'testing', + 'warning', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_device_status', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Device status', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Device status', + 'platform': 'brother', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'device_status', + 'unique_id': '0123456789_device_status', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_device_status-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'enum', + : 'HL-L2340DW Device status', + : list([ + 'down', + 'running', + 'testing', + 'warning', + ]), + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_device_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'running', + }) +# --- # name: test_sensors[sensor.hl_l2340dw_drum_page_counter-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ @@ -863,6 +927,60 @@ 'state': '97', }) # --- +# name: test_sensors[sensor.hl_l2340dw_ink_capture_box_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_ink_capture_box_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Ink capture box remaining lifetime', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Ink capture box remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'ink_capture_box_remaining_life', + 'unique_id': '0123456789_ink_capture_box_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_ink_capture_box_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'HL-L2340DW Ink capture box remaining lifetime', + : , + : '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_ink_capture_box_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '75', + }) +# --- # name: test_sensors[sensor.hl_l2340dw_magenta_drum_page_counter-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ @@ -1187,6 +1305,70 @@ 'state': '98', }) # --- +# name: test_sensors[sensor.hl_l2340dw_printer_status-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'idle', + 'other', + 'printing', + 'warmup', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.hl_l2340dw_printer_status', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Printer status', + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Printer status', + 'platform': 'brother', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'printer_status', + 'unique_id': '0123456789_printer_status', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_printer_status-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'enum', + : 'HL-L2340DW Printer status', + : list([ + 'idle', + 'other', + 'printing', + 'warmup', + ]), + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_printer_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'idle', + }) +# --- # name: test_sensors[sensor.hl_l2340dw_status-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/brother/test_sensor.py b/tests/components/brother/test_sensor.py index 28d08cd6b2fb..2e7dcf7cb331 100644 --- a/tests/components/brother/test_sensor.py +++ b/tests/components/brother/test_sensor.py @@ -39,13 +39,13 @@ async def test_availability( mock_config_entry: MockConfigEntry, ) -> None: """Ensure that we mark the entities unavailable correctly when device is offline.""" - entity_id = "sensor.hl_l2340dw_status" + entity_id = "sensor.hl_l2340dw_printer_status" await init_integration(hass, mock_config_entry) state = hass.states.get(entity_id) assert state assert state.state != STATE_UNAVAILABLE - assert state.state == "waiting" + assert state.state == "idle" mock_brother_client.async_update.side_effect = ConnectionError freezer.tick(UPDATE_INTERVAL) @@ -64,7 +64,7 @@ async def test_availability( state = hass.states.get(entity_id) assert state assert state.state != STATE_UNAVAILABLE - assert state.state == "waiting" + assert state.state == "idle" async def test_unique_id_migration(