Fix Husqvarna Automower schedule switch turning back on (#117692)

This commit is contained in:
Thomas55555 2024-06-21 15:27:39 +02:00 committed by GitHub
parent e149aa6b2e
commit 4aecd23f1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 12 deletions

View File

@ -7,8 +7,8 @@ from typing import TYPE_CHECKING, Any
from aioautomower.exceptions import ApiException from aioautomower.exceptions import ApiException
from aioautomower.model import ( from aioautomower.model import (
MowerActivities, MowerActivities,
MowerModes,
MowerStates, MowerStates,
RestrictedReasons,
StayOutZones, StayOutZones,
Zone, Zone,
) )
@ -86,11 +86,7 @@ class AutomowerScheduleSwitchEntity(AutomowerControlEntity, SwitchEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return the state of the switch.""" """Return the state of the switch."""
attributes = self.mower_attributes return self.mower_attributes.mower.mode != MowerModes.HOME
return not (
attributes.mower.state == MowerStates.RESTRICTED
and attributes.planner.restricted_reason == RestrictedReasons.NOT_APPLICABLE
)
@property @property
def available(self) -> bool: def available(self) -> bool:

View File

@ -3,7 +3,7 @@
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from aioautomower.exceptions import ApiException 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 aioautomower.utils import mower_list_to_dictionary_dataclass
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
@ -41,12 +41,11 @@ async def test_switch_states(
) )
await setup_integration(hass, mock_config_entry) await setup_integration(hass, mock_config_entry)
for state, restricted_reson, expected_state in ( for mode, expected_state in (
(MowerStates.RESTRICTED, RestrictedReasons.NOT_APPLICABLE, "off"), (MowerModes.HOME, "off"),
(MowerStates.IN_OPERATION, RestrictedReasons.NONE, "on"), (MowerModes.MAIN_AREA, "on"),
): ):
values[TEST_MOWER_ID].mower.state = state values[TEST_MOWER_ID].mower.mode = mode
values[TEST_MOWER_ID].planner.restricted_reason = restricted_reson
mock_automower_client.get_status.return_value = values mock_automower_client.get_status.return_value = values
freezer.tick(SCAN_INTERVAL) freezer.tick(SCAN_INTERVAL)
async_fire_time_changed(hass) async_fire_time_changed(hass)