Skip to content

Commit

Permalink
Merge pull request #2 from jldeen:add-toggle-and-docs
Browse files Browse the repository at this point in the history
add toggle on/off and docs
  • Loading branch information
jldeen authored Dec 15, 2021
2 parents d7027af + d01d71c commit 550dd6f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 98 deletions.
72 changes: 1 addition & 71 deletions 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
@@ -1,6 +1,6 @@
[package]
name = "keylight"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[![CI](https://github.com/jldeen/keylight-cli/actions/workflows/build-ci.yml/badge.svg)](https://github.com/jldeen/keylight-cli/actions/workflows/build-ci.yml)

# Elgato Keylight CLI

This is a cross platform lightweight CLI tool to simply and easily control your [Elgato Keylights](https://www.elgato.com/key-light) via local IP address.

## Work To Be Done

- [X] Support for `on` / `off` toggle arguements. **Added in v0.2.0**
- [X] Add help menu with `-h` flag. **Added in v0.2.0**
- [ ] Support for brightness and temperature via preset arguments, I.E, `low`, `medium`, and `high` or `warm`, `medium`, and `cool`.
- [ ] Testing with more than 1 Elgato Keylight.

## Building The App

This app should build with minimal dependencies. It's been tested with Rust 1.56 on macOS Monterey 12.1 and 1 Elgato Keylight.

`cargo build`

## Running The App

This CLI tool has three mandatory parameters and two optional ones (that have default values). There are environment variables that can be provided in place of CLI arguments.

```
keylight cli v0.2.0
Jessica Deen <jessica.deen@microsoft.com>
A Simple lightweight CLI to control Elgato Keylights from the command line
USAGE:
keylight [FLAGS] --elgato-ip <Local Elgato IP Address> --number-of-lights <Number of Elgato Keylights> --brightness <Brightness> --temperature <Temperature> [ARGS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose Resource group location for the ContainerApps environment.
OPTIONS:
-i, --elgato-ip <Local Elgato IP Address>
Local Elgato IP Address [env: elgato_ip=]
-n, --number-of-lights <Number of Elgato Keylights>
Number of Elgato Keylights to control [env: number_of_lights=]
-b, --brightness <Brightness>
Brightness level [env: brightness=] [default: 20]
-t, --temperature <Temperature>
Temperature level [env: temperature=] [default: 213]
ARGS:
<on/off> Toggle switch value to turn keylight(s) on or off.
```
35 changes: 20 additions & 15 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,51 @@ pub fn get_app_cli<'a, 'b>(version: &'b str) -> App<'a, 'b> {
Arg::with_name("switch")
.index(1)
.required(true)
.short("s")
.long("switch")
.takes_value(true)
.value_name("ON/OFF")
.value_name("on/off")
.help("Switch value for light status: Accepted values are: on, off."),
)
.arg(
Arg::with_name("brightness")
.long("brightness")
.short("b")
.help("Brightness value for light: Accepted values are: low, medium, high.")
.required(true)
.index(2)
.env("brightness")
.default_value("20"),
)
.arg(
Arg::with_name("temperature")
.long("temperature")
.short("t")
.help("Temperature value for light: Accepted values are: warm, medium, cool.")
.required(true)
.index(3)
.env("temperature")
.default_value("213"),
)
.arg(
Arg::with_name("ELGATO_IP")
.long("elgato-ip-address")
.short("ip")
Arg::with_name("elgato_ip")
.long("elgato-ip")
.short("i")
.help("Elgato Keylight IP address")
.index(4)
.required(true)
.aliases(&["elgato_ip", "elgato-ip", "elgato ip"])
.env("ELGATO_IP")
.env("elgato_ip")
.takes_value(true),
)
.arg(
Arg::with_name("NUMBER_OF_LIGHTS")
Arg::with_name("number_of_lights")
.long("number-of-lights")
.short("lights")
.short("n")
.help("Number of Elgato Keylights in use")
.required(true)
.index(5)
.aliases(&["number_of_lights", "number-of-lights", "number of lights"])
.env("NUMBER_OF_LIGHTS")
.env("number_of_lights")
.takes_value(true),
)
.arg(
Arg::with_name("verbose")
.long("verbose")
.short("v")
.help("Verbose mode enabled"),
)
}
21 changes: 10 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#![allow(unused)]
mod cli;

use cli::get_app_cli;
use reqwest::Client;
use serde_json::json;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let version = format!("v{}", env!("CARGO_PKG_VERSION"));

let matches = get_app_cli(&version).get_matches();
let elgato_ip = matches.value_of("ELGATO_IP").unwrap();
let numberoflights = matches.value_of("NUMBER_OF_LIGHTS").unwrap();
let switch = matches
.value_of("switch")
.and_then(|s| s.parse::<u8>().ok())
.unwrap();
let elgato_ip = matches.value_of("elgato_ip").unwrap();
let numberoflights = matches.value_of("number_of_lights").unwrap();
let switch = if matches.value_of("switch").unwrap() == "off" {
0
} else {
1
};
println!("Power switch value: {}", switch);

let brightness = matches
.value_of("brightness")
.and_then(|s| s.parse::<u8>().ok())
Expand All @@ -26,8 +27,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.and_then(|s| s.parse::<u8>().ok())
.unwrap();

println!("Value for switch: {}", switch);

let body = json!({
"numberOfLights":numberoflights,
"lights":[
Expand All @@ -43,7 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

println!("State: {}", url);

let client = reqwest::Client::new();
let client = Client::new();

let response = client.put(url).json(&body).send().await?;

Expand Down

0 comments on commit 550dd6f

Please sign in to comment.