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 @property
def state(self) -> str | None: def state(self) -> str | None:
"""Return the current state.""" """Return the current state."""
if (activity := self.activity) is None: return self.activity
return None
return str(activity)
@cached_property @cached_property
def activity(self) -> LawnMowerActivity | None: def activity(self) -> LawnMowerActivity | None:

View File

@ -100,7 +100,7 @@ async def test_mower(
await hass.async_block_till_done() await hass.async_block_till_done()
assert state_changes[0].data["entity_id"] == entity 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( @pytest.mark.parametrize(

View File

@ -176,4 +176,4 @@ async def test_lawn_mower_state(hass: HomeAssistant) -> None:
lawn_mower.hass = hass lawn_mower.hass = hass
lawn_mower.start_mowing() lawn_mower.start_mowing()
assert lawn_mower.state == str(LawnMowerActivity.MOWING) assert lawn_mower.state == LawnMowerActivity.MOWING