Skip to content

Commit

Permalink
Bump aioautomower to 2024.5.0 (#116942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas55555 committed May 6, 2024
1 parent 486b8ca commit 8e66e5b
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 20 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/husqvarna_automower/lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def activity(self) -> LawnMowerActivity:
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}"
Expand All @@ -92,7 +92,7 @@ async def async_start_mowing(self) -> None:
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}"
Expand All @@ -101,7 +101,7 @@ async def async_pause(self) -> None:
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}"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/husqvarna_automower/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
15 changes: 11 additions & 4 deletions homeassistant/components/husqvarna_automower/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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."""
Expand All @@ -77,9 +86,7 @@ class AutomowerNumberEntityDescription(NumberEntityDescription):
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,
),
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/husqvarna_automower/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def current_option(self) -> str:
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:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/husqvarna_automower/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def available(self) -> bool:
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}"
Expand All @@ -87,7 +87,7 @@ async def async_turn_off(self, **kwargs: Any) -> None:
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}"
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/components/husqvarna_automower/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ async def websocket_connect() -> ClientWebSocketResponse:
return ClientWebSocketResponse

client.auth = AsyncMock(side_effect=websocket_connect)
client.commands = AsyncMock()

yield client
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/components/husqvarna_automower/test_lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions tests/components/husqvarna_automower/test_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/components/husqvarna_automower/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/components/husqvarna_automower/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8e66e5b

Please sign in to comment.