From e1c15ef932cbe1e570610e153f7e6f4a66a17738 Mon Sep 17 00:00:00 2001 From: "Shaun J.V.Nieuwenhuizen" Date: Tue, 12 Mar 2024 17:36:50 +0200 Subject: [PATCH] Replace time drift conditions in solis_modbus The time drift conditions now use 'total_drift', which is calculated by summing the drift in hours, minutes, and seconds. This change enhances the clarity and readability of the code in the solis_modbus component. --- custom_components/solis_modbus/sensor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/solis_modbus/sensor.py b/custom_components/solis_modbus/sensor.py index 0f5fed2..5080bde 100644 --- a/custom_components/solis_modbus/sensor.py +++ b/custom_components/solis_modbus/sensor.py @@ -753,14 +753,15 @@ def clock_drift_test(hours, minutes, seconds): d_hours = r_hours - hours d_minutes = r_minutes - minutes d_seconds = r_seconds - seconds + total_drift = (d_hours * 60 * 60) + (d_minutes * 60) + d_seconds - if abs(d_seconds) > 60: + if abs(total_drift) > 60: _LOGGER.critical(f"inverter time {hours}:{minutes}:{seconds}. drift = {d_hours}:{d_minutes}:{d_seconds}") - elif abs(d_seconds) > 30: + elif abs(total_drift) > 30: _LOGGER.warning(f"inverter time {hours}:{minutes}:{seconds}. drift = {d_hours}:{d_minutes}:{d_seconds}") - elif abs(d_seconds) > 10: + elif abs(total_drift) > 10: _LOGGER.info(f"inverter time {hours}:{minutes}:{seconds}. drift = {d_hours}:{d_minutes}:{d_seconds}") else: _LOGGER.debug(f"inverter time {hours}:{minutes}:{seconds}. drift = {d_hours}:{d_minutes}:{d_seconds}")