Ver Fonte

## 2023-01-03 - s0meters.py
- fix issue in lastyearlastweek calculation - used code not working on Python < 3.9 (3.7.3 is the "current" version on Raspberry Pi OS Buster)

FloKra há 1 ano atrás
pai
commit
f834b8fc61
2 ficheiros alterados com 5 adições e 1 exclusões
  1. 3 0
      S0Meters_py/CHANGELOG.md
  2. 2 1
      S0Meters_py/s0meters.py

+ 3 - 0
S0Meters_py/CHANGELOG.md

@@ -1,5 +1,8 @@
 # CHANGELOG s0meters.py
 
+## 2023-01-03
+ - fix issue in lastyearlastweek calculation - used code not working on Python < 3.9 (3.7.3 is the "current" version on Raspberry Pi OS Buster)
+
 ## 2022-11-17
  - fix historic data calculation (until now this was only 'yesterday') did not change to the real "new yesterday" after date rollover
  - add historic data and cost calculation: this week, last week, this month, last month, this year, last year, since last bill

+ 2 - 1
S0Meters_py/s0meters.py

@@ -261,7 +261,8 @@ def processMeterData(data):
         else: 
             # get highest week number of last year
             lastweek_year = year - 1
-            lastyearlastweek = datetime.date.fromisoformat(str(lastweek_year) + "-12-31").isocalendar().week
+            #lastyearlastweek = datetime.date.fromisoformat(str(lastweek_year) + "-12-31").isocalendar().week    #### named tuple output needs python 3.9+, on RPi only 3.7.3 is currently available 
+            lastyearlastweek = datetime.date.fromisoformat(str(lastweek_year) + "-12-31").isocalendar()[1]       ## for Python 3.7.3
             lastweek = lastyearlastweek
         lastweek_d = str(lastweek_year) + "-W" + str(lastweek)
         #lastweek_day1 = datetime.date.fromisocalendar(lastweek_year, lastweek, 1)  # works only from python 3.8 - RPi only has 3.7.3