Skip to content

Commit

Permalink
Bump release to 0.2.0; finish conversion to libdyson
Browse files Browse the repository at this point in the history
This converts metrics.py over to use libdyson \o/ and removes the now no-longer
required libpurecool_adapter. This change also adds automatic reconnection to
devices if they disconnect.
  • Loading branch information
seanrees committed Mar 19, 2021
1 parent 792f39c commit f4c1d21
Show file tree
Hide file tree
Showing 9 changed files with 503 additions and 476 deletions.
30 changes: 6 additions & 24 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,11 @@ py_test(
],
)

py_library(
name = "libpurecool_adapter",
srcs = ["libpurecool_adapter.py"],
deps = [
requirement("libpurecool"),
],
)

py_test(
name = "libpurecool_adapter_test",
srcs = ["libpurecool_adapter_test.py"],
deps = [
":libpurecool_adapter",
requirement("libpurecool"),
],
)

py_library(
name = "metrics",
srcs = ["metrics.py"],
deps = [
requirement("libpurecool"),
requirement("libdyson"),
requirement("prometheus_client"),
],
)
Expand All @@ -54,7 +37,7 @@ py_test(
srcs = ["metrics_test.py"],
deps = [
":metrics",
requirement("libpurecool"),
requirement("libdyson"),
requirement("prometheus_client"),
],
)
Expand All @@ -65,7 +48,6 @@ py_binary(
deps = [
":account",
":config",
":libpurecool_adapter",
":metrics",
requirement("prometheus_client"),
requirement("libdyson"),
Expand All @@ -92,15 +74,15 @@ pkg_tar(
srcs = ["debian/prometheus-dyson"],
mode = "0644",
package_dir = "/etc/default",
strip_prefix = "debian/",
strip_prefix = "/debian",
)

pkg_tar(
name = "deb-service",
srcs = ["debian/prometheus-dyson.service"],
mode = "0644",
package_dir = "/lib/systemd/system",
strip_prefix = "debian/",
strip_prefix = "/debian",
)

pkg_tar(
Expand All @@ -115,7 +97,7 @@ pkg_tar(

pkg_deb(
name = "main-deb",
# libpurecool has native deps.
# libdyson includes native deps.
architecture = "amd64",
built_using = "bazel",
data = ":debian-data",
Expand All @@ -127,5 +109,5 @@ pkg_deb(
package = "prometheus-dyson",
postrm = "debian/postrm",
prerm = "debian/prerm",
version = "0.1.1",
version = "0.2.0",
)
61 changes: 49 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ the V1 model (reports VOC and Dust) and the V2 models (those that report
PM2.5, PM10, NOx, and VOC). Other Dyson fans may work out of the box or with
minor modifications.

## Updating instructions for 0.2.0

Due to changes in Dyson's Cloud API, automatic device detection based on your
Dyson login/password no longer works reliably.

This means you need to take a _one-time_ manual step to upgrade. The upside
to this is that it removes the runtime dependency on the Dyson API, because
it will cache the device information locally.

The manual step is to run this command and follow the prompts:
```
% /opt/prometheus-dyson/bin/main --create_device_cache
```

## Build

```
Expand All @@ -26,7 +40,7 @@ directory). This is _optional_ and not required.
You'll need these dependencies:

```
% pip install libpurecool
% pip install libdyson
% pip install prometheus_client
```

Expand Down Expand Up @@ -78,33 +92,56 @@ dyson_continuous_monitoring_mode | gauge | V2 fans only | continuous monitoring
This script reads `config.ini` (or another file, specified with `--config`)
for your DysonLink login credentials.

#### Device Configuration

Devices must be specifically listed in your `config.ini`. You can create this
automatically by running the binary with `--create_device_cache` and following
the prompts. A device entry looks like this:

```
[XX1-ZZ-ABC1234A]
active = true
name = My Fan
serial = XX1-ZZ-ABC1234A
version = 21.04.03
localcredentials = a_random_looking_string==
autoupdate = True
newversionavailable = True
producttype = 455
```

#### Manual IP Overrides

By default, fans are auto-detected with Zeroconf. It is possible to provide
manual IP overrides in the configuraton however in the `Hosts` section.

```
[Hosts]
XX1-ZZ-ABC1234A = 10.10.100.55
```

### Args
```
% ./prometheus_dyson.py --help
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--log_level LOG_LEVEL] [--include_inactive_devices]
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--create_device_cache] [--log_level LOG_LEVEL]
optional arguments:
-h, --help show this help message and exit
--port PORT HTTP server port
--config CONFIG Configuration file (INI file)
--create_device_cache
Performs a one-time login to Dyson's cloud service to identify your devices. This produces
a config snippet to add to your config, which will be used to connect to your device. Use
this when you first use this program and when you add or remove devices.
--log_level LOG_LEVEL
Logging level (DEBUG, INFO, WARNING, ERROR)
--include_inactive_devices
Monitor devices marked as inactive by Dyson (default is only active)
```

### Scrape Frequency

Metrics are updated at approximately 30 second intervals by `libpurecool`.
Environmental metrics are updated at approximately 30 second intervals.
Fan state changes (e.g; FAN -> HEAT) are published ~immediately on change.

### Other Notes

`libpurecool` by default uses a flavour of mDNS to automatically discover
the Dyson fan. If automatic discovery isn't available on your network, it is possible
to specify IP addresses mapped to device serial numbers in config.ini - see
`config-sample.ini` for usage.

## Dashboard

I've provided a sample Grafana dashboard in `grafana.json`.
7 changes: 4 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ pip_install(
)

# Packaging rules.
#load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_pkg",
urls = [
"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.6-1/rules_pkg-0.2.6.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.6/rules_pkg-0.2.6.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
],
sha256 = "aeca78988341a2ee1ba097641056d168320ecc51372ef7ff8e64b139516a4937",
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
)
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
47 changes: 0 additions & 47 deletions libpurecool_adapter.py

This file was deleted.

31 changes: 0 additions & 31 deletions libpurecool_adapter_test.py

This file was deleted.

Loading

0 comments on commit f4c1d21

Please sign in to comment.