-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added light codebase, settings, readme and misc
- Loading branch information
Showing
8 changed files
with
166 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,71 @@ | ||
# Hue-rs ~ Philips Hue Rust Library and CLI | ||
# Philips Hue Rust Library and CLI | ||
|
||
## Description - let there be light! | ||
**This is currently in development stage!** | ||
|
||
... | ||
## Hue-rs, let there be light! | ||
|
||
Hue-rs is a *Rust* library that can be used for home automation on Philips Hue lights. | ||
It offers a basic *CLI* with which you can control your lights from a terminal instead | ||
of looking for your phone and making desired changes from official Philips Hue app. | ||
|
||
## Installation and CLI use | ||
|
||
... | ||
```bash | ||
$ cat <<EOF > ~/.huerc | ||
debug = false | ||
[hue] | ||
ip = 192.168.0.1 | ||
username = <philips-hue-username> | ||
EOF | ||
|
||
$ hue help | ||
|
||
hue 1.0 | ||
Marko Kosmerl <marko.kosmerl@gmail.com> | ||
Philips Hue CLI | ||
|
||
USAGE: | ||
hue [FLAGS] [OPTIONS] <SUBCOMMAND> | ||
|
||
FLAGS: | ||
-h, --help Prints help information | ||
-V, --version Prints version information | ||
-v Sets the level of verbosity | ||
|
||
OPTIONS: | ||
-c, --config <FILE> Sets a custom config file | ||
|
||
SUBCOMMANDS: | ||
group Controls a group of lights | ||
help Prints this message or the help of the given subcommand(s) | ||
light Controls the lights | ||
scene Controls a scene | ||
|
||
$ hue light on 1 | ||
[{"success":{"/lights/1/state/on":true}}] | ||
``` | ||
|
||
## Library use | ||
|
||
```rust | ||
extern crate hue-rs; | ||
|
||
use hue-rs::*; | ||
use hue-rs::lights::*; | ||
|
||
## Library used | ||
pub fn funhue) { | ||
let client = Client::new(); | ||
|
||
... | ||
let mut light = Light::get_light(&client, 1).unwrap(); | ||
let &mut light_state = light.state(); | ||
light_state.set_on(true); | ||
light.update() | ||
} | ||
``` | ||
|
||
## Todo | ||
|
||
... | ||
- [ ] Tests | ||
- [ ] Finalize *light*, *group* and *scene* API | ||
- [ ] *Let there be light* voice recognition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: hue-rc | ||
name: hue | ||
version: "1.0" | ||
author: Marko Kosmerl <marko.kosmerl@gmail.com> | ||
about: Philips Hue CLI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
debug = false | ||
|
||
[hue] | ||
ip = 192.168.0.28 | ||
username = hue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use config::{Config, ConfigError, File, Environment}; | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct Hue { | ||
ip: String, | ||
username: String, | ||
} | ||
|
||
/// Configuration holding Phiplips Hue API information and debug option. | ||
#[derive(Debug, Deserialize)] | ||
pub struct Settings { | ||
debug: bool, | ||
hue: Hue, | ||
} | ||
|
||
impl Settings { | ||
/// Load configuration from environment or ~/.huerc configuration file. | ||
/// | ||
/// Environment variables have a priority over configuration file. | ||
pub fn new() -> Result<Self, ConfigError> { | ||
let mut s = Config::new(); | ||
|
||
s.merge(File::with_name("~/.huerc").required(false)); | ||
s.merge(Environment::with_prefix("HUE"))?; | ||
|
||
s.try_into() | ||
} | ||
|
||
/// Get IP address of Philips Hue bridge. | ||
pub fn ip(&self) -> &str { | ||
&self.hue.ip | ||
} | ||
|
||
/// Get username that is used to talk with the API. | ||
pub fn username(&self) -> &str { | ||
&self.hue.username | ||
} | ||
} |