diff --git a/homeassistant/components/husqvarna_automower/lawn_mower.py b/homeassistant/components/husqvarna_automower/lawn_mower.py index e9ed9187530..8ba9136364a 100644 --- a/homeassistant/components/husqvarna_automower/lawn_mower.py +++ b/homeassistant/components/husqvarna_automower/lawn_mower.py @@ -83,7 +83,7 @@ class AutomowerLawnMowerEntity(AutomowerControlEntity, LawnMowerEntity): async def async_start_mowing(self) -> None: """Resume schedule.""" try: - await self.coordinator.api.resume_schedule(self.mower_id) + await self.coordinator.api.commands.resume_schedule(self.mower_id) except ApiException as exception: raise HomeAssistantError( f"Command couldn't be sent to the command queue: {exception}" @@ -92,7 +92,7 @@ class AutomowerLawnMowerEntity(AutomowerControlEntity, LawnMowerEntity): async def async_pause(self) -> None: """Pauses the mower.""" try: - await self.coordinator.api.pause_mowing(self.mower_id) + await self.coordinator.api.commands.pause_mowing(self.mower_id) except ApiException as exception: raise HomeAssistantError( f"Command couldn't be sent to the command queue: {exception}" @@ -101,7 +101,7 @@ class AutomowerLawnMowerEntity(AutomowerControlEntity, LawnMowerEntity): async def async_dock(self) -> None: """Parks the mower until next schedule.""" try: - await self.coordinator.api.park_until_next_schedule(self.mower_id) + await self.coordinator.api.commands.park_until_next_schedule(self.mower_id) except ApiException as exception: raise HomeAssistantError( f"Command couldn't be sent to the command queue: {exception}" diff --git a/homeassistant/components/husqvarna_automower/manifest.json b/homeassistant/components/husqvarna_automower/manifest.json index 647320a8bf3..4f7a4bf966e 100644 --- a/homeassistant/components/husqvarna_automower/manifest.json +++ b/homeassistant/components/husqvarna_automower/manifest.json @@ -7,5 +7,5 @@ "documentation": "https://www.home-assistant.io/integrations/husqvarna_automower", "iot_class": "cloud_push", "loggers": ["aioautomower"], - "requirements": ["aioautomower==2024.4.4"] + "requirements": ["aioautomower==2024.5.0"] } diff --git a/homeassistant/components/husqvarna_automower/number.py b/homeassistant/components/husqvarna_automower/number.py index bcf74ac4d33..94fe7d9aab7 100644 --- a/homeassistant/components/husqvarna_automower/number.py +++ b/homeassistant/components/husqvarna_automower/number.py @@ -49,7 +49,7 @@ async def async_set_work_area_cutting_height( work_area_id: int, ) -> None: """Set cutting height for work area.""" - await coordinator.api.set_cutting_height_workarea( + await coordinator.api.commands.set_cutting_height_workarea( mower_id, int(cheight), work_area_id ) # As there are no updates from the websocket regarding work area changes, @@ -58,6 +58,15 @@ async def async_set_work_area_cutting_height( await coordinator.async_request_refresh() +async def async_set_cutting_height( + session: AutomowerSession, + mower_id: str, + cheight: float, +) -> None: + """Set cutting height.""" + await session.commands.set_cutting_height(mower_id, int(cheight)) + + @dataclass(frozen=True, kw_only=True) class AutomowerNumberEntityDescription(NumberEntityDescription): """Describes Automower number entity.""" @@ -77,9 +86,7 @@ NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = ( native_max_value=9, exists_fn=lambda data: data.cutting_height is not None, value_fn=_async_get_cutting_height, - set_value_fn=lambda session, mower_id, cheight: session.set_cutting_height( - mower_id, int(cheight) - ), + set_value_fn=async_set_cutting_height, ), ) diff --git a/homeassistant/components/husqvarna_automower/select.py b/homeassistant/components/husqvarna_automower/select.py index 67aac4a2046..08de86baf00 100644 --- a/homeassistant/components/husqvarna_automower/select.py +++ b/homeassistant/components/husqvarna_automower/select.py @@ -64,7 +64,7 @@ class AutomowerSelectEntity(AutomowerControlEntity, SelectEntity): async def async_select_option(self, option: str) -> None: """Change the selected option.""" try: - await self.coordinator.api.set_headlight_mode( + await self.coordinator.api.commands.set_headlight_mode( self.mower_id, cast(HeadlightModes, option.upper()) ) except ApiException as exception: diff --git a/homeassistant/components/husqvarna_automower/switch.py b/homeassistant/components/husqvarna_automower/switch.py index b178fc05c50..01d66a22a28 100644 --- a/homeassistant/components/husqvarna_automower/switch.py +++ b/homeassistant/components/husqvarna_automower/switch.py @@ -78,7 +78,7 @@ class AutomowerSwitchEntity(AutomowerControlEntity, SwitchEntity): async def async_turn_off(self, **kwargs: Any) -> None: """Turn the entity off.""" try: - await self.coordinator.api.park_until_further_notice(self.mower_id) + await self.coordinator.api.commands.park_until_further_notice(self.mower_id) except ApiException as exception: raise HomeAssistantError( f"Command couldn't be sent to the command queue: {exception}" @@ -87,7 +87,7 @@ class AutomowerSwitchEntity(AutomowerControlEntity, SwitchEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Turn the entity on.""" try: - await self.coordinator.api.resume_schedule(self.mower_id) + await self.coordinator.api.commands.resume_schedule(self.mower_id) except ApiException as exception: raise HomeAssistantError( f"Command couldn't be sent to the command queue: {exception}" diff --git a/requirements_all.txt b/requirements_all.txt index 0813639c627..66072f091b3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -201,7 +201,7 @@ aioaseko==0.1.1 aioasuswrt==1.4.0 # homeassistant.components.husqvarna_automower -aioautomower==2024.4.4 +aioautomower==2024.5.0 # homeassistant.components.azure_devops aioazuredevops==2.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 05ebed895f5..b04e6c2e47b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -180,7 +180,7 @@ aioaseko==0.1.1 aioasuswrt==1.4.0 # homeassistant.components.husqvarna_automower -aioautomower==2024.4.4 +aioautomower==2024.5.0 # homeassistant.components.azure_devops aioazuredevops==2.0.0 diff --git a/tests/components/husqvarna_automower/conftest.py b/tests/components/husqvarna_automower/conftest.py index 5d7cb43698b..fc258f89abc 100644 --- a/tests/components/husqvarna_automower/conftest.py +++ b/tests/components/husqvarna_automower/conftest.py @@ -90,5 +90,6 @@ def mock_automower_client() -> Generator[AsyncMock, None, None]: return ClientWebSocketResponse client.auth = AsyncMock(side_effect=websocket_connect) + client.commands = AsyncMock() yield client diff --git a/tests/components/husqvarna_automower/snapshots/test_diagnostics.ambr b/tests/components/husqvarna_automower/snapshots/test_diagnostics.ambr index c604923f67f..60bb04fdb94 100644 --- a/tests/components/husqvarna_automower/snapshots/test_diagnostics.ambr +++ b/tests/components/husqvarna_automower/snapshots/test_diagnostics.ambr @@ -5,6 +5,22 @@ 'battery_percent': 100, }), 'calendar': dict({ + 'events': list([ + dict({ + 'end': '2024-05-07T00:00:00+00:00', + 'rrule': 'FREQ=WEEKLY;BYDAY=MO,WE,FR', + 'start': '2024-05-06T19:00:00+00:00', + 'uid': '1140_300_MO,WE,FR', + 'work_area_id': None, + }), + dict({ + 'end': '2024-05-07T08:00:00+00:00', + 'rrule': 'FREQ=WEEKLY;BYDAY=TU,TH,SA', + 'start': '2024-05-07T00:00:00+00:00', + 'uid': '0_480_TU,TH,SA', + 'work_area_id': None, + }), + ]), 'tasks': list([ dict({ 'duration': 300, diff --git a/tests/components/husqvarna_automower/test_lawn_mower.py b/tests/components/husqvarna_automower/test_lawn_mower.py index c8aea0e7c98..58e7c65bf92 100644 --- a/tests/components/husqvarna_automower/test_lawn_mower.py +++ b/tests/components/husqvarna_automower/test_lawn_mower.py @@ -71,9 +71,9 @@ async def test_lawn_mower_commands( """Test lawn_mower commands.""" await setup_integration(hass, mock_config_entry) - getattr(mock_automower_client, aioautomower_command).side_effect = ApiException( - "Test error" - ) + getattr( + mock_automower_client.commands, aioautomower_command + ).side_effect = ApiException("Test error") with pytest.raises(HomeAssistantError) as exc_info: await hass.services.async_call( diff --git a/tests/components/husqvarna_automower/test_number.py b/tests/components/husqvarna_automower/test_number.py index a883ed43e81..1b3751af28f 100644 --- a/tests/components/husqvarna_automower/test_number.py +++ b/tests/components/husqvarna_automower/test_number.py @@ -35,7 +35,7 @@ async def test_number_commands( service_data={"value": "3"}, blocking=True, ) - mocked_method = mock_automower_client.set_cutting_height + mocked_method = mock_automower_client.commands.set_cutting_height assert len(mocked_method.mock_calls) == 1 mocked_method.side_effect = ApiException("Test error") @@ -68,7 +68,9 @@ async def test_number_workarea_commands( values[TEST_MOWER_ID].work_areas[123456].cutting_height = 75 mock_automower_client.get_status.return_value = values mocked_method = AsyncMock() - setattr(mock_automower_client, "set_cutting_height_workarea", mocked_method) + setattr( + mock_automower_client.commands, "set_cutting_height_workarea", mocked_method + ) await hass.services.async_call( domain="number", service="set_value", diff --git a/tests/components/husqvarna_automower/test_select.py b/tests/components/husqvarna_automower/test_select.py index 9e255eb410f..b6f3ba4b665 100644 --- a/tests/components/husqvarna_automower/test_select.py +++ b/tests/components/husqvarna_automower/test_select.py @@ -81,7 +81,7 @@ async def test_select_commands( }, blocking=True, ) - mocked_method = mock_automower_client.set_headlight_mode + mocked_method = mock_automower_client.commands.set_headlight_mode assert len(mocked_method.mock_calls) == 1 mocked_method.side_effect = ApiException("Test error") diff --git a/tests/components/husqvarna_automower/test_switch.py b/tests/components/husqvarna_automower/test_switch.py index aab1128a746..1356b802857 100644 --- a/tests/components/husqvarna_automower/test_switch.py +++ b/tests/components/husqvarna_automower/test_switch.py @@ -76,7 +76,7 @@ async def test_switch_commands( service_data={"entity_id": "switch.test_mower_1_enable_schedule"}, blocking=True, ) - mocked_method = getattr(mock_automower_client, aioautomower_command) + mocked_method = getattr(mock_automower_client.commands, aioautomower_command) assert len(mocked_method.mock_calls) == 1 mocked_method.side_effect = ApiException("Test error")