From 28c2ed9de47692173262c84012ef871c2ffba024 Mon Sep 17 00:00:00 2001 From: Sean Rees Date: Fri, 30 Jul 2021 19:12:14 +0100 Subject: [PATCH] Add support for Pure Cool Formaldehyde fans and bump to 0.3.1 --- BUILD | 2 +- README.md | 1 + metrics.py | 5 +++++ metrics_test.py | 23 +++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 804d9f6..a441c25 100644 --- a/BUILD +++ b/BUILD @@ -112,5 +112,5 @@ pkg_deb( package = "prometheus-dyson", postrm = "debian/postrm", prerm = "debian/prerm", - version = "0.3.0", + version = "0.3.1", ) diff --git a/README.md b/README.md index 214dc4d..d32e275 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/metrics.py b/metrics.py index 4344dc9..0dd8a6c 100644 --- a/metrics.py +++ b/metrics.py @@ -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. @@ -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()) diff --git a/metrics_test.py b/metrics_test.py index a6f3c28..efa5675 100644 --- a/metrics_test.py +++ b/metrics_test.py @@ -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)