mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +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(
|
local_now = datetime.now(
|
||||||
tz=dt_util.get_time_zone(self.coordinator.hass.config.time_zone)
|
tz=dt_util.get_time_zone(self.coordinator.hass.config.time_zone)
|
||||||
)
|
)
|
||||||
if value in [0, None, time.min]:
|
self._device_state = (
|
||||||
# Reset to None
|
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
|
value = None
|
||||||
elif self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
|
elif self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
|
||||||
if self.entity_description.key in TIME_SENSOR_DESC:
|
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)
|
value = local_now.replace(hour=value.hour, minute=value.minute)
|
||||||
else:
|
else:
|
||||||
# Set timestamp for delta
|
# Set timestamp for delta
|
||||||
new_state = (
|
event_data = timedelta(
|
||||||
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(
|
|
||||||
hours=value.hour, minutes=value.minute, seconds=value.second
|
hours=value.hour, minutes=value.minute, seconds=value.second
|
||||||
)
|
)
|
||||||
value = (
|
new_time = (
|
||||||
(local_now - time_delta)
|
(local_now - event_data)
|
||||||
if self.entity_description.key == TimerProperty.RUNNING
|
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:
|
elif self.entity_description.device_class == SensorDeviceClass.DURATION:
|
||||||
# Set duration
|
# Set duration
|
||||||
value = self._get_duration(
|
value = self._get_duration(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user