From c4e7a7af21b761473c1a3d66c2fc30a457df5969 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sat, 20 Apr 2024 12:33:08 +0200 Subject: [PATCH] Use snapshot testing in Brother sensor (#115875) Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com> --- .../brother/snapshots/test_sensor.ambr | 1394 +++++++++++++++++ tests/components/brother/test_sensor.py | 395 +---- 2 files changed, 1420 insertions(+), 369 deletions(-) create mode 100644 tests/components/brother/snapshots/test_sensor.ambr diff --git a/tests/components/brother/snapshots/test_sensor.ambr b/tests/components/brother/snapshots/test_sensor.ambr new file mode 100644 index 00000000000..a27c5addd61 --- /dev/null +++ b/tests/components/brother/snapshots/test_sensor.ambr @@ -0,0 +1,1394 @@ +# serializer version: 1 +# name: test_sensors[sensor.hl_l2340dw_b_w_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_b_w_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'B/W pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'bw_pages', + 'unique_id': '0123456789_bw_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_b_w_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW B/W pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_b_w_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '709', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_belt_unit_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_belt_unit_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Belt unit remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'belt_unit_remaining_life', + 'unique_id': '0123456789_belt_unit_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_belt_unit_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Belt unit remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_belt_unit_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '97', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Black drum page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'black_drum_page_counter', + 'unique_id': '0123456789_black_drum_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Black drum page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1611', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Black drum remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'black_drum_remaining_life', + 'unique_id': '0123456789_black_drum_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Black drum remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '92', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_remaining_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_remaining_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Black drum remaining pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'black_drum_remaining_pages', + 'unique_id': '0123456789_black_drum_remaining_pages', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_drum_remaining_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Black drum remaining pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_black_drum_remaining_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '16389', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_toner_remaining-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_black_toner_remaining', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Black toner remaining', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'black_toner_remaining', + 'unique_id': '0123456789_black_toner_remaining', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_black_toner_remaining-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Black toner remaining', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_black_toner_remaining', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '75', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_color_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_color_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Color pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'color_pages', + 'unique_id': '0123456789_color_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_color_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Color pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_color_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '902', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Cyan drum page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cyan_drum_page_counter', + 'unique_id': '0123456789_cyan_drum_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Cyan drum page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1611', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Cyan drum remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cyan_drum_remaining_life', + 'unique_id': '0123456789_cyan_drum_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Cyan drum remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '92', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_remaining_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_remaining_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Cyan drum remaining pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cyan_drum_remaining_pages', + 'unique_id': '0123456789_cyan_drum_remaining_pages', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_drum_remaining_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Cyan drum remaining pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_cyan_drum_remaining_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '16389', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_toner_remaining-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_cyan_toner_remaining', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Cyan toner remaining', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'cyan_toner_remaining', + 'unique_id': '0123456789_cyan_toner_remaining', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_cyan_toner_remaining-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Cyan toner remaining', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_cyan_toner_remaining', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '10', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_drum_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Drum page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'drum_page_counter', + 'unique_id': '0123456789_drum_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Drum page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_drum_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '986', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_drum_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Drum remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'drum_remaining_life', + 'unique_id': '0123456789_drum_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Drum remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_drum_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '92', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_remaining_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_drum_remaining_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Drum remaining pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'drum_remaining_pages', + 'unique_id': '0123456789_drum_remaining_pages', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_drum_remaining_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Drum remaining pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_drum_remaining_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '11014', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_duplex_unit_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_duplex_unit_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Duplex unit page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'duplex_unit_page_counter', + 'unique_id': '0123456789_duplex_unit_pages_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_duplex_unit_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Duplex unit page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_duplex_unit_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '538', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_fuser_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_fuser_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Fuser remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'fuser_remaining_life', + 'unique_id': '0123456789_fuser_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_fuser_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Fuser remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_fuser_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '97', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_last_restart-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_last_restart', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Last restart', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'last_restart', + 'unique_id': '0123456789_uptime', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_last_restart-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'timestamp', + 'friendly_name': 'HL-L2340DW Last restart', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_last_restart', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2024-03-03T15:04:24+00:00', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Magenta drum page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'magenta_drum_page_counter', + 'unique_id': '0123456789_magenta_drum_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Magenta drum page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1611', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Magenta drum remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'magenta_drum_remaining_life', + 'unique_id': '0123456789_magenta_drum_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Magenta drum remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '92', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_remaining_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_remaining_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Magenta drum remaining pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'magenta_drum_remaining_pages', + 'unique_id': '0123456789_magenta_drum_remaining_pages', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_drum_remaining_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Magenta drum remaining pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_magenta_drum_remaining_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '16389', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_toner_remaining-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_magenta_toner_remaining', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Magenta toner remaining', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'magenta_toner_remaining', + 'unique_id': '0123456789_magenta_toner_remaining', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_magenta_toner_remaining-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Magenta toner remaining', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_magenta_toner_remaining', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '8', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'page_counter', + 'unique_id': '0123456789_page_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '986', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_pf_kit_1_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_pf_kit_1_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'PF Kit 1 remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'pf_kit_1_remaining_life', + 'unique_id': '0123456789_pf_kit_1_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_pf_kit_1_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW PF Kit 1 remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_pf_kit_1_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '98', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_status-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_status', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Status', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'status', + 'unique_id': '0123456789_status', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_status-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Status', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'waiting', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_page_counter-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_page_counter', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Yellow drum page counter', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'yellow_drum_page_counter', + 'unique_id': '0123456789_yellow_drum_counter', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_page_counter-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Yellow drum page counter', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_page_counter', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1611', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_remaining_lifetime-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_remaining_lifetime', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Yellow drum remaining lifetime', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'yellow_drum_remaining_life', + 'unique_id': '0123456789_yellow_drum_remaining_life', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_remaining_lifetime-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Yellow drum remaining lifetime', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_remaining_lifetime', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '92', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_remaining_pages-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_remaining_pages', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Yellow drum remaining pages', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'yellow_drum_remaining_pages', + 'unique_id': '0123456789_yellow_drum_remaining_pages', + 'unit_of_measurement': 'p', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_drum_remaining_pages-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Yellow drum remaining pages', + 'state_class': , + 'unit_of_measurement': 'p', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_yellow_drum_remaining_pages', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '16389', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_toner_remaining-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.hl_l2340dw_yellow_toner_remaining', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Yellow toner remaining', + 'platform': 'brother', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'yellow_toner_remaining', + 'unique_id': '0123456789_yellow_toner_remaining', + 'unit_of_measurement': '%', + }) +# --- +# name: test_sensors[sensor.hl_l2340dw_yellow_toner_remaining-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'HL-L2340DW Yellow toner remaining', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.hl_l2340dw_yellow_toner_remaining', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2', + }) +# --- diff --git a/tests/components/brother/test_sensor.py b/tests/components/brother/test_sensor.py index ff29f8cb368..39aa3b83d6f 100644 --- a/tests/components/brother/test_sensor.py +++ b/tests/components/brother/test_sensor.py @@ -1,389 +1,46 @@ """Test sensor of Brother integration.""" -from datetime import datetime, timedelta +from datetime import timedelta import json -from unittest.mock import Mock, patch +from unittest.mock import patch + +from freezegun.api import FrozenDateTimeFactory +from syrupy import SnapshotAssertion from homeassistant.components.brother.const import DOMAIN -from homeassistant.components.brother.sensor import UNIT_PAGES -from homeassistant.components.sensor import ( - ATTR_STATE_CLASS, - DOMAIN as SENSOR_DOMAIN, - SensorDeviceClass, - SensorStateClass, -) -from homeassistant.const import ( - ATTR_DEVICE_CLASS, - ATTR_ENTITY_ID, - ATTR_ICON, - ATTR_UNIT_OF_MEASUREMENT, - PERCENTAGE, - STATE_UNAVAILABLE, -) +from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component -from homeassistant.util.dt import UTC, utcnow +from homeassistant.util.dt import utcnow from . import init_integration from tests.common import async_fire_time_changed, load_fixture -ATTR_REMAINING_PAGES = "remaining_pages" -ATTR_COUNTER = "counter" - -async def test_sensors(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None: - """Test states of the sensors.""" - entry = await init_integration(hass, skip_setup=True) - - # Pre-create registry entries for disabled by default sensors - entity_registry.async_get_or_create( - SENSOR_DOMAIN, - DOMAIN, - "0123456789_uptime", - suggested_object_id="hl_l2340dw_last_restart", - disabled_by=None, - ) - test_time = datetime(2019, 11, 11, 9, 10, 32, tzinfo=UTC) - with ( - patch("brother.Brother.initialize"), - patch("brother.datetime", now=Mock(return_value=test_time)), - patch( - "brother.Brother._get_data", - return_value=json.loads(load_fixture("printer_data.json", "brother")), - ), - ): - await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - - state = hass.states.get("sensor.hl_l2340dw_status") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.state == "waiting" - assert state.attributes.get(ATTR_STATE_CLASS) is None - - entry = entity_registry.async_get("sensor.hl_l2340dw_status") - assert entry - assert entry.unique_id == "0123456789_status" - - state = hass.states.get("sensor.hl_l2340dw_black_toner_remaining") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "75" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_black_toner_remaining") - assert entry - assert entry.unique_id == "0123456789_black_toner_remaining" - - state = hass.states.get("sensor.hl_l2340dw_cyan_toner_remaining") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "10" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_toner_remaining") - assert entry - assert entry.unique_id == "0123456789_cyan_toner_remaining" - - state = hass.states.get("sensor.hl_l2340dw_magenta_toner_remaining") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "8" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_toner_remaining") - assert entry - assert entry.unique_id == "0123456789_magenta_toner_remaining" - - state = hass.states.get("sensor.hl_l2340dw_yellow_toner_remaining") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "2" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_toner_remaining") - assert entry - assert entry.unique_id == "0123456789_yellow_toner_remaining" - - state = hass.states.get("sensor.hl_l2340dw_drum_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "92" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_drum_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_drum_remaining_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "11014" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_drum_remaining_pages") - assert entry - assert entry.unique_id == "0123456789_drum_remaining_pages" - - state = hass.states.get("sensor.hl_l2340dw_drum_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "986" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_drum_page_counter") - assert entry - assert entry.unique_id == "0123456789_drum_counter" - - state = hass.states.get("sensor.hl_l2340dw_black_drum_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "92" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_black_drum_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_black_drum_remaining_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "16389" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_remaining_pages") - assert entry - assert entry.unique_id == "0123456789_black_drum_remaining_pages" - - state = hass.states.get("sensor.hl_l2340dw_black_drum_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "1611" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_black_drum_page_counter") - assert entry - assert entry.unique_id == "0123456789_black_drum_counter" - - state = hass.states.get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "92" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_cyan_drum_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_cyan_drum_remaining_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "16389" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_remaining_pages") - assert entry - assert entry.unique_id == "0123456789_cyan_drum_remaining_pages" - - state = hass.states.get("sensor.hl_l2340dw_cyan_drum_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "1611" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_cyan_drum_page_counter") - assert entry - assert entry.unique_id == "0123456789_cyan_drum_counter" - - state = hass.states.get("sensor.hl_l2340dw_magenta_drum_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "92" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get( - "sensor.hl_l2340dw_magenta_drum_remaining_lifetime" - ) - assert entry - assert entry.unique_id == "0123456789_magenta_drum_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_magenta_drum_remaining_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "16389" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_remaining_pages") - assert entry - assert entry.unique_id == "0123456789_magenta_drum_remaining_pages" - - state = hass.states.get("sensor.hl_l2340dw_magenta_drum_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "1611" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_magenta_drum_page_counter") - assert entry - assert entry.unique_id == "0123456789_magenta_drum_counter" - - state = hass.states.get("sensor.hl_l2340dw_yellow_drum_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "92" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get( - "sensor.hl_l2340dw_yellow_drum_remaining_lifetime" - ) - assert entry - assert entry.unique_id == "0123456789_yellow_drum_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_yellow_drum_remaining_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "16389" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_remaining_pages") - assert entry - assert entry.unique_id == "0123456789_yellow_drum_remaining_pages" - - state = hass.states.get("sensor.hl_l2340dw_yellow_drum_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "1611" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_yellow_drum_page_counter") - assert entry - assert entry.unique_id == "0123456789_yellow_drum_counter" - - state = hass.states.get("sensor.hl_l2340dw_fuser_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "97" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_fuser_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_fuser_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_belt_unit_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "97" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_belt_unit_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_belt_unit_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE - assert state.state == "98" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_pf_kit_1_remaining_lifetime") - assert entry - assert entry.unique_id == "0123456789_pf_kit_1_remaining_life" - - state = hass.states.get("sensor.hl_l2340dw_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "986" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_page_counter") - assert entry - assert entry.unique_id == "0123456789_page_counter" - - state = hass.states.get("sensor.hl_l2340dw_duplex_unit_page_counter") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "538" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_duplex_unit_page_counter") - assert entry - assert entry.unique_id == "0123456789_duplex_unit_pages_counter" - - state = hass.states.get("sensor.hl_l2340dw_b_w_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "709" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_b_w_pages") - assert entry - assert entry.unique_id == "0123456789_bw_counter" - - state = hass.states.get("sensor.hl_l2340dw_color_pages") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UNIT_PAGES - assert state.state == "902" - assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT - - entry = entity_registry.async_get("sensor.hl_l2340dw_color_pages") - assert entry - assert entry.unique_id == "0123456789_color_counter" - - state = hass.states.get("sensor.hl_l2340dw_last_restart") - assert state - assert state.attributes.get(ATTR_ICON) is None - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None - assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP - assert state.state == "2019-09-24T12:14:56+00:00" - assert state.attributes.get(ATTR_STATE_CLASS) is None - - entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart") - assert entry - assert entry.unique_id == "0123456789_uptime" - - -async def test_disabled_by_default_sensors( - hass: HomeAssistant, entity_registry: er.EntityRegistry +async def test_sensors( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + entity_registry_enabled_by_default: None, + snapshot: SnapshotAssertion, + freezer: FrozenDateTimeFactory, ) -> None: - """Test the disabled by default Brother sensors.""" - await init_integration(hass) + """Test states of the sensors.""" + hass.config.set_time_zone("UTC") + freezer.move_to("2024-04-20 12:00:00+00:00") - state = hass.states.get("sensor.hl_l2340dw_last_restart") - assert state is None + with patch("homeassistant.components.brother.PLATFORMS", [Platform.SENSOR]): + entry = await init_integration(hass) - entry = entity_registry.async_get("sensor.hl_l2340dw_last_restart") - assert entry - assert entry.unique_id == "0123456789_uptime" - assert entry.disabled - assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION + entity_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id) + + assert entity_entries + for entity_entry in entity_entries: + assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry") + assert (state := hass.states.get(entity_entry.entity_id)) + assert state == snapshot(name=f"{entity_entry.entity_id}-state") async def test_availability(hass: HomeAssistant) -> None: