Skip to content

Commit

Permalink
Add a config_builder to replace --create_device_cache
Browse files Browse the repository at this point in the history
The config builder is capable of both initial and re-builds of the config, and
can also directly write to the configuration file (as opposed to relying on the
user to copy-paste). It's also a separate binary and no-longer (buggily)
plumbed through main.py.
  • Loading branch information
seanrees committed Apr 23, 2021
1 parent 89cebac commit 65102bd
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 138 deletions.
25 changes: 14 additions & 11 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@pip//:requirements.bzl", "requirement")
load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")

py_library(
name = "account",
srcs = ["account.py"],
deps = [
requirement("libdyson"),
],
)

py_library(
name = "config",
srcs = ["config.py"],
Expand Down Expand Up @@ -46,18 +38,29 @@ py_binary(
name = "main",
srcs = ["main.py"],
deps = [
":account",
":config",
":metrics",
requirement("prometheus_client"),
requirement("libdyson"),
],
)

py_binary(
name = "config_builder",
srcs = ["config_builder.py"],
deps = [
":config",
requirement("libdyson"),
],
)

pkg_tar(
name = "deb-bin",
# This depends on --build_python_zip.
srcs = [":main"],
srcs = [
":main",
":config_builder"
],
mode = "0755",
package_dir = "/opt/prometheus-dyson/bin",
)
Expand Down Expand Up @@ -109,5 +112,5 @@ pkg_deb(
package = "prometheus-dyson",
postrm = "debian/postrm",
prerm = "debian/prerm",
version = "0.2.1",
version = "0.3.0",
)
41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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
## Updating instructions from 0.1.x (to 0.2.x or beyond)

Due to changes in Dyson's Cloud API, automatic device detection based on your
Dyson login/password no longer works reliably.
Expand All @@ -15,10 +15,8 @@ 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
```
Please see the _Usage_ > _Configuration_ > _Automatic Setup_ section below for instructions.


## Build

Expand All @@ -44,7 +42,6 @@ You'll need these dependencies:
% pip install prometheus_client
```


## Metrics

### Environmental
Expand Down Expand Up @@ -92,24 +89,36 @@ 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.

#### Automatic Setup

TIP: you must do this if you're upgrading from 0.1.x (to 0.2.x or beyond)

prometheus-dyson requires a configuration file to operate. In the Debian-based
installation, this lives in ```/etc/prometheus-dyson/config.ini```.

To generate this configuration, run the config builder, like this:
```
% /opt/prometheus-dyson/bin/config_builder
```

You will need to run this as root (or a user with write permissions to
/etc/prometheus-dyson).

#### 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:
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
```

The ```localcredentials``` field is provided by the Dyson Cloud API, please see
the _Automatic Setup_ section.

#### Manual IP Overrides

By default, fans are auto-detected with Zeroconf. It is possible to provide
Expand All @@ -123,16 +132,12 @@ XX1-ZZ-ABC1234A = 10.10.100.55
### Args
```
% ./prometheus_dyson.py --help
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--create_device_cache] [--log_level LOG_LEVEL]
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--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)
```
Expand Down
83 changes: 0 additions & 83 deletions account.py

This file was deleted.

2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def dyson_credentials(self) -> Optional[DysonLinkCredentials]:
country = self._config['Dyson Link']['country']
return DysonLinkCredentials(username, password, country)
except KeyError as ex:
logging.critical(
logging.warning(
'Required key missing in "%s": %s', self._filename, ex)
return None

Expand Down
Loading

0 comments on commit 65102bd

Please sign in to comment.