Skip to content

Commit

Permalink
Force timestamp timezone to None
Browse files Browse the repository at this point in the history
  • Loading branch information
ttu committed Feb 1, 2025
1 parent 07900a5 commit 36f6ca0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ruuvitag_sensor/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _get_timestamp(self, data: list[str]) -> datetime:
# The timestamp is a 4-byte value after the header byte, in seconds since Unix epoch
timestamp_bytes = bytes.fromhex("".join(data[3:7]))
timestamp = int.from_bytes(timestamp_bytes, "big")
return datetime.fromtimestamp(timestamp)
return datetime.fromtimestamp(timestamp, tz=None)

def _get_temperature(self, data: list[str]) -> Optional[float]:
"""Return temperature in celsius"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_history_decode_real_samples(self):
assert result["temperature"] == 22.75
assert result["humidity"] is None
assert result["pressure"] is None
assert result["timestamp"].timestamp() == datetime(2025, 2, 1, 7, 46, 10).timestamp()
assert result["timestamp"] == datetime(2025, 2, 1, 7, 46, 10)

# Test humidity data
data = bytearray(b':1\x10g\x9d\xb5"\x00\x00\x10\x90')
Expand All @@ -217,7 +217,7 @@ def test_history_decode_real_samples(self):
assert result["humidity"] == 42.4
assert result["temperature"] is None
assert result["pressure"] is None
assert result["timestamp"].timestamp() == datetime(2025, 2, 1, 7, 46, 10).timestamp()
assert result["timestamp"] == datetime(2025, 2, 1, 7, 46, 10)

# Test pressure data
data = bytearray(b':2\x10g\x9d\xb5"\x00\x01\x8b@')
Expand All @@ -226,7 +226,7 @@ def test_history_decode_real_samples(self):
assert result["pressure"] == 35648
assert result["temperature"] is None
assert result["humidity"] is None
assert result["timestamp"].timestamp() == datetime(2025, 2, 1, 7, 46, 10).timestamp()
assert result["timestamp"] == datetime(2025, 2, 1, 7, 46, 10)

def test_history_end_marker(self):
decoder = HistoryDecoder()
Expand Down

0 comments on commit 36f6ca0

Please sign in to comment.