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 all 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
14 changes: 11 additions & 3 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
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
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': 'returning',
}),
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Mower is paused',
Expand Down
6 changes: 6 additions & 0 deletions tests/components/kitchen_sink/test_lawn_mower.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ async def test_states(hass: HomeAssistant, snapshot: SnapshotAssertion) -> None:
LawnMowerActivity.MOWING,
LawnMowerActivity.DOCKED,
),
(
"lawn_mower.mower_can_return",
mikey0000 marked this conversation as resolved.
Show resolved Hide resolved
SERVICE_DOCK,
LawnMowerActivity.RETURNING,
LawnMowerActivity.DOCKED,
),
],
)
async def test_mower(
Expand Down
18 changes: 17 additions & 1 deletion 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 @@ -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