Skip to content

Commit

Permalink
Merge pull request #439 from vingerha/0.9.3
Browse files Browse the repository at this point in the history
Add daily week tempo color values to sensor, for use in linky card (and other)
  • Loading branch information
m4dm4rtig4n authored Dec 9, 2023
2 parents 09f2c4d + 6ad5b52 commit 7bc5939
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/export_home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,15 @@ def myelectricaldata_usage_point_id(self, measurement_direction):
stats.max_power_over(5)["value"],
stats.max_power_over(6)["value"],
],
"dailyweek_Tempo": [
stats.tempo_color(0)["value"],
stats.tempo_color(1)["value"],
stats.tempo_color(2)["value"],
stats.tempo_color(3)["value"],
stats.tempo_color(4)["value"],
stats.tempo_color(5)["value"],
stats.tempo_color(6)["value"],
],
"monthly_evolution": round(monthly_evolution, 2),
"current_week_evolution": round(current_week_evolution, 2),
"current_month_evolution": round(current_month_evolution, 2),
Expand Down
15 changes: 15 additions & 0 deletions app/models/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ def tempo(self, index):
"end": end.strftime(self.date_format)
}

def tempo_color(self, index=0):
now_date = datetime.now(timezone.utc)
yesterday_date = datetime.combine(now_date - relativedelta(days=1), datetime.max.time())
begin = datetime.combine(yesterday_date - timedelta(days=index), datetime.min.time())
end = datetime.combine(begin, datetime.max.time())
value = ""
for data in self.db.get_tempo_range(begin, end):
logging.info(f"tempo data: {data}")
value = value + data.color
return {
"value": value,
"begin": begin.strftime(self.date_format),
"end": end.strftime(self.date_format)
}

def max_power(self, index=0):
now_date = datetime.now(timezone.utc)
yesterday_date = datetime.combine(now_date - relativedelta(days=1), datetime.max.time())
Expand Down

0 comments on commit 7bc5939

Please sign in to comment.