Skip to content

Commit 65102bd

Browse files
committed
Add a config_builder to replace --create_device_cache
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.
1 parent 89cebac commit 65102bd

File tree

6 files changed

+227
-138
lines changed

6 files changed

+227
-138
lines changed

BUILD

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library")
22
load("@pip//:requirements.bzl", "requirement")
33
load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")
44

5-
py_library(
6-
name = "account",
7-
srcs = ["account.py"],
8-
deps = [
9-
requirement("libdyson"),
10-
],
11-
)
12-
135
py_library(
146
name = "config",
157
srcs = ["config.py"],
@@ -46,18 +38,29 @@ py_binary(
4638
name = "main",
4739
srcs = ["main.py"],
4840
deps = [
49-
":account",
5041
":config",
5142
":metrics",
5243
requirement("prometheus_client"),
5344
requirement("libdyson"),
5445
],
5546
)
5647

48+
py_binary(
49+
name = "config_builder",
50+
srcs = ["config_builder.py"],
51+
deps = [
52+
":config",
53+
requirement("libdyson"),
54+
],
55+
)
56+
5757
pkg_tar(
5858
name = "deb-bin",
5959
# This depends on --build_python_zip.
60-
srcs = [":main"],
60+
srcs = [
61+
":main",
62+
":config_builder"
63+
],
6164
mode = "0755",
6265
package_dir = "/opt/prometheus-dyson/bin",
6366
)
@@ -109,5 +112,5 @@ pkg_deb(
109112
package = "prometheus-dyson",
110113
postrm = "debian/postrm",
111114
prerm = "debian/prerm",
112-
version = "0.2.1",
115+
version = "0.3.0",
113116
)

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ the V1 model (reports VOC and Dust) and the V2 models (those that report
66
PM2.5, PM10, NOx, and VOC). Other Dyson fans may work out of the box or with
77
minor modifications.
88

9-
## Updating instructions for 0.2.0
9+
## Updating instructions from 0.1.x (to 0.2.x or beyond)
1010

1111
Due to changes in Dyson's Cloud API, automatic device detection based on your
1212
Dyson login/password no longer works reliably.
@@ -15,10 +15,8 @@ This means you need to take a _one-time_ manual step to upgrade. The upside
1515
to this is that it removes the runtime dependency on the Dyson API, because
1616
it will cache the device information locally.
1717

18-
The manual step is to run this command and follow the prompts:
19-
```
20-
% /opt/prometheus-dyson/bin/main --create_device_cache
21-
```
18+
Please see the _Usage_ > _Configuration_ > _Automatic Setup_ section below for instructions.
19+
2220

2321
## Build
2422

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

47-
4845
## Metrics
4946

5047
### Environmental
@@ -92,24 +89,36 @@ dyson_continuous_monitoring_mode | gauge | V2 fans only | continuous monitoring
9289
This script reads `config.ini` (or another file, specified with `--config`)
9390
for your DysonLink login credentials.
9491

92+
#### Automatic Setup
93+
94+
TIP: you must do this if you're upgrading from 0.1.x (to 0.2.x or beyond)
95+
96+
prometheus-dyson requires a configuration file to operate. In the Debian-based
97+
installation, this lives in ```/etc/prometheus-dyson/config.ini```.
98+
99+
To generate this configuration, run the config builder, like this:
100+
```
101+
% /opt/prometheus-dyson/bin/config_builder
102+
```
103+
104+
You will need to run this as root (or a user with write permissions to
105+
/etc/prometheus-dyson).
106+
95107
#### Device Configuration
96108

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

101111
```
102112
[XX1-ZZ-ABC1234A]
103-
active = true
104113
name = My Fan
105114
serial = XX1-ZZ-ABC1234A
106-
version = 21.04.03
107115
localcredentials = a_random_looking_string==
108-
autoupdate = True
109-
newversionavailable = True
110116
producttype = 455
111117
```
112118

119+
The ```localcredentials``` field is provided by the Dyson Cloud API, please see
120+
the _Automatic Setup_ section.
121+
113122
#### Manual IP Overrides
114123

115124
By default, fans are auto-detected with Zeroconf. It is possible to provide
@@ -123,16 +132,12 @@ XX1-ZZ-ABC1234A = 10.10.100.55
123132
### Args
124133
```
125134
% ./prometheus_dyson.py --help
126-
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--create_device_cache] [--log_level LOG_LEVEL]
135+
usage: ./prometheus_dyson.py [-h] [--port PORT] [--config CONFIG] [--log_level LOG_LEVEL]
127136
128137
optional arguments:
129138
-h, --help show this help message and exit
130139
--port PORT HTTP server port
131140
--config CONFIG Configuration file (INI file)
132-
--create_device_cache
133-
Performs a one-time login to Dyson's cloud service to identify your devices. This produces
134-
a config snippet to add to your config, which will be used to connect to your device. Use
135-
this when you first use this program and when you add or remove devices.
136141
--log_level LOG_LEVEL
137142
Logging level (DEBUG, INFO, WARNING, ERROR)
138143
```

account.py

Lines changed: 0 additions & 83 deletions
This file was deleted.

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def dyson_credentials(self) -> Optional[DysonLinkCredentials]:
6060
country = self._config['Dyson Link']['country']
6161
return DysonLinkCredentials(username, password, country)
6262
except KeyError as ex:
63-
logging.critical(
63+
logging.warning(
6464
'Required key missing in "%s": %s', self._filename, ex)
6565
return None
6666

0 commit comments

Comments
 (0)