Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LawnMowerActivity.RETURNING to Lawn Mower #124261

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions homeassistant/components/kitchen_sink/lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,34 @@ async def async_setup_platform(
),
DemoLawnMower(
"kitchen_sink_mower_002",
"Mower can return",
LawnMowerActivity.RETURNING,
LawnMowerEntityFeature.DOCK
| LawnMowerEntityFeature.PAUSE
| LawnMowerEntityFeature.START_MOWING,
),
DemoLawnMower(
"kitchen_sink_mower_003",
"Mower can dock",
LawnMowerActivity.MOWING,
LawnMowerEntityFeature.DOCK | LawnMowerEntityFeature.START_MOWING,
),
DemoLawnMower(
"kitchen_sink_mower_003",
"kitchen_sink_mower_004",
"Mower can pause",
LawnMowerActivity.DOCKED,
LawnMowerEntityFeature.PAUSE | LawnMowerEntityFeature.START_MOWING,
),
DemoLawnMower(
"kitchen_sink_mower_004",
"kitchen_sink_mower_005",
"Mower can do all",
LawnMowerActivity.DOCKED,
LawnMowerEntityFeature.DOCK
| LawnMowerEntityFeature.PAUSE
| LawnMowerEntityFeature.START_MOWING,
),
DemoLawnMower(
"kitchen_sink_mower_005",
"kitchen_sink_mower_006",
"Mower is paused",
LawnMowerActivity.PAUSED,
LawnMowerEntityFeature.DOCK
Expand Down Expand Up @@ -92,7 +100,7 @@ async def async_start_mowing(self) -> None:

async def async_dock(self) -> None:
"""Start docking."""
self._attr_activity = LawnMowerActivity.DOCKED
self._attr_activity = LawnMowerActivity.RETURNING
self.async_write_ha_state()

async def async_pause(self) -> None:
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/lawn_mower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class LawnMowerActivity(StrEnum):
DOCKED = "docked"
"""Device is docked."""

RETURNING = "returning"
"""Device is returning."""


class LawnMowerEntityFeature(IntFlag):
"""Supported features of the lawn mower entity."""
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/lawn_mower/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"error": "Error",
"paused": "[%key:common::state::paused%]",
"mowing": "Mowing",
"docked": "Docked"
"docked": "Docked",
"returning": "Returning"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def async_start_mowing(self) -> None:

async def async_dock(self) -> None:
"""Dock the mower."""
await self._async_operate("dock", LawnMowerActivity.DOCKED)
await self._async_operate("dock", LawnMowerActivity.RETURNING)
mikey0000 marked this conversation as resolved.
Show resolved Hide resolved

async def async_pause(self) -> None:
"""Pause the lawn mower."""
Expand Down
12 changes: 12 additions & 0 deletions tests/components/kitchen_sink/snapshots/test_lawn_mower.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
'last_updated': <ANY>,
'state': 'docked',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Mower can return',
'supported_features': <LawnMowerEntityFeature: 7>,
}),
'context': <ANY>,
'entity_id': 'lawn_mower.mower_can_return',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'paused',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Mower is paused',
Expand Down
6 changes: 3 additions & 3 deletions tests/components/kitchen_sink/test_lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
async def test_states(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None:
"""Test the expected lawn mower entities are added."""
states = hass.states.async_all()
assert set(states) == snapshot

Check failure on line 45 in tests/components/kitchen_sink/test_lawn_mower.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (2)

test_states AssertionError: assert [+ received] == [- snapshot] set({ ... 'last_updated': <ANY>, - 'state': 'paused', + 'state': 'returning', }), ... })


@pytest.mark.parametrize(
Expand All @@ -67,10 +67,10 @@
LawnMowerActivity.MOWING,
),
(
"lawn_mower.mower_can_dock",
"lawn_mower.mower_can_return",
mikey0000 marked this conversation as resolved.
Show resolved Hide resolved
SERVICE_DOCK,
LawnMowerActivity.MOWING,
LawnMowerActivity.DOCKED,
LawnMowerActivity.PAUSED,
LawnMowerActivity.RETURNING,
),
],
)
Expand All @@ -84,7 +84,7 @@
"""Test the activity states of a lawn mower."""
state = hass.states.get(entity)

assert state.state == str(activity.value)

Check failure on line 87 in tests/components/kitchen_sink/test_lawn_mower.py

View workflow job for this annotation

GitHub Actions / Run tests Python 3.12 (2)

test_mower[lawn_mower.mower_can_return-dock-paused-returning] AssertionError: assert 'returning' == 'paused' - paused + returning
await hass.async_block_till_done()

state_changes = async_capture_events(hass, EVENT_STATE_CHANGED)
Expand Down
24 changes: 20 additions & 4 deletions tests/components/mqtt/test_lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ async def test_run_lawn_mower_setup_and_state_updates(
state = hass.states.get("lawn_mower.test_lawn_mower")
assert state.state == "mowing"

async_fire_mqtt_message(hass, "test/lawn_mower_stat", "returning")

await hass.async_block_till_done()

state = hass.states.get("lawn_mower.test_lawn_mower")
assert state.state == "returning"

async_fire_mqtt_message(hass, "test/lawn_mower_stat", "docked")

await hass.async_block_till_done()
Expand Down Expand Up @@ -198,6 +205,13 @@ async def test_value_template(
state = hass.states.get("lawn_mower.test_lawn_mower")
assert state.state == "paused"

async_fire_mqtt_message(hass, "test/lawn_mower_stat", '{"val":"returning"}')

await hass.async_block_till_done()

state = hass.states.get("lawn_mower.test_lawn_mower")
assert state.state == "returning"

async_fire_mqtt_message(hass, "test/lawn_mower_stat", '{"val": null}')

await hass.async_block_till_done()
Expand Down Expand Up @@ -262,7 +276,7 @@ async def test_run_lawn_mower_service_optimistic(
mqtt_mock.async_publish.assert_called_once_with("dock-test-topic", "dock", 0, False)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("lawn_mower.test")
assert state.state == "docked"
assert state.state == "returning"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -362,7 +376,7 @@ async def test_run_lawn_mower_service_optimistic_with_command_templates(
)
mqtt_mock.async_publish.reset_mock()
state = hass.states.get("lawn_mower.test_lawn_mower")
assert state.state == "docked"
assert state.state == "returning"


@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
Expand Down Expand Up @@ -632,7 +646,7 @@ async def test_entity_id_update_discovery_update(
(
SERVICE_DOCK,
"dock",
"docked",
"returning",
"test/lawn_mower_stat",
"dock-test-topic",
),
Expand Down Expand Up @@ -702,7 +716,8 @@ async def test_mqtt_payload_not_a_valid_activity_warning(

assert (
"Invalid activity for lawn_mower.test_lawn_mower: 'painting' "
"(valid activities: ['error', 'paused', 'mowing', 'docked'])" in caplog.text
"(valid activities: ['error', 'paused', 'mowing', 'docked', 'returning'])"
in caplog.text
)


Expand Down Expand Up @@ -774,6 +789,7 @@ async def test_reloadable(
[
("activity_state_topic", "paused", None, "paused"),
("activity_state_topic", "docked", None, "docked"),
("activity_state_topic", "returning", None, "returning"),
("activity_state_topic", "mowing", None, "mowing"),
],
)
Expand Down
Loading