mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix work area sensor for Husqvarna Automower (#141527)
* Fix work area sensor for Husqvarna Automower * simplify
This commit is contained in:
parent
35bcc9d5af
commit
ca6286f241
@ -227,12 +227,16 @@ def _get_work_area_names(data: MowerAttributes) -> list[str]:
|
||||
@callback
|
||||
def _get_current_work_area_name(data: MowerAttributes) -> str:
|
||||
"""Return the name of the current work area."""
|
||||
if data.mower.work_area_id is None:
|
||||
return STATE_NO_WORK_AREA_ACTIVE
|
||||
if TYPE_CHECKING:
|
||||
# Sensor does not get created if values are None
|
||||
assert data.work_areas is not None
|
||||
return data.work_areas[data.mower.work_area_id].name
|
||||
if (
|
||||
data.mower.work_area_id is not None
|
||||
and data.mower.work_area_id in data.work_areas
|
||||
):
|
||||
return data.work_areas[data.mower.work_area_id].name
|
||||
|
||||
return STATE_NO_WORK_AREA_ACTIVE
|
||||
|
||||
|
||||
@callback
|
||||
|
@ -110,6 +110,18 @@ async def test_work_area_sensor(
|
||||
state = hass.states.get("sensor.test_mower_1_work_area")
|
||||
assert state.state == "my_lawn"
|
||||
|
||||
# Test EPOS mower, which returns work_area_id = 0, when no
|
||||
# work area is active and has no default work_area_id=0
|
||||
values[TEST_MOWER_ID].mower.work_area_id = 0
|
||||
del values[TEST_MOWER_ID].work_areas[0]
|
||||
del values[TEST_MOWER_ID].work_area_dict[0]
|
||||
mock_automower_client.get_status.return_value = values
|
||||
freezer.tick(SCAN_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.test_mower_1_work_area")
|
||||
assert state.state == "no_work_area_active"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user