Skip to content

Commit

Permalink
Fix home connect remaining progress time (#109525)
Browse files Browse the repository at this point in the history
* fix remaining progress time for home connect component

The home connect API is sending some default values (on dishwashers) for
the remaining progress time after the program finished. This is a problem
because this value is stored and on every API event, for example opening
the door of a dishwasher, the value for remaining progress time is
updated with this wrong value. So I see a wrong value the whole time the
dishwasher is not running and therefore has no remaining progress time.
This coming fixes this problem and adds a check if the appliance is in
running, pause or finished state, because there we have valid data. In
the other states the new code just returns none like on other edge
cases. Now there is no value if there is no program running.

* fix some formating according to the ruff rules

* fix some formating according to the ruff rules again

* fix alphabetic order of imports

* add check if keys exist in dict before accessing them

check if BSH_OPERATION_STATE and ATTR_VALUE key values exist before
accessing them later in the elif statement

* fix formating because forgotten local ruff run
  • Loading branch information
leahoswald authored and frenck committed Feb 5, 2024
1 parent 5c1e437 commit 66d8856
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/home_connect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
BSH_POWER_OFF = "BSH.Common.EnumType.PowerState.Off"
BSH_POWER_STANDBY = "BSH.Common.EnumType.PowerState.Standby"
BSH_ACTIVE_PROGRAM = "BSH.Common.Root.ActiveProgram"
BSH_OPERATION_STATE = "BSH.Common.Status.OperationState"
BSH_REMOTE_CONTROL_ACTIVATION_STATE = "BSH.Common.Status.RemoteControlActive"
BSH_REMOTE_START_ALLOWANCE_STATE = "BSH.Common.Status.RemoteControlStartAllowed"

BSH_OPERATION_STATE = "BSH.Common.Status.OperationState"
BSH_OPERATION_STATE_RUN = "BSH.Common.EnumType.OperationState.Run"
BSH_OPERATION_STATE_PAUSE = "BSH.Common.EnumType.OperationState.Pause"
BSH_OPERATION_STATE_FINISHED = "BSH.Common.EnumType.OperationState.Finished"

COOKING_LIGHTING = "Cooking.Common.Setting.Lighting"
COOKING_LIGHTING_BRIGHTNESS = "Cooking.Common.Setting.LightingBrightness"

Expand Down
22 changes: 20 additions & 2 deletions homeassistant/components/home_connect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.dt as dt_util

from .const import ATTR_VALUE, BSH_OPERATION_STATE, DOMAIN
from .const import (
ATTR_VALUE,
BSH_OPERATION_STATE,
BSH_OPERATION_STATE_FINISHED,
BSH_OPERATION_STATE_PAUSE,
BSH_OPERATION_STATE_RUN,
DOMAIN,
)
from .entity import HomeConnectEntity

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -69,9 +76,20 @@ async def async_update(self) -> None:
# if the date is supposed to be in the future but we're
# already past it, set state to None.
self._attr_native_value = None
else:
elif (
BSH_OPERATION_STATE in status
and ATTR_VALUE in status[BSH_OPERATION_STATE]
and status[BSH_OPERATION_STATE][ATTR_VALUE]
in [
BSH_OPERATION_STATE_RUN,
BSH_OPERATION_STATE_PAUSE,
BSH_OPERATION_STATE_FINISHED,
]
):
seconds = self._sign * float(status[self._key][ATTR_VALUE])
self._attr_native_value = dt_util.utcnow() + timedelta(seconds=seconds)
else:
self._attr_native_value = None
else:
self._attr_native_value = status[self._key].get(ATTR_VALUE)
if self._key == BSH_OPERATION_STATE:
Expand Down

0 comments on commit 66d8856

Please sign in to comment.