Private GIT

Skip to content
Snippets Groups Projects
Commit e7fbbe5f authored by Sean Rees's avatar Sean Rees
Browse files

Rebase on libpurecool

libpurecoollink hasn't been maintained in 3 years, and in the interim, Dyson
have shutdown the old API endpoint.

libpurecool is a fork and has slightly different conversion behaviour for
temperatures, so adjust the conversions here accordingly.
parent 93fc222a
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ to extend to other fan types (I just don't have one to test). ...@@ -7,7 +7,7 @@ to extend to other fan types (I just don't have one to test).
## Dependencies ## Dependencies
``` ```
pip install libpurecoollink pip install libpurecool
pip install prometheus_client pip install prometheus_client
``` ```
## Metrics ## Metrics
...@@ -57,11 +57,11 @@ optional arguments: ...@@ -57,11 +57,11 @@ optional arguments:
### Scrape Frequency ### Scrape Frequency
I scrape at 15s intervals. Metrics are updated at approximately 30 second I scrape at 15s intervals. Metrics are updated at approximately 30 second
intervals by `libpurecoollink`. intervals by `libpurecool`.
### Other Notes ### Other Notes
`libpurecoollink` by default uses a flavour of mDNS to automatically discover `libpurecool` by default uses a flavour of mDNS to automatically discover
the Dyson fan. This is overridable (but this script doesn't at the moment). the Dyson fan. This is overridable (but this script doesn't at the moment).
The mDNS dependency makes Dockerising this script somewhat challenging at The mDNS dependency makes Dockerising this script somewhat challenging at
the moment. the moment.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"""Exports Dyson Pure Hot+Cool (DysonLink) statistics as Prometheus metrics. """Exports Dyson Pure Hot+Cool (DysonLink) statistics as Prometheus metrics.
This module depends on two libraries to function: This module depends on two libraries to function:
pip install libpurecoollink pip install libpurecool
pip install prometheus_client pip install prometheus_client
""" """
...@@ -16,8 +16,8 @@ import time ...@@ -16,8 +16,8 @@ import time
from typing import Callable from typing import Callable
from libpurecoollink import dyson from libpurecool import dyson
from libpurecoollink import dyson_pure_state from libpurecool import dyson_pure_state
import prometheus_client import prometheus_client
# Rationale: # Rationale:
...@@ -79,7 +79,7 @@ class Metrics(): ...@@ -79,7 +79,7 @@ class Metrics():
if isinstance(message, dyson_pure_state.DysonEnvironmentalSensorState): if isinstance(message, dyson_pure_state.DysonEnvironmentalSensorState):
self.humidity.labels(name=name, serial=serial).set(message.humidity) self.humidity.labels(name=name, serial=serial).set(message.humidity)
self.temperature.labels(name=name, serial=serial).set(message.temperature - 273) self.temperature.labels(name=name, serial=serial).set(message.temperature - 273.2)
self.voc.labels(name=name, serial=serial).set(message.volatil_organic_compounds) self.voc.labels(name=name, serial=serial).set(message.volatil_organic_compounds)
self.dust.labels(name=name, serial=serial).set(message.dust) self.dust.labels(name=name, serial=serial).set(message.dust)
elif isinstance(message, dyson_pure_state.DysonPureHotCoolState): elif isinstance(message, dyson_pure_state.DysonPureHotCoolState):
...@@ -91,11 +91,14 @@ class Metrics(): ...@@ -91,11 +91,14 @@ class Metrics():
speed = -1 speed = -1
self.fan_speed.labels(name=name, serial=serial).set(speed) self.fan_speed.labels(name=name, serial=serial).set(speed)
# Convert from Decicelsius to Kelvin.
heat_target = int(message.heat_target) / 10 - 273.2
self.oscillation.labels(name=name, serial=serial).state(message.oscillation) self.oscillation.labels(name=name, serial=serial).state(message.oscillation)
self.focus_mode.labels(name=name, serial=serial).state(message.focus_mode) self.focus_mode.labels(name=name, serial=serial).state(message.focus_mode)
self.heat_mode.labels(name=name, serial=serial).state(message.heat_mode) self.heat_mode.labels(name=name, serial=serial).state(message.heat_mode)
self.heat_state.labels(name=name, serial=serial).state(message.heat_state) self.heat_state.labels(name=name, serial=serial).state(message.heat_state)
self.heat_target.labels(name=name, serial=serial).set(int(message.heat_target)/10 - 273) self.heat_target.labels(name=name, serial=serial).set(heat_target)
self.quality_target.labels(name=name, serial=serial).set(message.quality_target) self.quality_target.labels(name=name, serial=serial).set(message.quality_target)
self.filter_life.labels(name=name, serial=serial).set(message.filter_life) self.filter_life.labels(name=name, serial=serial).set(message.filter_life)
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment