Skip to content

Commit

Permalink
fix: add adapter selection is settings
Browse files Browse the repository at this point in the history
  • Loading branch information
CKY- committed Nov 9, 2024
1 parent 87c8b5c commit 0261d09
Show file tree
Hide file tree
Showing 8 changed files with 7,595 additions and 16,395 deletions.
23,903 changes: 7,530 additions & 16,373 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@
"author": "CKY",
"license": "GNU3",
"devDependencies": {
"@crowbartools/firebot-custom-scripts-types": "https://github.com/crowbartools/firebot-custom-scripts-types/tarball/fe78b95646ced8c91c09bdb71b6c87a5aa08b98c",
"@types/color-convert": "^2.0.0",
"@types/node": "^14.18.36",
"@types/pino": "^4.15.3",
"@types/tinycolor2": "^1.4.3",
"jest": "^26.6.3",
"terser-webpack-plugin": "^4.2.3",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^4.1.0"
"@crowbartools/firebot-custom-scripts-types": "^5.63.0",
"@types/node": "^20.14.0",
"jest": "^29.7.0",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"class-validator": "^0.13.2",
"ip": "^1.1.5",
"pino": "^4.15.3",
"tiny-typed-emitter": "^2.1.0",
"tinycolor2": "^1.5.1"
},
"volta": {
"node": "20.14.0",
"npm": "10.8.1"
}
}
}
4 changes: 2 additions & 2 deletions src/firebot/effects/wiz-light-set-brightness.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Firebot } from "@crowbartools/firebot-custom-scripts-types";
import { changeBrigtness } from "../../wiz-lights"
import { changeBrightness } from "../../wiz-lights"

export const setWizLightBrightnessEffectType: Firebot.EffectType<{
lightCollectionName: string;
Expand Down Expand Up @@ -76,7 +76,7 @@ export const setWizLightBrightnessEffectType: Firebot.EffectType<{
return [];
},
onTriggerEvent: async ({ effect }) => {
changeBrigtness(effect.lightCollectionName, effect.brightness);
changeBrightness(effect.lightCollectionName, effect.brightness);
return true;
},
};
4 changes: 2 additions & 2 deletions src/firebot/effects/wiz-light-set-color.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Firebot } from "@crowbartools/firebot-custom-scripts-types";
import { changeBrigtness, changeLight, changeLightModeAndBrightness } from "../../wiz-lights"
import { changeBrightness, changeLight, changeLightModeAndBrightness } from "../../wiz-lights"

export const setWizLightColorEffectType: Firebot.EffectType<{
lightCollectionName: string;
Expand Down Expand Up @@ -124,7 +124,7 @@ export const setWizLightColorEffectType: Firebot.EffectType<{
}

if (effect.setColor == true && effect.setBrighteness == false) {
changeBrigtness(effect.lightCollectionName, effect.brightness);
changeBrightness(effect.lightCollectionName, effect.brightness);
}

if (effect.setColor == true && effect.setBrighteness == true) {
Expand Down
4 changes: 2 additions & 2 deletions src/firebot/effects/wiz-light-set-scene.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Firebot } from "@crowbartools/firebot-custom-scripts-types";
import { changeBrigtness, changeLightModeSceneAndBrightness, changeLightScene } from "../../wiz-lights"
import { changeBrightness, changeLightModeSceneAndBrightness, changeLightScene } from "../../wiz-lights"
import { logger } from "../../logger";
import { Scene } from "../../../wiz-local-control/dist/classes/LightMode";

Expand Down Expand Up @@ -142,7 +142,7 @@ export const setWizLightSceneEffectType: Firebot.EffectType<{
}

if (effect.setScene == false && effect.setBrightness == true) {
changeBrigtness(effect.lightCollectionName, effect.brightness);
changeBrightness(effect.lightCollectionName, effect.brightness);
}

if (effect.setScene == true && effect.setBrightness == true) {
Expand Down
4 changes: 3 additions & 1 deletion src/firebot/wiz-intagration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initRemote } from "../wiz-lights";
type WizSettings = {
wizSettings: {
ipAddress: string;
adapter: string
};
};

Expand All @@ -31,11 +32,12 @@ class WizIntegration
return;
}
const {
wizSettings: { ipAddress },
wizSettings: { ipAddress, adapter},
} = settings;
initRemote(
{
ip: ipAddress,
adapter: adapter
},
{
eventManager: this.eventManager,
Expand Down
30 changes: 27 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ import { turnWizLightOnEffectType } from "./firebot/effects/wiz-light-on";
import { turnWizLightOffEffectType } from "./firebot/effects/wiz-light-off";
import { setWizLightSceneEffectType } from "./firebot/effects/wiz-light-set-scene";
import { setWizLightBrightnessEffectType } from "./firebot/effects/wiz-light-set-brightness";
import { initLogger } from "./logger";
import { initLogger, logger } from "./logger";
const os = require('os');

interface Params {
ipAddress: string;
adapter: string;
}

let networkInterfaces = os.networkInterfaces();
let interfaceNames: string[] = [];
for (const interfaceName in networkInterfaces) {
if (networkInterfaces.hasOwnProperty(interfaceName)) {
interfaceNames.push(interfaceName);
}
}


const script: Firebot.CustomScript<Params> = {
getScriptManifest: () => {
return {
name: "Wiz Lights",
description: "Control Wiz lights from Events and commmands.",
description: "Control Wiz lights from Events and commands.",
author: "CKY",
version: "1.0",
firebotVersion: "5",
Expand All @@ -28,6 +39,7 @@ const script: Firebot.CustomScript<Params> = {
ipAddress: {
type: "filepath",
default: "",
title: "Please Select A file",
description: "List of ip addess file",
secondaryDescription:
"The ip address's of the first light to control",
Expand All @@ -38,6 +50,16 @@ const script: Firebot.CustomScript<Params> = {
buttonLabel: "Select"
}
},
adapter: {
type: "enum",
default: "Select",
title: "Please Select An Adapter",
description: "Connection device (Must restart firebot)",
secondaryDescription: "The connection device by name that is connected to your access point",
options: interfaceNames,
searchable: true,
placeholder: "Connection device"
}
};
},
run: async (runRequest) => {
Expand All @@ -46,12 +68,14 @@ const script: Firebot.CustomScript<Params> = {
initRemote(
{
ip: runRequest.parameters.ipAddress,
adapter: runRequest.parameters.adapter
},
{
eventManager,
}
);

logger.error(interfaceNames.toString())
logger.error(networkInterfaces.toString());
setupFrontendListeners(runRequest.modules.frontendCommunicator);
runRequest.modules.effectManager.registerEffect(turnWizLightOnEffectType);
runRequest.modules.effectManager.registerEffect(turnWizLightOffEffectType);
Expand Down
18 changes: 15 additions & 3 deletions src/wiz-lights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ export class lightCollections {
export function initRemote(
{
ip,
adapter
}: {
ip: string;
adapter: string;
},
modules: {
eventManager: ScriptModules["eventManager"];
}
) {
eventManager = modules.eventManager;
setFile(ip);
setAdapter(adapter);
}

let eventManager: ScriptModules["eventManager"];
let filePath: string;
let selectedAdapter: string;

function setFile(ip: string) {
filePath = ip;
}

function setAdapter(adapter: string) {
selectedAdapter = adapter;
}

const detectedDevices = new lightCollections();
const wizLocalControl = new WiZLocalControl({
incomingMsgCallback: (msg: WiZMessage, ip: string) => {
Expand All @@ -49,7 +57,7 @@ const wizLocalControl = new WiZLocalControl({
}
});
},
interfaceName: "eth0"
interfaceName: selectedAdapter
});

export async function getSceneCollection(): Promise<Scene[]> {
Expand All @@ -76,7 +84,7 @@ export async function getlightCollections(): Promise<string[]> {
return [];
}

export function connectToLight(ip: any, r: number, g: number, b: number) {
export function connectToLight(ip: any) {
wizLocalControl.udpManager.startListening();
}

Expand Down Expand Up @@ -130,7 +138,7 @@ export function changeLightModeSceneAndBrightness(ip: any, scene: Scene, brighen
);
}

export function changeBrigtness( ip: string, brightness: number){
export function changeBrightness( ip: string, brightness: number){
wizLocalControl.changeBrightness(brightness, ip);
}

Expand All @@ -140,4 +148,8 @@ export function lightOn(ip: any) {

export function lightOff(ip: any) {
wizLocalControl.changeStatus(false, ip);
}

export function getConfig(ip: any) {
wizLocalControl.getSystemConfig(ip);
}

0 comments on commit 0261d09

Please sign in to comment.