Skip to content

Commit

Permalink
Add support for Pure Cool Formaldehyde fans and bump to 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
seanrees committed Jul 30, 2021
1 parent 65102bd commit 28c2ed9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ pkg_deb(
package = "prometheus-dyson",
postrm = "debian/postrm",
prerm = "debian/prerm",
version = "0.3.0",
version = "0.3.1",
)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dyson_volatile_organic_compounds_units | gauge | all | volatile organic compound
dyson_dust_units | gauge | V1 fans only | dust level (range 0-10)
dyson_pm25_units | gauge | V2 fans only | PM2.5 units (µg/m^3 ?)
dyson_pm10_units | gauge | V2 fans only | PM10 units (µg/m^3 ?)
dyson_formaldehyde_units | gauge | Formaldehyde units only | Formaldehyde/H-CHO units
dyson_nitrogen_oxide_units | gauge | V2 fans only | Nitrogen Oxide (NOx) levels (range 0-10)


Expand Down
5 changes: 5 additions & 0 deletions metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def make_enum(name, documentation, state_cls):
'dyson_pm10_units', 'Level of PM10 particulate matter (V2 units only)')
self.nox = make_gauge('dyson_nitrogen_oxide_units',
'Level of nitrogen oxides (NOx, V2 units only)')
self.formaldehyde = make_gauge(
'dyson_formaldehyde_units', 'Level of formaldehyde/H-CHO (Formaldehyde unit only)')

# Operational State (v1 & v2 common)
# Not included: tilt (known values: "OK", others?), standby_monitoring.
Expand Down Expand Up @@ -235,6 +237,9 @@ def update_v2_environmental(self, name: str, device) -> None:
update_env_gauge(self.voc, name, device.serial, voc)
update_env_gauge(self.nox, name, device.serial, nox)

if isinstance(device, libdyson.DysonPureCoolFormaldehyde):
update_env_gauge(self.formaldehyde, name, device.serial, device.formaldehyde)

def update_common_environmental(self, name: str, device) -> None:
update_gauge(self.last_update_environmental,
name, device.serial, timestamp())
Expand Down
23 changes: 23 additions & 0 deletions metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def test_update_v2_environmental(self):
got = self.registry.get_sample_value(metric, labels)
self.assertEqual(got, want, f'metric {metric}')

def test_update_formaldehyde_environmental(self):
device = libdyson.DysonPureCoolFormaldehyde(
SERIAL, CREDENTIALS, libdyson.DEVICE_TYPE_PURE_COOL_FORMALDEHYDE)
payload = {
'msg': 'ENVIRONMENTAL-CURRENT-SENSOR-DATA',
'time': '2021-03-17T15:09:23.000Z',
'data': {'tact': '2956', 'hact': '0047', 'pm10': '3', 'pm25': 'INIT',
'noxl': 30, 'va10': 'INIT', 'hcho': '0002', 'hchr': '0003',
'sltm': 'OFF'}
}
device._handle_message(payload)

labels = {'name': NAME, 'serial': SERIAL}
self.metrics.update(NAME, device, is_state=False,
is_environmental=True)

cases = {
'dyson_formaldehyde_units': 2,
}
for metric, want in cases.items():
got = self.registry.get_sample_value(metric, labels)
self.assertEqual(got, want, f'metric {metric}')

def test_update_v1_state(self):
device = libdyson.DysonPureHotCoolLink(
SERIAL, CREDENTIALS, libdyson.DEVICE_TYPE_PURE_HOT_COOL_LINK)
Expand Down

0 comments on commit 28c2ed9

Please sign in to comment.