Skip to content

Commit

Permalink
Merge pull request #106 from mattes-bru/environment-min-max
Browse files Browse the repository at this point in the history
added min max temperatures to environment data
  • Loading branch information
tuna-f1sh authored Aug 6, 2024
2 parents 4d4ff27 + 823e9f5 commit 2e63186
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions openant/devices/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class EnvironmentData(DeviceData):
"""ANT+ environment data."""

temperature: float = field(default=-1, metadata={"unit": "C"})
min_24h_temperature: float = field(default=-1, metadata={"unit": "C"})
max_24h_temperature: float = field(default=-1, metadata={"unit": "C"})


class Environment(AntPlusDevice):
Expand Down Expand Up @@ -43,8 +45,16 @@ def on_data(self, data):
if page == 1:
# Data page 1, temperature info
# bytes 6,7 indicate temperature, LSB first
low_msn = (data[4] & 0xF0)>>4
high_lsn = (data[4] & 0x0F)<<4
self.data["environment"].temperature = (
int.from_bytes(data[6:8], byteorder="little") * 0.01
)
self.data["environment"].min_24h_temperature = (
int.from_bytes([data[3], low_msn], byteorder="little") * 0.1
)
self.data["environment"].max_24h_temperature = (
(int.from_bytes([data[5],high_lsn], byteorder="big")>>4) * 0.1
)

self.on_device_data(page, "environment", self.data["environment"])

0 comments on commit 2e63186

Please sign in to comment.