Skip to content

Commit

Permalink
refactor: rename KeyLightCli to ElgatoLight
Browse files Browse the repository at this point in the history
  • Loading branch information
wassimk committed Jun 8, 2024
1 parent ff689ae commit 07100ff
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- release_for: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: elgato-light-cli
name: elgato-light-cli-Darwin-x86_64.tar.gz
bin: elgato-light
name: elgato-light-Darwin-x86_64.tar.gz

- release_for: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
bin: elgato-light-cli
name: elgato-light-cli-Darwin-aarch64.tar.gz
bin: elgato-light
name: elgato-light-Darwin-aarch64.tar.gz

runs-on: ${{ matrix.platform.os }}

Expand Down Expand Up @@ -50,8 +50,8 @@ jobs:
- name: Publish release artifacts
uses: actions/upload-artifact@v3
with:
name: elgato-light-cli-${{ matrix.platform.os_name }}
path: "elgato-light-cli-*"
name: elgato-light-${{ matrix.platform.os_name }}
path: "elgato-light-*"

- name: Generate SHA-256
run: shasum -a 256 ${{ matrix.platform.name }}
Expand All @@ -60,4 +60,4 @@ jobs:
uses: softprops/action-gh-release@v2
with:
draft: true
files: "elgato-light-cli*"
files: "elgato-light*"
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
@@ -1,5 +1,5 @@
[package]
name = "elgato-light-cli"
name = "elgato-light"
version = "0.1.0"
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# elgato-light-cli
# elgato-light

This is a CLI tool to control an Elgato light. It also works for any of their key lights.

Expand Down Expand Up @@ -62,5 +62,5 @@ keylight status
The Apple binaries are not signed with an Apple Developer account, so you must authorize them manually.

```shell
xattr -dr com.apple.quarantine ./elgato-light-cli
xattr -dr com.apple.quarantine ./elgato-light
```
34 changes: 17 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const DEFAULT_IP_ADDRESS: &str = "192.168.0.25";

#[derive(StructOpt, Debug)]
#[structopt(
name = "elgago light cli",
name = "elgato light",
about = "A command line interface for controlling an Elgato light by its IP address"
)]
enum KeyLightCli {
enum ElgatoLight {
#[structopt(about = "Turns the light on with specified brightness and temperature")]
On {
#[structopt(
Expand Down Expand Up @@ -63,14 +63,14 @@ enum KeyLightCli {
},
}

impl KeyLightCli {
impl ElgatoLight {
fn ip_address(&self) -> Result<Ipv4Addr, Box<dyn Error>> {
let ip_str = match self {
KeyLightCli::On { ip_address, .. }
| KeyLightCli::Off { ip_address }
| KeyLightCli::Brightness { ip_address, .. }
| KeyLightCli::Temperature { ip_address, .. }
| KeyLightCli::Status { ip_address } => ip_address,
ElgatoLight::On { ip_address, .. }
| ElgatoLight::Off { ip_address }
| ElgatoLight::Brightness { ip_address, .. }
| ElgatoLight::Temperature { ip_address, .. }
| ElgatoLight::Status { ip_address } => ip_address,
};

Ipv4Addr::from_str(ip_str).map_err(|_| "Invalid IP address format".into())
Expand All @@ -91,7 +91,7 @@ impl KeyLightCli {

async fn run(&self, mut keylight: KeyLight) -> Result<(), Box<dyn Error>> {
match self {
KeyLightCli::On {
ElgatoLight::On {
brightness,
temperature,
..
Expand All @@ -100,21 +100,21 @@ impl KeyLightCli {
keylight.set_brightness(*brightness).await?;
keylight.set_temperature(*temperature).await?;
}
KeyLightCli::Off { .. } => {
ElgatoLight::Off { .. } => {
keylight.set_power(false).await?;
}
KeyLightCli::Brightness { brightness, .. } => {
KeyLightCli::ensure_light_on(&mut keylight).await?;
ElgatoLight::Brightness { brightness, .. } => {
ElgatoLight::ensure_light_on(&mut keylight).await?;
let status = keylight.get().await?;
let current_brightness = status.lights[0].brightness;
let new_brightness = ((current_brightness as i8) + *brightness).clamp(0, 100) as u8;
keylight.set_brightness(new_brightness).await?;
}
KeyLightCli::Temperature { temperature, .. } => {
KeyLightCli::ensure_light_on(&mut keylight).await?;
ElgatoLight::Temperature { temperature, .. } => {
ElgatoLight::ensure_light_on(&mut keylight).await?;
keylight.set_temperature(*temperature).await?;
}
KeyLightCli::Status { .. } => {
ElgatoLight::Status { .. } => {
let status = keylight.get().await?;
println!("{:?}", status);
}
Expand All @@ -126,9 +126,9 @@ impl KeyLightCli {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = KeyLightCli::from_args();
let args = ElgatoLight::from_args();
let ip_address = args.ip_address()?;
let keylight = KeyLightCli::get_keylight(ip_address).await?;
let keylight = ElgatoLight::get_keylight(ip_address).await?;
args.run(keylight).await?;

Ok(())
Expand Down

0 comments on commit 07100ff

Please sign in to comment.