Skip to content

Commit

Permalink
fix: pass datetime to base device
Browse files Browse the repository at this point in the history
  • Loading branch information
EuleMitKeule committed Apr 29, 2023
1 parent a3fead6 commit 0cfbf37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions estimenergy/devices/base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,49 @@ async def increment(
self,
metric: Metric,
value: float,
date: datetime.datetime = datetime.datetime.now(),
value_dt: datetime.datetime = datetime.datetime.now(),
):
"""Increment a metric in the database."""

if metric not in self.provided_metrics:
raise ValueError(f"Metric {metric} not provided by this device.")

for data_service in self.data_services:
await data_service.increment(metric, value, date)
await data_service.increment(metric, value, value_dt)

async def decrement(
self,
metric: Metric,
value: float,
date: datetime.datetime = datetime.datetime.now(),
value_dt: datetime.datetime = datetime.datetime.now(),
):
"""Decrement a metric in the database."""

if metric not in self.provided_metrics:
raise ValueError(f"Metric {metric} not provided by this device.")

for data_service in self.data_services:
await data_service.decrement(metric, value, date)
await data_service.decrement(metric, value, value_dt)

async def write(
self,
metric: Metric,
value: float,
date: datetime.datetime = datetime.datetime.now(),
value_dt: datetime.datetime = datetime.datetime.now(),
):
"""Write a metric to the database."""

if metric not in self.provided_metrics:
raise ValueError(f"Metric {metric} not provided by this device.")

for data_service in self.data_services:
await data_service.write(metric, value, date)
await data_service.write(metric, value, value_dt)

async def update(
self,
date: datetime.datetime = datetime.datetime.now(),
value_dt: datetime.datetime = datetime.datetime.now(),
):
"""Calculate metrics based on other metrics."""

for data_service in self.data_services:
await data_service.update(date)
await data_service.update(value_dt)
5 changes: 4 additions & 1 deletion estimenergy/devices/glow_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ async def __on_total_kwh_changed(self, value: float):
)

await self.increment(
Metric(MetricType.ENERGY, MetricPeriod.DAY, False, False), kwh_increase
Metric(MetricType.ENERGY, MetricPeriod.DAY, False, False),
kwh_increase,
time,
)
await self.increment(
Metric(MetricType.ACCURACY, MetricPeriod.DAY, False, False),
accuracy_increase,
time,
)

await self.update()
Expand Down

0 comments on commit 0cfbf37

Please sign in to comment.