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:
LG-ThinQ-Integration 2025-02-23 05:51:54 +09:00 committed by GitHub
parent 93b01a3bc3
commit d821aa9162
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
value = None
elif self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
if self.entity_description.key in TIME_SENSOR_DESC:
# Set timestamp for 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 self.coordinator.data[self._device_state_id].value
if self._device_state_id in self.coordinator.data if self._device_state_id in self.coordinator.data
else None else None
) )
if ( if value in [0, None, time.min] or (
self.native_value is not None self._device_state == "power_off"
and self._device_state == new_state and self.entity_description.key
in [TimerProperty.REMAIN, TimerProperty.TOTAL]
): ):
# Skip update when same state # Reset to None when power_off
return value = None
elif self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
self._device_state = new_state if self.entity_description.key in TIME_SENSOR_DESC:
time_delta = timedelta( # Set timestamp for absolute time
value = local_now.replace(hour=value.hour, minute=value.minute)
else:
# Set timestamp for delta
event_data = 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(