Skip to content

Commit

Permalink
Release 0.2.0 (#32)
Browse files Browse the repository at this point in the history
* Bump version numbers

* Print the http server host/port

* update known issues

* document the http server
  • Loading branch information
mikekap committed Jan 24, 2021
1 parent 5431b53 commit 028dd42
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 19 deletions.
461 changes: 461 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Next

## 0.2.0
- Add HTTP server running on port 3000. You can toggle stuff on it!
- Crash when the message queue is full, in the hopes that the supervisor restarts us. rumqttc seems to have issues reconnecting sometimes.
- Broadcast discovery info every time we connect to the mqtt server.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["strip"]

[package]
name = "wink-mqtt-rs"
version = "0.2.0-prerelease"
version = "0.2.0"
authors = ["Mike Kaplinskiy <mike.kaplinskiy@gmail.com>"]
edition = "2018"
license = "CC-BY-4.0"
Expand Down
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ You can configure more options by editing the `/opt/wink-mqtt-rs/config` file af

## Usage
```bash
wink-mqtt-rs 0.1.5
wink-mqtt-rs 0.2.0
Mike Kaplinskiy <mike.kaplinskiy@gmail.com>
wink hub v1 mqtt bridge

USAGE:
wink-mqtt-rs [FLAGS] [OPTIONS] -s <mqtt-uri>
wink-mqtt-rs [FLAGS] [OPTIONS]

FLAGS:
-h, --help Prints help information
Expand All @@ -34,16 +34,23 @@ FLAGS:

OPTIONS:
--discovery-listen-topic <discovery-listen-topic>
Topic to listen to in order to (re)broadcast discovery information. Only applies if --discovery-prefix is
set. [default: homeassistant/status]
Topic to listen to in order to (re)broadcast discovery information. Only applies if
--discovery-prefix is set. [default: homeassistant/status]

-d <discovery-prefix>
Prefix (applied independently of --topic-prefix) to broadcast mqtt discovery information (see
https://www.home-assistant.io/docs/mqtt/discovery/)
Prefix (applied independently of --topic-prefix) to broadcast mqtt discovery information
(see https://www.home-assistant.io/docs/mqtt/discovery/)

--http-port <http-port>
If you'd like an http server, this is the port on which to start it [default: 3000]
-s <mqtt-uri>
mqtt server to connect to. Should be of the form
mqtt[s]://[username:password@]host:port/[?connection_options]
-i <resync-interval>
how frequently to check if the light changed state (e.g. via Wink or other external means) [default: 10000]
how frequently to check if the light changed state (e.g. via Wink or other external
means) [default: 10000]
-t <topic-prefix>
Prefix for the mqtt topic used for device status/control [default: home/wink/]
Expand All @@ -64,13 +71,23 @@ If you have a topic prefix of `home/wink/`, and a device id with `1` named `Fan`
Messages on the discovery topic follow a format that works with home assistant MQTT discovery. For details, see [converter.rs](https://github.com/mikekap/wink-mqtt-rs/blob/master/src/converter.rs).
### HTTP Server
An HTTP server is started (by default on port 3000) to let you see a quick UI of what your wink sees. Visit `http://192.168.1.123:3000/` in your browser to see it (replacing `192.168.1.123` with however you reach your wink).
In addition, there's an (unstable) REST API to control the wink exposed via this server. The endpoints are:
```
# List of devices, as well as current attribute values
curl http://wink:3000/api/devices
# Set device id 2's attribute id 3 to 255.
curl http://wink:3000/api/devices/2/3 -d '{"value": 255}' -H "Content-Type: application/json"
```

## Known Issues
- Groups are not exposed.
- This has only been tested with Z-Wave devices. It may not work in other scenarios.
This is very easy to fix, so please file issues with the output of `aprontest -l` and `aprontest -l -m <device_id>` from your Wink!
- Does not send device details to Home Assistant, even though the data exists. PRs welcome!
- `mqtts` support is untested.
- Could be smarter about tailing log files (like wink-mqtt), but a resync every 10 seconds seems fine.
- Don't publish status if nothing changed. Easy fix, if necessary.
## Uninstalling
Expand Down
16 changes: 9 additions & 7 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ impl HttpServer {
}
});

info!(slog_scope::logger(), "starting_http_server"; "port" => config.http_port.unwrap());

let server = Server::bind(&SocketAddr::from(([0, 0, 0, 0], config.http_port.unwrap())))
.tcp_nodelay(true)
.http1_only(true)
.http1_keepalive(false)
.serve(handler)
.with_graceful_shutdown(async move {
rx.await.ok();
});
.serve(handler);

info!(slog_scope::logger(), "started_http_server"; "listen_addr" => server.local_addr());

tokio::task::spawn(async move {
server.await.log_failing_result("http_server_failed");
server
.with_graceful_shutdown(async move {
rx.await.ok();
})
.await
.log_failing_result("http_server_failed");
});

this
Expand Down

0 comments on commit 028dd42

Please sign in to comment.