Skip to content

Commit

Permalink
Use the hchr field for Formaldehyde values (#15)
Browse files Browse the repository at this point in the history
Reference discussion link: libdyson-wg/ha-dyson#4

The `hcho` field in MQTT is of an unknown unit/scale and has no known
conversion factor to a known unit. However, it was recently discovered
that `hchr` (referred to as "High Res Formaldehyde" in the android app)
has a clean conversion factor of n/1000 to mg/m^3.
  • Loading branch information
dotvezz authored Jul 6, 2023
1 parent 4229ce3 commit b7ab8b6
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libdyson/cloud/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
from requests.auth import AuthBase, HTTPBasicAuth

from libdyson.exceptions import (
from ..exceptions import (
DysonAuthRequired,
DysonInvalidAccountStatus,
DysonInvalidAuth,
Expand Down
6 changes: 3 additions & 3 deletions libdyson/dyson_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ def warning_code(self) -> str:
return self._get_field_value(self._status, "wacd")

@property
def formaldehyde(self) -> Optional[int]:
def formaldehyde(self) -> Optional[float]:
"""Return formaldehyde reading."""
val = self._get_environmental_field_value("hcho")
val = self._get_environmental_field_value("hchr", divisor=1000)
if val is None:
return None

return int(val)
return float(val)

@property
def humidity(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = libdyson-neon
version = 1.0.2
version = 1.1.0
author = The libdyson Working Group
author_email = [email protected]
license = MIT License
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pure_cool_formaldehyde.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def test_properties(mqtt_client: MockedMQTT):
assert device.particulate_matter_10 == 5
assert device.volatile_organic_compounds == 0.4
assert device.nitrogen_dioxide == 1.1
assert device.formaldehyde == 1
assert device.formaldehyde == 0.002
3 changes: 1 addition & 2 deletions tests/test_pure_cool_missing_env_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_no_hcho(mqtt_client: MockedMQTT):
"p10r": "0009",
"sltm": "OFF",
"hcho": "NONE",
"hchr": "0002",
"hchr": "NONE",
}
}
device.request_environmental_data()
Expand Down Expand Up @@ -92,7 +92,6 @@ def test_missing_data(mqtt_client: MockedMQTT):
"p25r": "0010",
"p10r": "0009",
"sltm": "OFF",
"hchr": "0002",
}
}
device.request_environmental_data()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_purifier_humidify_cool_formaldehyde.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def test_properties(mqtt_client: MockedMQTT):
assert device.particulate_matter_10 == 5
assert device.volatile_organic_compounds == .4
assert device.nitrogen_dioxide == 1.1
assert device.formaldehyde == 1
assert device.formaldehyde == 0.002

0 comments on commit b7ab8b6

Please sign in to comment.