Skip to content

Commit

Permalink
Merge pull request #473 from vingerha/main
Browse files Browse the repository at this point in the history
Replacing 'year'-number with 'current' in case it is current year
  • Loading branch information
m4dm4rtig4n authored Jan 27, 2024
2 parents 810742c + 4fd6afa commit b3bda75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/models/export_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def daily_annual(self, price, measurement_direction="consumption"):
get_daily_year = stat.get_year(year=year)
get_daily_month = stat.get_month(year=year)
get_daily_week = stat.get_week(year=year)
sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/{year}"
if year == int(datetime.now().strftime("%Y")):
sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/current"
else:
sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/{year}"
mqtt_data = {
# thisYear
f"{sub_prefix}/thisYear/dateBegin": get_daily_year["begin"],
Expand Down Expand Up @@ -247,7 +250,10 @@ def detail_annual(self, price_hp, price_hc=0, measurement_direction="consumption
measure_type="HC",
)

sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/{year}"
if year == int(datetime.now().strftime("%Y")):
sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/current"
else:
sub_prefix = f"{self.usage_point_id}/{measurement_direction}/annual/{year}"
mqtt_data = {
# thisYear - HP
f"{sub_prefix}/thisYear/hp/Wh": get_detail_year_hp["value"],
Expand Down Expand Up @@ -460,6 +466,8 @@ def tempo(self):
mqtt_data[f"tempo/color/tomorrow"] = tempo_color[0].color
if tempo_data:
for year, data in ast.literal_eval(tempo_data[0].value).items():
if year == datetime.now().strftime("%Y"):
year = "current"
for color, tempo in data["TEMPO"].items():
mqtt_data[f"{self.usage_point_id}/consumption/annual/{year}/thisYear/tempo/{color}/Wh"] = round(
tempo["Wh"], 2
Expand Down
14 changes: 8 additions & 6 deletions src/models/export_mqttv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ def daily_annual(self, price):
date_begin_current = datetime.combine(date_end.replace(month=1).replace(day=1), datetime.min.time())
finish = False
while not finish:
sub_prefix = (
f"{self.usage_point_id}/{self.measurement_direction}/annual/{date_begin_current.strftime('%Y')}"
)
if date_begin_current.strftime('%Y') == datetime.now().strftime("%Y"):
sub_prefix = f"{self.usage_point_id}/{self.measurement_direction}/annual/current"
else:
sub_prefix = f"{self.usage_point_id}/{self.measurement_direction}/annual/{date_begin_current.strftime('%Y')}"
self.load_daily_data(date_begin_current, date_end, price, sub_prefix)
# CALCUL NEW DATE
if date_begin_current == date_begin:
Expand Down Expand Up @@ -391,9 +392,10 @@ def detail_annual(self, price_hp, price_hc=0):
date_begin_current = datetime.combine(date_end.replace(month=1).replace(day=1), datetime.min.time())
finish = False
while not finish:
sub_prefix = (
f"{self.usage_point_id}/{self.measurement_direction}/annual/{date_begin_current.strftime('%Y')}"
)
if date_begin_current.strftime('%Y') == datetime.now().strftime("%Y"):
sub_prefix = f"{self.usage_point_id}/{self.measurement_direction}/annual/current"
else:
sub_prefix = f"{self.usage_point_id}/{self.measurement_direction}/annual/{date_begin_current.strftime('%Y')}"
self.load_detail_data(date_begin_current, date_end, price_hp, price_hc, sub_prefix)
# CALCUL NEW DATE
if date_begin_current == date_begin:
Expand Down

0 comments on commit b3bda75

Please sign in to comment.