mirror of
https://github.com/home-assistant/core.git
synced 2026-09-27 01:46:11 -04:00
Add new sensor to the Brother integration (#182799)
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -593,6 +593,70 @@
|
||||
'state': '10',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.hl_l2340dw_device_status-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
<SensorEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'down',
|
||||
'running',
|
||||
'testing',
|
||||
'warning',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.hl_l2340dw_device_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Device status',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||
'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({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'enum',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'HL-L2340DW Device status',
|
||||
<SensorEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'down',
|
||||
'running',
|
||||
'testing',
|
||||
'warning',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hl_l2340dw_device_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'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({
|
||||
<SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.hl_l2340dw_ink_capture_box_remaining_lifetime',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'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({
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'HL-L2340DW Ink capture box remaining lifetime',
|
||||
<SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: '%',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hl_l2340dw_ink_capture_box_remaining_lifetime',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'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({
|
||||
<SensorEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'idle',
|
||||
'other',
|
||||
'printing',
|
||||
'warmup',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'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': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Printer status',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
|
||||
'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({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'enum',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'HL-L2340DW Printer status',
|
||||
<SensorEntityCapabilityAttribute.OPTIONS: 'options'>: list([
|
||||
'idle',
|
||||
'other',
|
||||
'printing',
|
||||
'warmup',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.hl_l2340dw_printer_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'idle',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.hl_l2340dw_status-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user