Skip to content

Commit

Permalink
Update hex regex, fix bugs and add README (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xabadu authored May 9, 2021
1 parent d190451 commit 85074e4
Show file tree
Hide file tree
Showing 11 changed files with 6,110 additions and 1,271 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
HUB_IP=127.0.0.1
HUB_USER=my_hue_user
TWITCH_CHANNELS=my_channel,other_channel
LIGHTS_COMMAND=lights
LOOP_COMMAND=loop
HUE_RESOURCE=lights #or groups
HUE_RESOURCE_ID=6
HUE_TRANSITION_TIME=10
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ dist
# Ignore all local history of files
.history

### Others
TODO

# End of https://www.toptal.com/developers/gitignore/api/node,macos,visualstudiocode
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Operation Hue Hue Hue

This app lets your Twitch viewers interact with your Philips Hue Lights using the chat.

## Installation

1. Clone this repo

2. Install dependencies

```bash
npm install
```

3. Rename `env.example` to `.env` and edit this values:

- `HUB_IP`: This is the IP address for your Philips Hue Hub. You can find yours accessing [this URL](https://discovery.meethue.com/) from the network your hub is on.
- `HUB_USER`: The user to access your hub. If you don't have one yet, you'll have to create one following the instructions on the [Philips Hue Developer portal](https://developers.meethue.com/).
- `TWITCH_CHANNELS`: List of Twitch channels you want to listen to for messages, separated by commas.
- `LIGHTS_COMMAND`: The command the app will listen to for light updates.
- `LOOP_COMMAND`: The command the app will listen to enable the color loop.
- `HUE_RESOURCE`: The type of resource you want to manage with the app (lights or groups)
- `HUE_RESOURCE_ID`: The id of the light you want to update with the messages.
- `HUE_TRANSITION_TIME`: Transition time for the light updates.

4. Run the app locally

```bash
npm start
```

## Usage/Examples

The app supports 3 types of color inputs:

- hex: `#000000` to `#ffffff`
- rgb: `rgb(0, 0, 0)` to `rgb(255, 255, 255)`
- CSS colors: Anything from [this list](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)

```bash
// hex
!{YOUR-COMMAND} #ff6347

// rgb
!{YOUR-COMMAND} rgb(255, 99, 71)

// CSS colors
!{YOUR-COMMAND} tomato
```

## License

[MIT](https://choosealicense.com/licenses/mit/)
35 changes: 35 additions & 0 deletions __tests__/src/hue_colors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { hexToRGB } = require("../../src/lib/color_helpers");

describe("hexToRGB", () => {
test("Returns invalid color if the hex is invalid", () => {
const invalid1 = hexToRGB("invalid");
const invalid2 = hexToRGB("123123@");
const invalid3 = hexToRGB("#ff");
const invalid4 = hexToRGB("#fffffffffffffffff");
const invalid5 = hexToRGB("heello");
const invalid6 = hexToRGB("FFFFFF");
const invalid7 = hexToRGB("FFF");

expect(invalid1).toBe(undefined);
expect(invalid2).toBe(undefined);
expect(invalid3).toBe(undefined);
expect(invalid4).toBe(undefined);
expect(invalid5).toBe(undefined);
expect(invalid6).toBe(undefined);
expect(invalid7).toBe(undefined);
});

test("Returns a valid color if the hex is valid", () => {
const valid = hexToRGB("#ffffff");
const validShort = hexToRGB("#ffffff");
const valid2 = hexToRGB("#ff0000");
const valid3 = hexToRGB("#00ff00");
const valid4 = hexToRGB("#0000ff");

expect(valid).toBe("rgb(255,255,255)");
expect(validShort).toBe("rgb(255,255,255)");
expect(valid2).toBe("rgb(255,0,0)");
expect(valid3).toBe("rgb(0,255,0)");
expect(valid4).toBe("rgb(0,0,255)");
});
});
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/* This is the legacy code done originally on the stream - No longer used.
App logic now lives in src/index.js
You can watch the original video here:
https://www.youtube.com/watch?v=sBglf1RggaM
*/

const axios = require("axios");
const Color = require("color");
const tmi = require("tmi.js");
Expand Down
Loading

0 comments on commit 85074e4

Please sign in to comment.