Skip to content

Commit 3ca78b3

Browse files
committed
Added datacontainer to save energy measurement data for Crownstones.
1 parent e48458a commit 3ca78b3

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

crownstone_cloud/cloud_models/crownstones.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Crownstone handler for Crownstone cloud data"""
2+
import logging
3+
from typing import Dict, Any
4+
25
from crownstone_cloud.const import DIMMING_ABILITY
36
from crownstone_cloud.exceptions import (
47
CrownstoneAbilityError,
58
AbilityError
69
)
7-
from typing import Dict, Any
8-
import logging
10+
from crownstone_cloud.helpers.containers import EnergyData
911

1012
_LOGGER = logging.Logger(__name__)
1113

@@ -113,8 +115,9 @@ def __init__(self, cloud, data: Dict[str, Any]) -> None:
113115
self.abilities: Dict[str, CrownstoneAbility] = {}
114116
# power usage (W)
115117
self.power_usage = 0
116-
# energy usage (kWh)
117-
self.energy_usage = 0
118+
# energy usage data object
119+
# initially defined with 0 Joule and no timestamp
120+
self.energy_usage = EnergyData(0, None)
118121

119122
@property
120123
def name(self) -> str:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Contains classes that only hold data."""
2+
3+
4+
class EnergyData:
5+
"""Data class that holds energy measurements"""
6+
7+
def __init__(self, accumulated_energy: int, utc_timestamp: int) -> None:
8+
"""Initialize the object."""
9+
# new value obtained from Crownstone USB Dongle (or other source)
10+
self.energy_usage = accumulated_energy
11+
12+
# the new energy usage value (after adding the offset or previous value)
13+
self.corrected_energy_usage = 0
14+
15+
# timestamp of the measurement in UTC
16+
self.timestamp = utc_timestamp

0 commit comments

Comments
 (0)