Change lawn_mower state to an enum (#126458)

* Change lawn_mower state to an enum

* annotate as string
This commit is contained in:
G Johansson 2024-09-23 17:39:53 +02:00 committed by GitHub
parent 8a2dccddc5
commit 8eb76ea68d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 5 deletions

View file

@ -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:

View file

@ -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(

View file

@ -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