Skip to content
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
11 changes: 11 additions & 0 deletions disruptive/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class Temperature(_EventData):
Temperature value in Fahrenheit.
samples : list[TemperatureSample]
Temperature values sampled over a single heartbeat.
is_backfilled : bool
Indicates if the temperature event is backfilled.
timestamp : datetime
Timestamp of when the event was received by a Cloud Connector.

Expand All @@ -243,6 +245,7 @@ class Temperature(_EventData):
def __init__(self,
celsius: float,
samples: Optional[list] = None,
is_backfilled: Optional[bool] = None,
timestamp: Optional[datetime | str] = None,
) -> None:
"""
Expand All @@ -255,6 +258,8 @@ def __init__(self,
Temperature value in Celsius.
samples : list[TemperatureSample]
Temperature values sampled over a single heartbeat.
is_backfilled : bool
Indicates if the temperature event is backfilled.
timestamp : datetime, str, optional
Timestamp in either datetime or string iso8601 format
(i.e. yyyy-MM-ddTHH:mm:ssZ).
Expand All @@ -265,6 +270,7 @@ def __init__(self,
self.celsius: float = celsius
self.samples: Optional[list] = samples
self.fahrenheit: float = dttrans._celsius_to_fahrenheit(celsius)
self.is_backfilled: Optional[bool] = is_backfilled
self.timestamp: Optional[datetime | str] = timestamp

# Inherit parent _EventData class init with repacked data dictionary.
Expand All @@ -274,13 +280,15 @@ def __repr__(self) -> str:
string = '{}.{}('\
'celsius={}, '\
'samples={}, '\
'is_backfilled={}, '\
'timestamp={}'\
')'
return string.format(
self.__class__.__module__,
self.__class__.__name__,
self.celsius,
self.samples,
self.is_backfilled,
repr(dttrans.to_iso8601(self.timestamp)),
)

Expand Down Expand Up @@ -313,6 +321,7 @@ def _from_raw(cls, data: dict) -> Temperature:
obj = cls(
celsius=data['value'],
samples=sample_objs,
is_backfilled=data['isBackfilled'],
timestamp=data['updateTime'],
)

Expand All @@ -327,6 +336,8 @@ def __repack(self) -> dict:
data['value'] = self.celsius
if self.samples is not None:
data['samples'] = [s._raw for s in self.samples]
if self.is_backfilled is not None:
data['isBackfilled'] = self.is_backfilled
if self.timestamp is not None:
data['updateTime'] = self.timestamp
return data
Expand Down
5 changes: 4 additions & 1 deletion tests/api_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
},
"temperature": {
"value": -27,
"isBackfilled": False,
"samples": [
{
"value": -27,
Expand Down Expand Up @@ -661,6 +662,7 @@
"data": {
"temperature": {
"value": 24.9,
"isBackfilled": False,
"samples": [
{
"value": 24.9,
Expand Down Expand Up @@ -908,7 +910,8 @@
b'"d1vtobtd83ut9sd2bj9g","targetName":"projects/914u9p094l47cdv1o3pg'\
b'/devices/emui17m69nlq0bgk44smcng","eventType":"temperature","data"'\
b':{"temperature":{"value":5,"updateTime":"2021-04-21T08:'\
b'15:43.512330Z","samples":[{"value":5,"sampleTime":"2021-04-21T08:'\
b'15:43.512330Z","isBackfilled":"False",'\
b'"samples":[{"value":5,"sampleTime":"2021-04-21T08:'\
b'15:43.512330Z"}]}},"timestamp":"2021-04-21T08:15:43.512330Z"}}}'

stream_networkstatus_event = b'{"result":{"event":{"eventId":"c1vtubtd83it'\
Expand Down
1 change: 1 addition & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def test_touch(self):
def test_temperature(self):
x = disruptive.events.Temperature(
celsius=23,
is_backfilled=False,
timestamp=datetime.now(),
)

Expand Down