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.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:

View file

@ -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)