From 5eb4cf6a0569cde13888c11f79f372f88cb6358f Mon Sep 17 00:00:00 2001 From: Thomas55555 <59625598+Thomas55555@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:06:30 +0200 Subject: [PATCH] Add error sensor for Husqvarna Automower (#113165) * Add error sensor for Husqvarna Automower * Apply suggestions from code review Co-authored-by: Jan-Philipp Benecke * address review * Add restricted reason sensor * ruff * pin options --------- Co-authored-by: Jan-Philipp Benecke --- .../components/husqvarna_automower/icons.json | 6 + .../components/husqvarna_automower/sensor.py | 177 +++++++- .../husqvarna_automower/strings.json | 143 ++++++ .../snapshots/test_sensor.ambr | 410 ++++++++++++++++++ .../husqvarna_automower/test_sensor.py | 25 ++ 5 files changed, 760 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/husqvarna_automower/icons.json b/homeassistant/components/husqvarna_automower/icons.json index 65cc85bd09b..ec11ef92d08 100644 --- a/homeassistant/components/husqvarna_automower/icons.json +++ b/homeassistant/components/husqvarna_automower/icons.json @@ -14,11 +14,17 @@ } }, "sensor": { + "error": { + "default": "mdi:alert-circle-outline" + }, "number_of_charging_cycles": { "default": "mdi:battery-sync-outline" }, "number_of_collisions": { "default": "mdi:counter" + }, + "restricted_reason": { + "default": "mdi:tooltip-question" } } } diff --git a/homeassistant/components/husqvarna_automower/sensor.py b/homeassistant/components/husqvarna_automower/sensor.py index e054d02e3ba..10aec9b1536 100644 --- a/homeassistant/components/husqvarna_automower/sensor.py +++ b/homeassistant/components/husqvarna_automower/sensor.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from datetime import datetime import logging -from aioautomower.model import MowerAttributes, MowerModes +from aioautomower.model import MowerAttributes, MowerModes, RestrictedReasons from homeassistant.components.sensor import ( SensorDeviceClass, @@ -26,6 +26,165 @@ from .entity import AutomowerBaseEntity _LOGGER = logging.getLogger(__name__) +ERROR_KEY_LIST = [ + "no_error", + "alarm_mower_in_motion", + "alarm_mower_lifted", + "alarm_mower_stopped", + "alarm_mower_switched_off", + "alarm_mower_tilted", + "alarm_outside_geofence", + "angular_sensor_problem", + "battery_problem", + "battery_problem", + "battery_restriction_due_to_ambient_temperature", + "can_error", + "charging_current_too_high", + "charging_station_blocked", + "charging_system_problem", + "charging_system_problem", + "collision_sensor_defect", + "collision_sensor_error", + "collision_sensor_problem_front", + "collision_sensor_problem_rear", + "com_board_not_available", + "communication_circuit_board_sw_must_be_updated", + "complex_working_area", + "connection_changed", + "connection_not_changed", + "connectivity_problem", + "connectivity_problem", + "connectivity_problem", + "connectivity_problem", + "connectivity_problem", + "connectivity_problem", + "connectivity_settings_restored", + "cutting_drive_motor_1_defect", + "cutting_drive_motor_2_defect", + "cutting_drive_motor_3_defect", + "cutting_height_blocked", + "cutting_height_problem", + "cutting_height_problem_curr", + "cutting_height_problem_dir", + "cutting_height_problem_drive", + "cutting_motor_problem", + "cutting_stopped_slope_too_steep", + "cutting_system_blocked", + "cutting_system_blocked", + "cutting_system_imbalance_warning", + "cutting_system_major_imbalance", + "destination_not_reachable", + "difficult_finding_home", + "docking_sensor_defect", + "electronic_problem", + "empty_battery", + "folding_cutting_deck_sensor_defect", + "folding_sensor_activated", + "geofence_problem", + "geofence_problem", + "gps_navigation_problem", + "guide_1_not_found", + "guide_2_not_found", + "guide_3_not_found", + "guide_calibration_accomplished", + "guide_calibration_failed", + "high_charging_power_loss", + "high_internal_power_loss", + "high_internal_temperature", + "internal_voltage_error", + "invalid_battery_combination_invalid_combination_of_different_battery_types", + "invalid_sub_device_combination", + "invalid_system_configuration", + "left_brush_motor_overloaded", + "lift_sensor_defect", + "lifted", + "limited_cutting_height_range", + "limited_cutting_height_range", + "loop_sensor_defect", + "loop_sensor_problem_front", + "loop_sensor_problem_left", + "loop_sensor_problem_rear", + "loop_sensor_problem_right", + "low_battery", + "memory_circuit_problem", + "mower_lifted", + "mower_tilted", + "no_accurate_position_from_satellites", + "no_confirmed_position", + "no_drive", + "no_loop_signal", + "no_power_in_charging_station", + "no_response_from_charger", + "outside_working_area", + "poor_signal_quality", + "reference_station_communication_problem", + "right_brush_motor_overloaded", + "safety_function_faulty", + "settings_restored", + "sim_card_locked", + "sim_card_locked", + "sim_card_locked", + "sim_card_locked", + "sim_card_not_found", + "sim_card_requires_pin", + "slipped_mower_has_slipped_situation_not_solved_with_moving_pattern", + "slope_too_steep", + "sms_could_not_be_sent", + "stop_button_problem", + "stuck_in_charging_station", + "switch_cord_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "temporary_battery_problem", + "tilt_sensor_problem", + "too_high_discharge_current", + "too_high_internal_current", + "trapped", + "ultrasonic_problem", + "ultrasonic_sensor_1_defect", + "ultrasonic_sensor_2_defect", + "ultrasonic_sensor_3_defect", + "ultrasonic_sensor_4_defect", + "unexpected_cutting_height_adj", + "unexpected_error", + "upside_down", + "weak_gps_signal", + "wheel_drive_problem_left", + "wheel_drive_problem_rear_left", + "wheel_drive_problem_rear_right", + "wheel_drive_problem_right", + "wheel_motor_blocked_left", + "wheel_motor_blocked_rear_left", + "wheel_motor_blocked_rear_right", + "wheel_motor_blocked_right", + "wheel_motor_overloaded_left", + "wheel_motor_overloaded_rear_left", + "wheel_motor_overloaded_rear_right", + "wheel_motor_overloaded_right", + "work_area_not_valid", + "wrong_loop_signal", + "wrong_pin_code", + "zone_generator_problem", +] + +RESTRICTED_REASONS: list = [ + RestrictedReasons.ALL_WORK_AREAS_COMPLETED.lower(), + RestrictedReasons.DAILY_LIMIT.lower(), + RestrictedReasons.EXTERNAL.lower(), + RestrictedReasons.FOTA.lower(), + RestrictedReasons.FROST.lower(), + RestrictedReasons.NONE.lower(), + RestrictedReasons.NOT_APPLICABLE.lower(), + RestrictedReasons.PARK_OVERRIDE.lower(), + RestrictedReasons.SENSOR.lower(), + RestrictedReasons.WEEK_SCHEDULE.lower(), +] + @dataclass(frozen=True, kw_only=True) class AutomowerSensorEntityDescription(SensorEntityDescription): @@ -141,6 +300,22 @@ SENSOR_TYPES: tuple[AutomowerSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.TIMESTAMP, value_fn=lambda data: dt_util.as_local(data.planner.next_start_datetime), ), + AutomowerSensorEntityDescription( + key="error", + translation_key="error", + device_class=SensorDeviceClass.ENUM, + value_fn=lambda data: ( + "no_error" if data.mower.error_key is None else data.mower.error_key + ), + options=ERROR_KEY_LIST, + ), + AutomowerSensorEntityDescription( + key="restricted_reason", + translation_key="restricted_reason", + device_class=SensorDeviceClass.ENUM, + options=RESTRICTED_REASONS, + value_fn=lambda data: data.planner.restricted_reason.lower(), + ), ) diff --git a/homeassistant/components/husqvarna_automower/strings.json b/homeassistant/components/husqvarna_automower/strings.json index 8032c670404..0a2d3685c6e 100644 --- a/homeassistant/components/husqvarna_automower/strings.json +++ b/homeassistant/components/husqvarna_automower/strings.json @@ -49,6 +49,134 @@ } }, "sensor": { + "error": { + "name": "Error", + "state": { + "alarm_mower_in_motion": "Alarm! Mower in motion", + "alarm_mower_lifted": "Alarm! Mower lifted", + "alarm_mower_stopped": "Alarm! Mower stopped", + "alarm_mower_switched_off": "Alarm! Mower switched off", + "alarm_mower_tilted": "Alarm! Mower tilted", + "alarm_outside_geofence": "Alarm! Outside geofence", + "angular_sensor_problem": "Angular sensor problem", + "battery_problem": "Battery problem", + "battery_restriction_due_to_ambient_temperature": "Battery restriction due to ambient temperature", + "can_error": "CAN error", + "charging_current_too_high": "Charging current too high", + "charging_station_blocked": "Charging station blocked", + "charging_system_problem": "Charging system problem", + "collision_sensor_defect": "Collision sensor defect", + "collision_sensor_error": "Collision sensor error", + "collision_sensor_problem_front": "Front collision sensor problem", + "collision_sensor_problem_rear": "Rear collision sensor problem", + "com_board_not_available": "Com board not available", + "communication_circuit_board_sw_must_be_updated": "Communication circuit board software must be updated", + "complex_working_area": "Complex working area", + "connection_changed": "Connection changed", + "connection_not_changed": "Connection NOT changed", + "connectivity_problem": "Connectivity problem", + "connectivity_settings_restored": "Connectivity settings restored", + "cutting_drive_motor_1_defect": "Cutting drive motor 1 defect", + "cutting_drive_motor_2_defect": "Cutting drive motor 2 defect", + "cutting_drive_motor_3_defect": "Cutting drive motor 3 defect", + "cutting_height_blocked": "Cutting height blocked", + "cutting_height_problem": "Cutting height problem", + "cutting_height_problem_curr": "Cutting height problem, curr", + "cutting_height_problem_dir": "Cutting height problem, dir", + "cutting_height_problem_drive": "Cutting height problem, drive", + "cutting_motor_problem": "Cutting motor problem", + "cutting_stopped_slope_too_steep": "Cutting stopped - slope too steep", + "cutting_system_blocked": "Cutting system blocked", + "cutting_system_imbalance_warning": "Cutting system imbalance", + "cutting_system_major_imbalance": "Cutting system major imbalance", + "destination_not_reachable": "Destination not reachable", + "difficult_finding_home": "Difficult finding home", + "docking_sensor_defect": "Docking sensor defect", + "electronic_problem": "Electronic problem", + "empty_battery": "Empty battery", + "folding_cutting_deck_sensor_defect": "Folding cutting deck sensor defect", + "folding_sensor_activated": "Folding sensor activated", + "geofence_problem": "Geofence problem", + "gps_navigation_problem": "GPS navigation problem", + "guide_1_not_found": "Guide 1 not found", + "guide_2_not_found": "Guide 2 not found", + "guide_3_not_found": "Guide 3 not found", + "guide_calibration_accomplished": "Guide calibration accomplished", + "guide_calibration_failed": "Guide calibration failed", + "high_charging_power_loss": "High charging power loss", + "high_internal_power_loss": "High internal power loss", + "high_internal_temperature": "High internal temperature", + "internal_voltage_error": "Internal voltage error", + "invalid_battery_combination_invalid_combination_of_different_battery_types": "Invalid battery combination - Invalid combination of different battery types.", + "invalid_sub_device_combination": "Invalid sub-device combination", + "invalid_system_configuration": "Invalid system configuration", + "left_brush_motor_overloaded": "Left brush motor overloaded", + "lift_sensor_defect": "Lift Sensor defect", + "lifted": "Lifted", + "limited_cutting_height_range": "Limited cutting height range", + "loop_sensor_defect": "Loop sensor defect", + "loop_sensor_problem_front": "Front loop sensor problem", + "loop_sensor_problem_left": "Left loop sensor problem", + "loop_sensor_problem_rear": "Rear loop sensor problem", + "loop_sensor_problem_right": "Right loop sensor problem", + "low_battery": "Low battery", + "memory_circuit_problem": "Memory circuit problem", + "mower_lifted": "Mower lifted", + "mower_tilted": "Mower tilted", + "no_accurate_position_from_satellites": "No accurate position from satellites", + "no_confirmed_position": "No confirmed position", + "no_drive": "No drive", + "no_error": "No error", + "no_loop_signal": "No loop signal", + "no_power_in_charging_station": "No power in charging station", + "no_response_from_charger": "No response from charger", + "outside_working_area": "Outside working area", + "poor_signal_quality": "Poor signal quality", + "reference_station_communication_problem": "Reference station communication problem", + "right_brush_motor_overloaded": "Right brush motor overloaded", + "safety_function_faulty": "Safety function faulty", + "settings_restored": "Settings restored", + "sim_card_locked": "SIM card locked", + "sim_card_not_found": "SIM card not found", + "sim_card_requires_pin": "SIM card requires PIN", + "slipped_mower_has_slipped_situation_not_solved_with_moving_pattern": "Slipped - Mower has Slipped. Situation not solved with moving pattern", + "slope_too_steep": "Slope too steep", + "sms_could_not_be_sent": "SMS could not be sent", + "stop_button_problem": "STOP button problem", + "stuck_in_charging_station": "Stuck in charging station", + "switch_cord_problem": "Switch cord problem", + "temporary_battery_problem": "Temporary battery problem", + "tilt_sensor_problem": "Tilt sensor problem", + "too_high_discharge_current": "Discharge current too high", + "too_high_internal_current": "Internal current too high", + "trapped": "Trapped", + "ultrasonic_problem": "Ultrasonic problem", + "ultrasonic_sensor_1_defect": "Ultrasonic Sensor 1 defect", + "ultrasonic_sensor_2_defect": "Ultrasonic Sensor 2 defect", + "ultrasonic_sensor_3_defect": "Ultrasonic Sensor 3 defect", + "ultrasonic_sensor_4_defect": "Ultrasonic Sensor 4 defect", + "unexpected_cutting_height_adj": "Unexpected cutting height adjustment", + "unexpected_error": "Unexpected error", + "upside_down": "Upside down", + "weak_gps_signal": "Weak GPS signal", + "wheel_drive_problem_left": "Left wheel drive problem", + "wheel_drive_problem_rear_left": "Rear left wheel drive problem", + "wheel_drive_problem_rear_right": "Rear right wheel drive problem", + "wheel_drive_problem_right": "Right wheel drive problem", + "wheel_motor_blocked_left": "Left wheel motor blocked", + "wheel_motor_blocked_rear_left": "Rear left wheel motor blocked", + "wheel_motor_blocked_rear_right": "Rear right wheel motor blocked", + "wheel_motor_blocked_right": "Right wheel motor blocked", + "wheel_motor_overloaded_left": "Left wheel motor overloaded", + "wheel_motor_overloaded_rear_left": "Rear left wheel motor overloaded", + "wheel_motor_overloaded_rear_right": "Rear right wheel motor overloaded", + "wheel_motor_overloaded_right": "Right wheel motor overloaded", + "work_area_not_valid": "Work area not valid", + "wrong_loop_signal": "Wrong loop signal", + "wrong_pin_code": "Wrong PIN code", + "zone_generator_problem": "Zone generator problem" + } + }, "number_of_charging_cycles": { "name": "Number of charging cycles" }, @@ -58,6 +186,21 @@ "cutting_blade_usage_time": { "name": "Cutting blade usage time" }, + "restricted_reason": { + "name": "Restricted reason", + "state": { + "none": "No restrictions", + "week_schedule": "Week schedule", + "park_override": "Park override", + "sensor": "Weather timer", + "daily_limit": "Daily limit", + "fota": "Firmware Over-the-Air update running", + "frost": "Frost", + "all_work_areas_completed": "All work areas completed", + "external": "External", + "not_applicable": "Not applicable" + } + }, "total_charging_time": { "name": "Total charging time" }, diff --git a/tests/components/husqvarna_automower/snapshots/test_sensor.ambr b/tests/components/husqvarna_automower/snapshots/test_sensor.ambr index ce81098f753..fda9c900240 100644 --- a/tests/components/husqvarna_automower/snapshots/test_sensor.ambr +++ b/tests/components/husqvarna_automower/snapshots/test_sensor.ambr @@ -104,6 +104,344 @@ 'state': '0.034', }) # --- +# name: test_sensor[sensor.test_mower_1_error-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'no_error', + 'alarm_mower_in_motion', + 'alarm_mower_lifted', + 'alarm_mower_stopped', + 'alarm_mower_switched_off', + 'alarm_mower_tilted', + 'alarm_outside_geofence', + 'angular_sensor_problem', + 'battery_problem', + 'battery_problem', + 'battery_restriction_due_to_ambient_temperature', + 'can_error', + 'charging_current_too_high', + 'charging_station_blocked', + 'charging_system_problem', + 'charging_system_problem', + 'collision_sensor_defect', + 'collision_sensor_error', + 'collision_sensor_problem_front', + 'collision_sensor_problem_rear', + 'com_board_not_available', + 'communication_circuit_board_sw_must_be_updated', + 'complex_working_area', + 'connection_changed', + 'connection_not_changed', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_settings_restored', + 'cutting_drive_motor_1_defect', + 'cutting_drive_motor_2_defect', + 'cutting_drive_motor_3_defect', + 'cutting_height_blocked', + 'cutting_height_problem', + 'cutting_height_problem_curr', + 'cutting_height_problem_dir', + 'cutting_height_problem_drive', + 'cutting_motor_problem', + 'cutting_stopped_slope_too_steep', + 'cutting_system_blocked', + 'cutting_system_blocked', + 'cutting_system_imbalance_warning', + 'cutting_system_major_imbalance', + 'destination_not_reachable', + 'difficult_finding_home', + 'docking_sensor_defect', + 'electronic_problem', + 'empty_battery', + 'folding_cutting_deck_sensor_defect', + 'folding_sensor_activated', + 'geofence_problem', + 'geofence_problem', + 'gps_navigation_problem', + 'guide_1_not_found', + 'guide_2_not_found', + 'guide_3_not_found', + 'guide_calibration_accomplished', + 'guide_calibration_failed', + 'high_charging_power_loss', + 'high_internal_power_loss', + 'high_internal_temperature', + 'internal_voltage_error', + 'invalid_battery_combination_invalid_combination_of_different_battery_types', + 'invalid_sub_device_combination', + 'invalid_system_configuration', + 'left_brush_motor_overloaded', + 'lift_sensor_defect', + 'lifted', + 'limited_cutting_height_range', + 'limited_cutting_height_range', + 'loop_sensor_defect', + 'loop_sensor_problem_front', + 'loop_sensor_problem_left', + 'loop_sensor_problem_rear', + 'loop_sensor_problem_right', + 'low_battery', + 'memory_circuit_problem', + 'mower_lifted', + 'mower_tilted', + 'no_accurate_position_from_satellites', + 'no_confirmed_position', + 'no_drive', + 'no_loop_signal', + 'no_power_in_charging_station', + 'no_response_from_charger', + 'outside_working_area', + 'poor_signal_quality', + 'reference_station_communication_problem', + 'right_brush_motor_overloaded', + 'safety_function_faulty', + 'settings_restored', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_not_found', + 'sim_card_requires_pin', + 'slipped_mower_has_slipped_situation_not_solved_with_moving_pattern', + 'slope_too_steep', + 'sms_could_not_be_sent', + 'stop_button_problem', + 'stuck_in_charging_station', + 'switch_cord_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'tilt_sensor_problem', + 'too_high_discharge_current', + 'too_high_internal_current', + 'trapped', + 'ultrasonic_problem', + 'ultrasonic_sensor_1_defect', + 'ultrasonic_sensor_2_defect', + 'ultrasonic_sensor_3_defect', + 'ultrasonic_sensor_4_defect', + 'unexpected_cutting_height_adj', + 'unexpected_error', + 'upside_down', + 'weak_gps_signal', + 'wheel_drive_problem_left', + 'wheel_drive_problem_rear_left', + 'wheel_drive_problem_rear_right', + 'wheel_drive_problem_right', + 'wheel_motor_blocked_left', + 'wheel_motor_blocked_rear_left', + 'wheel_motor_blocked_rear_right', + 'wheel_motor_blocked_right', + 'wheel_motor_overloaded_left', + 'wheel_motor_overloaded_rear_left', + 'wheel_motor_overloaded_rear_right', + 'wheel_motor_overloaded_right', + 'work_area_not_valid', + 'wrong_loop_signal', + 'wrong_pin_code', + 'zone_generator_problem', + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_mower_1_error', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Error', + 'platform': 'husqvarna_automower', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'error', + 'unique_id': 'c7233734-b219-4287-a173-08e3643f89f0_error', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensor[sensor.test_mower_1_error-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'Test Mower 1 Error', + 'options': list([ + 'no_error', + 'alarm_mower_in_motion', + 'alarm_mower_lifted', + 'alarm_mower_stopped', + 'alarm_mower_switched_off', + 'alarm_mower_tilted', + 'alarm_outside_geofence', + 'angular_sensor_problem', + 'battery_problem', + 'battery_problem', + 'battery_restriction_due_to_ambient_temperature', + 'can_error', + 'charging_current_too_high', + 'charging_station_blocked', + 'charging_system_problem', + 'charging_system_problem', + 'collision_sensor_defect', + 'collision_sensor_error', + 'collision_sensor_problem_front', + 'collision_sensor_problem_rear', + 'com_board_not_available', + 'communication_circuit_board_sw_must_be_updated', + 'complex_working_area', + 'connection_changed', + 'connection_not_changed', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_problem', + 'connectivity_settings_restored', + 'cutting_drive_motor_1_defect', + 'cutting_drive_motor_2_defect', + 'cutting_drive_motor_3_defect', + 'cutting_height_blocked', + 'cutting_height_problem', + 'cutting_height_problem_curr', + 'cutting_height_problem_dir', + 'cutting_height_problem_drive', + 'cutting_motor_problem', + 'cutting_stopped_slope_too_steep', + 'cutting_system_blocked', + 'cutting_system_blocked', + 'cutting_system_imbalance_warning', + 'cutting_system_major_imbalance', + 'destination_not_reachable', + 'difficult_finding_home', + 'docking_sensor_defect', + 'electronic_problem', + 'empty_battery', + 'folding_cutting_deck_sensor_defect', + 'folding_sensor_activated', + 'geofence_problem', + 'geofence_problem', + 'gps_navigation_problem', + 'guide_1_not_found', + 'guide_2_not_found', + 'guide_3_not_found', + 'guide_calibration_accomplished', + 'guide_calibration_failed', + 'high_charging_power_loss', + 'high_internal_power_loss', + 'high_internal_temperature', + 'internal_voltage_error', + 'invalid_battery_combination_invalid_combination_of_different_battery_types', + 'invalid_sub_device_combination', + 'invalid_system_configuration', + 'left_brush_motor_overloaded', + 'lift_sensor_defect', + 'lifted', + 'limited_cutting_height_range', + 'limited_cutting_height_range', + 'loop_sensor_defect', + 'loop_sensor_problem_front', + 'loop_sensor_problem_left', + 'loop_sensor_problem_rear', + 'loop_sensor_problem_right', + 'low_battery', + 'memory_circuit_problem', + 'mower_lifted', + 'mower_tilted', + 'no_accurate_position_from_satellites', + 'no_confirmed_position', + 'no_drive', + 'no_loop_signal', + 'no_power_in_charging_station', + 'no_response_from_charger', + 'outside_working_area', + 'poor_signal_quality', + 'reference_station_communication_problem', + 'right_brush_motor_overloaded', + 'safety_function_faulty', + 'settings_restored', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_locked', + 'sim_card_not_found', + 'sim_card_requires_pin', + 'slipped_mower_has_slipped_situation_not_solved_with_moving_pattern', + 'slope_too_steep', + 'sms_could_not_be_sent', + 'stop_button_problem', + 'stuck_in_charging_station', + 'switch_cord_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'temporary_battery_problem', + 'tilt_sensor_problem', + 'too_high_discharge_current', + 'too_high_internal_current', + 'trapped', + 'ultrasonic_problem', + 'ultrasonic_sensor_1_defect', + 'ultrasonic_sensor_2_defect', + 'ultrasonic_sensor_3_defect', + 'ultrasonic_sensor_4_defect', + 'unexpected_cutting_height_adj', + 'unexpected_error', + 'upside_down', + 'weak_gps_signal', + 'wheel_drive_problem_left', + 'wheel_drive_problem_rear_left', + 'wheel_drive_problem_rear_right', + 'wheel_drive_problem_right', + 'wheel_motor_blocked_left', + 'wheel_motor_blocked_rear_left', + 'wheel_motor_blocked_rear_right', + 'wheel_motor_blocked_right', + 'wheel_motor_overloaded_left', + 'wheel_motor_overloaded_rear_left', + 'wheel_motor_overloaded_rear_right', + 'wheel_motor_overloaded_right', + 'work_area_not_valid', + 'wrong_loop_signal', + 'wrong_pin_code', + 'zone_generator_problem', + ]), + }), + 'context': , + 'entity_id': 'sensor.test_mower_1_error', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'no_error', + }) +# --- # name: test_sensor[sensor.test_mower_1_mode-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -311,6 +649,78 @@ 'state': '11396', }) # --- +# name: test_sensor[sensor.test_mower_1_restricted_reason-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'all_work_areas_completed', + 'daily_limit', + 'external', + 'fota', + 'frost', + 'none', + 'not_applicable', + 'park_override', + 'sensor', + 'week_schedule', + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_mower_1_restricted_reason', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Restricted reason', + 'platform': 'husqvarna_automower', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'restricted_reason', + 'unique_id': 'c7233734-b219-4287-a173-08e3643f89f0_restricted_reason', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensor[sensor.test_mower_1_restricted_reason-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'enum', + 'friendly_name': 'Test Mower 1 Restricted reason', + 'options': list([ + 'all_work_areas_completed', + 'daily_limit', + 'external', + 'fota', + 'frost', + 'none', + 'not_applicable', + 'park_override', + 'sensor', + 'week_schedule', + ]), + }), + 'context': , + 'entity_id': 'sensor.test_mower_1_restricted_reason', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'week_schedule', + }) +# --- # name: test_sensor[sensor.test_mower_1_total_charging_time-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/husqvarna_automower/test_sensor.py b/tests/components/husqvarna_automower/test_sensor.py index bc464b2ce78..6d4e8412ad3 100644 --- a/tests/components/husqvarna_automower/test_sensor.py +++ b/tests/components/husqvarna_automower/test_sensor.py @@ -94,6 +94,31 @@ async def test_statistics_not_available( assert state is None +async def test_error_sensor( + hass: HomeAssistant, + mock_automower_client: AsyncMock, + mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, +) -> None: + """Test error sensor.""" + values = mower_list_to_dictionary_dataclass( + load_json_value_fixture("mower.json", DOMAIN) + ) + await setup_integration(hass, mock_config_entry) + + for state, expected_state in [ + (None, "no_error"), + ("can_error", "can_error"), + ]: + values[TEST_MOWER_ID].mower.error_key = state + mock_automower_client.get_status.return_value = values + freezer.tick(timedelta(minutes=5)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + state = hass.states.get("sensor.test_mower_1_error") + assert state.state == expected_state + + async def test_sensor( hass: HomeAssistant, entity_registry: er.EntityRegistry,