Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add max_date to Home Assistant WS import #488

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.exemple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ home_assistant_ws: # FOR ENERGY TAB
ssl: true
token: HOME_ASSISTANT_TOKEN_GENERATE_IN_PROFILE_TABS_(BOTTOM)
url: myhomeassistant.domain.fr
max_date: "2021-06-01"
ssl:
gateway: true
certfile: ""
Expand Down
18 changes: 17 additions & 1 deletion src/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,10 +1131,26 @@
table = ProductionDetail
relation = UsagePoints.relation_production_detail
sort = asc("date") if order_dir == "desc" else desc("date")
if begin is None or end is None:
if begin is None and end is None:
return self.session.scalars(
select(table).join(relation).where(table.usage_point_id == usage_point_id).order_by(sort)
).all()
elif begin is not None and end is None:
return self.session.scalars(

Check warning on line 1139 in src/models/database.py

View check run for this annotation

Codecov / codecov/patch

src/models/database.py#L1139

Added line #L1139 was not covered by tests
select(table)
.join(relation)
.where(table.usage_point_id == usage_point_id)
.filter(table.date >= begin)
.order_by(sort)
).all()
elif end is not None and begin is None:
return self.session.scalars(

Check warning on line 1147 in src/models/database.py

View check run for this annotation

Codecov / codecov/patch

src/models/database.py#L1147

Added line #L1147 was not covered by tests
select(table)
.join(relation)
.where(table.usage_point_id == usage_point_id)
.filter(table.date <= end)
.order_by(sort)
).all()
else:
return self.session.scalars(
select(table)
Expand Down
7 changes: 6 additions & 1 deletion src/models/export_home_assistant_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@
if self.usage_point_id_config.consumption_detail:
logging.info("Consommation")
measure_type = "consumption"
detail = DB.get_detail_all(self.usage_point_id, order_dir="desc")
if "max_date" in self.config:
logging.warn(f"WARNING : Max date détecter {self.config['max_date']}")
begin = datetime.strptime(self.config["max_date"], "%Y-%m-%d")
detail = DB.get_detail_all(begin=begin, usage_point_id=self.usage_point_id, order_dir="desc")

Check warning on line 149 in src/models/export_home_assistant_ws.py

View check run for this annotation

Codecov / codecov/patch

src/models/export_home_assistant_ws.py#L146-L149

Added lines #L146 - L149 were not covered by tests
else:
detail = DB.get_detail_all(self.usage_point_id, order_dir="desc")

Check warning on line 151 in src/models/export_home_assistant_ws.py

View check run for this annotation

Codecov / codecov/patch

src/models/export_home_assistant_ws.py#L151

Added line #L151 was not covered by tests

cost = 0
last_year = None
Expand Down
Loading