mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 23:57:06 +00:00
Fix dryer's remaining time issue (#138764)
Fix dryer's remain_time issue Co-authored-by: yunseon.park <yunseon.park@lge.com>
This commit is contained in:
parent
93b01a3bc3
commit
d821aa9162
@ -581,36 +581,44 @@ class ThinQSensorEntity(ThinQEntity, SensorEntity):
|
||||
local_now = datetime.now(
|
||||
tz=dt_util.get_time_zone(self.coordinator.hass.config.time_zone)
|
||||
)
|
||||
if value in [0, None, time.min]:
|
||||
# Reset to None
|
||||
self._device_state = (
|
||||
self.coordinator.data[self._device_state_id].value
|
||||
if self._device_state_id in self.coordinator.data
|
||||
else None
|
||||
)
|
||||
if value in [0, None, time.min] or (
|
||||
self._device_state == "power_off"
|
||||
and self.entity_description.key
|
||||
in [TimerProperty.REMAIN, TimerProperty.TOTAL]
|
||||
):
|
||||
# Reset to None when power_off
|
||||
value = None
|
||||
elif self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
|
||||
if self.entity_description.key in TIME_SENSOR_DESC:
|
||||
# Set timestamp for time
|
||||
# Set timestamp for absolute time
|
||||
value = local_now.replace(hour=value.hour, minute=value.minute)
|
||||
else:
|
||||
# Set timestamp for delta
|
||||
new_state = (
|
||||
self.coordinator.data[self._device_state_id].value
|
||||
if self._device_state_id in self.coordinator.data
|
||||
else None
|
||||
)
|
||||
if (
|
||||
self.native_value is not None
|
||||
and self._device_state == new_state
|
||||
):
|
||||
# Skip update when same state
|
||||
return
|
||||
|
||||
self._device_state = new_state
|
||||
time_delta = timedelta(
|
||||
event_data = timedelta(
|
||||
hours=value.hour, minutes=value.minute, seconds=value.second
|
||||
)
|
||||
value = (
|
||||
(local_now - time_delta)
|
||||
new_time = (
|
||||
(local_now - event_data)
|
||||
if self.entity_description.key == TimerProperty.RUNNING
|
||||
else (local_now + time_delta)
|
||||
else (local_now + event_data)
|
||||
)
|
||||
# The remain_time may change during the wash/dry operation depending on various reasons.
|
||||
# If there is a diff of more than 60sec, the new timestamp is used
|
||||
if (
|
||||
parse_native_value := dt_util.parse_datetime(
|
||||
str(self.native_value)
|
||||
)
|
||||
) is None or abs(new_time - parse_native_value) > timedelta(
|
||||
seconds=60
|
||||
):
|
||||
value = new_time
|
||||
else:
|
||||
value = self.native_value
|
||||
elif self.entity_description.device_class == SensorDeviceClass.DURATION:
|
||||
# Set duration
|
||||
value = self._get_duration(
|
||||
|
Loading…
x
Reference in New Issue
Block a user