From 8eb76ea68d8bc48d8be7390e25937390309730ff Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 23 Sep 2024 17:39:53 +0200 Subject: [PATCH] Change lawn_mower state to an enum (#126458) * Change lawn_mower state to an enum * annotate as string --- homeassistant/components/lawn_mower/__init__.py | 4 +--- tests/components/kitchen_sink/test_lawn_mower.py | 2 +- tests/components/lawn_mower/test_init.py | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/lawn_mower/__init__.py b/homeassistant/components/lawn_mower/__init__.py index b4d174f6676..604a6580f97 100644 --- a/homeassistant/components/lawn_mower/__init__.py +++ b/homeassistant/components/lawn_mower/__init__.py @@ -86,9 +86,7 @@ class LawnMowerEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @property def state(self) -> str | None: """Return the current state.""" - if (activity := self.activity) is None: - return None - return str(activity) + return self.activity @cached_property def activity(self) -> LawnMowerActivity | None: diff --git a/tests/components/kitchen_sink/test_lawn_mower.py b/tests/components/kitchen_sink/test_lawn_mower.py index e1ba201a722..5bd4fc834f8 100644 --- a/tests/components/kitchen_sink/test_lawn_mower.py +++ b/tests/components/kitchen_sink/test_lawn_mower.py @@ -100,7 +100,7 @@ async def test_mower( await hass.async_block_till_done() assert state_changes[0].data["entity_id"] == entity - assert state_changes[0].data["new_state"].state == str(next_activity.value) + assert state_changes[0].data["new_state"].state == next_activity.value @pytest.mark.parametrize( diff --git a/tests/components/lawn_mower/test_init.py b/tests/components/lawn_mower/test_init.py index 16f32da7e04..0735d4541ff 100644 --- a/tests/components/lawn_mower/test_init.py +++ b/tests/components/lawn_mower/test_init.py @@ -176,4 +176,4 @@ async def test_lawn_mower_state(hass: HomeAssistant) -> None: lawn_mower.hass = hass lawn_mower.start_mowing() - assert lawn_mower.state == str(LawnMowerActivity.MOWING) + assert lawn_mower.state == LawnMowerActivity.MOWING