diff --git a/homeassistant/components/husqvarna_automower/switch.py b/homeassistant/components/husqvarna_automower/switch.py index fed2d3cfedc..a856e9c9050 100644 --- a/homeassistant/components/husqvarna_automower/switch.py +++ b/homeassistant/components/husqvarna_automower/switch.py @@ -7,8 +7,8 @@ from typing import TYPE_CHECKING, Any from aioautomower.exceptions import ApiException from aioautomower.model import ( MowerActivities, + MowerModes, MowerStates, - RestrictedReasons, StayOutZones, Zone, ) @@ -86,11 +86,7 @@ class AutomowerScheduleSwitchEntity(AutomowerControlEntity, SwitchEntity): @property def is_on(self) -> bool: """Return the state of the switch.""" - attributes = self.mower_attributes - return not ( - attributes.mower.state == MowerStates.RESTRICTED - and attributes.planner.restricted_reason == RestrictedReasons.NOT_APPLICABLE - ) + return self.mower_attributes.mower.mode != MowerModes.HOME @property def available(self) -> bool: diff --git a/tests/components/husqvarna_automower/test_switch.py b/tests/components/husqvarna_automower/test_switch.py index de18f9081ea..08450158876 100644 --- a/tests/components/husqvarna_automower/test_switch.py +++ b/tests/components/husqvarna_automower/test_switch.py @@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, patch from aioautomower.exceptions import ApiException -from aioautomower.model import MowerStates, RestrictedReasons +from aioautomower.model import MowerModes from aioautomower.utils import mower_list_to_dictionary_dataclass from freezegun.api import FrozenDateTimeFactory import pytest @@ -41,12 +41,11 @@ async def test_switch_states( ) await setup_integration(hass, mock_config_entry) - for state, restricted_reson, expected_state in ( - (MowerStates.RESTRICTED, RestrictedReasons.NOT_APPLICABLE, "off"), - (MowerStates.IN_OPERATION, RestrictedReasons.NONE, "on"), + for mode, expected_state in ( + (MowerModes.HOME, "off"), + (MowerModes.MAIN_AREA, "on"), ): - values[TEST_MOWER_ID].mower.state = state - values[TEST_MOWER_ID].planner.restricted_reason = restricted_reson + values[TEST_MOWER_ID].mower.mode = mode mock_automower_client.get_status.return_value = values freezer.tick(SCAN_INTERVAL) async_fire_time_changed(hass)