Skip to content
Open
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
44 changes: 40 additions & 4 deletions airthings_ble/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,46 @@
Keep measuring. If levels are maintained for more than 1 month,
contact a professional radon mitigator.
"""
VERY_LOW = (0, 49, "very low")
LOW = (50, 99, "low")
MODERATE = (100, 299, "moderate")
HIGH = (300, None, "high")
RADON_VERY_LOW = (0, 49, "very low")
RADON_LOW = (50, 99, "low")
RADON_MODERATE = (100, 299, "moderate")
RADON_HIGH = (300, None, "high")

"""
0 - 249 ppb
The VOC contents in the air are low.
250 - 1999 ppb
Look for VOC sources if this average level persists for a month
2000 ppb and up
The VOC contents are very high - consider taking action/ventilating right now
"""
VOC_LOW = (0, 249, "low")
VOC_MODERATE = (250, 1999, "moderate")
VOC_VERY_HIGH = (2000, None, "very high")

"""
250 - 399 ppm
Normal background concentration in outdoor ambient air
400 - 999 ppm
Concentrations typical of occupied indoor spaces with good air exchange.
1000 - 1999 ppm
Complaints of drowsiness and poor air
2000 - 4999 ppm
Headaches, sleepiness and stagnant, stale, stuffy air. Poor concentration, loss
of attention, increased heart rate and slight nausea.
5000 - 39999 ppm
Extremely high
40000 and up
Exposure may lead to serious oxygen deprivation resulting in permanent brain
damage, coma and even death.
"""
CO2_LOW = (0, 249, "low")
CO2_OUTDOOR_NORMAL = (250, 399, "outdoor normal")
CO2_INDOOR_NORMAL = (400, 999, "indoor normal")
CO2_HIGH = (1000, 1999, "high")
CO2_VERY_HIGH = (2000, 4999, "very high")
CO2_EXTREMELLY_HIGH = (5000, 39999, "extremelly high")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CO2_EXTREMELLY_HIGH = (5000, 39999, "extremelly high")
CO2_EXTREMELY_HIGH = (5000, 39999, "extremely high")

CO2_CRITICAL = (40000, None, "critical")

BQ_TO_PCI_MULTIPLIER = 0.027

Expand Down
65 changes: 54 additions & 11 deletions airthings_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,30 @@
CHAR_UUID_WAVE_2_DATA,
CHAR_UUID_WAVE_PLUS_DATA,
CHAR_UUID_WAVEMINI_DATA,
CO2_CRITICAL,
CO2_EXTREMELLY_HIGH,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CO2_EXTREMELLY_HIGH,
CO2_EXTREMELY_HIGH,

CO2_HIGH,
CO2_INDOOR_NORMAL,
CO2_LOW,
CO2_MAX,
CO2_OUTDOOR_NORMAL,
CO2_VERY_HIGH,
COMMAND_UUID_WAVE_2,
COMMAND_UUID_WAVE_MINI,
COMMAND_UUID_WAVE_PLUS,
HIGH,
LOW,
MODERATE,
PERCENTAGE_MAX,
PRESSURE_MAX,
RADON_HIGH,
RADON_LOW,
RADON_MAX,
RADON_MODERATE,
RADON_VERY_LOW,
TEMPERATURE_MAX,
UPDATE_TIMEOUT,
VERY_LOW,
VOC_LOW,
VOC_MAX,
VOC_MODERATE,
VOC_VERY_HIGH,
)
from .device_type import AirthingsDeviceType

Expand Down Expand Up @@ -379,16 +389,43 @@ async def wait_for_message(self, timeout: float) -> None:

def get_radon_level(data: float) -> str:
"""Returns the applicable radon level"""
if data <= VERY_LOW[1]:
radon_level = VERY_LOW[2]
elif data <= LOW[1]:
radon_level = LOW[2]
elif data <= MODERATE[1]:
radon_level = MODERATE[2]
if data <= RADON_VERY_LOW[1]:
radon_level = RADON_VERY_LOW[2]
elif data <= RADON_LOW[1]:
radon_level = RADON_LOW[2]
elif data <= RADON_MODERATE[1]:
radon_level = RADON_MODERATE[2]
else:
radon_level = HIGH[2]
radon_level = RADON_HIGH[2]
return radon_level

def get_voc_level(data: float) -> str:
"""Returns the applicable voc level"""
if data <= VOC_LOW[1]:
voc_level = VOC_LOW[2]
elif data <= VOC_MODERATE[1]:
voc_level = VOC_MODERATE[2]
else:
voc_level = VOC_VERY_HIGH[2]
return voc_level

def get_co2_level(data: float) -> str:
"""Returns the applicable co2 level"""
if data <= CO2_LOW[1]:
co2_level = CO2_LOW[2]
elif data <= CO2_OUTDOOR_NORMAL[1]:
co2_level = CO2_OUTDOOR_NORMAL[2]
elif data <= CO2_INDOOR_NORMAL[1]:
co2_level = CO2_INDOOR_NORMAL[2]
elif data <= CO2_HIGH[1]:
co2_level = CO2_HIGH[2]
elif data <= CO2_VERY_HIGH[1]:
co2_level = CO2_VERY_HIGH[2]
elif data <= CO2_EXTREMELLY_HIGH[1]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif data <= CO2_EXTREMELLY_HIGH[1]:
elif data <= CO2_EXTREMELY_HIGH[1]:

co2_level = CO2_EXTREMELLY_HIGH[2]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
co2_level = CO2_EXTREMELLY_HIGH[2]
co2_level = CO2_EXTREMELY_HIGH[2]

else:
co2_level = CO2_CRITICAL[2]
return co2_level

sensor_decoders: dict[
str,
Expand Down Expand Up @@ -613,6 +650,12 @@ async def _get_service_characteristics(
float(d) * BQ_TO_PCI_MULTIPLIER
)

if (d := sensor_data.get("voc")) is not None:
sensors["voc_level"] = get_voc_level(float(d))

if (d := sensor_data.get("co2")) is not None:
sensors["co2_level"] = get_co2_level(float(d))

if uuid_str in command_decoders:
decoder = command_decoders[uuid_str]
command_data_receiver = decoder.make_data_receiver()
Expand Down