Skip to content

Commit

Permalink
Fixed rounding issue datetime conversion
Browse files Browse the repository at this point in the history
Rounding issue when expected a year of 2 digits but receiving one of 4 digits in functions:
- value_function_rtc
- value_function_rtc_ymd
  • Loading branch information
PSMGoossens committed Jan 12, 2025
1 parent cf79b12 commit 2d99211
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/solax_modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def value_function_rtc(initval, descr, datadict):
rtc_months,
rtc_years,
) = initval
val = f"{rtc_days:02}/{rtc_months:02}/{rtc_years:02} {rtc_hours:02}:{rtc_minutes:02}:{rtc_seconds:02}"
val = f"{rtc_days:02}/{rtc_months:02}/{rtc_years%100:02} {rtc_hours:02}:{rtc_minutes:02}:{rtc_seconds:02}"
return datetime.strptime(val, "%d/%m/%y %H:%M:%S") # ok since sensor.py has been adapted
except:
pass
Expand All @@ -423,7 +423,7 @@ def value_function_rtc_ymd(initval, descr, datadict):
rtc_minutes,
rtc_seconds,
) = initval
val = f"{rtc_days:02}/{rtc_months:02}/{rtc_years:02} {rtc_hours:02}:{rtc_minutes:02}:{rtc_seconds:02}"
val = f"{rtc_days:02}/{rtc_months:02}/{rtc_years%100:02} {rtc_hours:02}:{rtc_minutes:02}:{rtc_seconds:02}"
return datetime.strptime(val, "%d/%m/%y %H:%M:%S") # ok since sensor.py has been adapted
except:
pass
Expand Down

0 comments on commit 2d99211

Please sign in to comment.