Skip to content

Commit

Permalink
Fix inconsistent remaining minutes attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ofalvai committed Oct 12, 2021
1 parent b2b8db5 commit 9d4bab6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion custom_components/candy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def extra_state_attributes(self) -> Mapping[str, Any]:
"program": status.program,
"temperature": status.temp,
"spin_speed": status.spin_speed,
"remaining_minutes": status.remaining_minutes,
"remaining_minutes": status.remaining_minutes if status.machine_state in [MachineState.RUNNING,
MachineState.PAUSED] else 0,
"remote_control": status.remote_control,
}

Expand Down
18 changes: 16 additions & 2 deletions tests/test_sensor_washing_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def test_main_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpClie
'program': 1,
'temperature': 40,
'spin_speed': 800,
'remaining_minutes': 39,
'remaining_minutes': 0,
'remote_control': True,
'fill_percent': 0,
'friendly_name': 'Washing machine',
Expand Down Expand Up @@ -53,6 +53,20 @@ async def test_remaining_time_sensor_wash(hass: HomeAssistant, aioclient_mock: A
}


async def test_remaining_time_sensor_idle(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
await init_integration(hass, aioclient_mock, load_fixture("washing_machine/idle.json"))

state = hass.states.get("sensor.wash_cycle_remaining_time")

assert state
assert state.state == "0"
assert state.attributes == {
"friendly_name": "Wash cycle remaining time",
"icon": "mdi:progress-clock",
"unit_of_measurement": "min",
}


async def test_main_sensor_no_fillr(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker):
await init_integration(hass, aioclient_mock, load_fixture("washing_machine/no_fillr.json"))

Expand All @@ -64,7 +78,7 @@ async def test_main_sensor_no_fillr(hass: HomeAssistant, aioclient_mock: Aiohttp
'program': 4,
'temperature': 40,
'spin_speed': 1000,
'remaining_minutes': 1,
'remaining_minutes': 0,
'remote_control': False,
'friendly_name': 'Washing machine',
'icon': 'mdi:washing-machine'
Expand Down

0 comments on commit 9d4bab6

Please sign in to comment.