From d306a2e2f2075f346e99465ed4c15ded0ef1b684 Mon Sep 17 00:00:00 2001 From: Nick Moone <33722387+nickmoone@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:30:24 +0100 Subject: [PATCH 1/2] Create shelly-plus-i4dc.ts --- src/device-delegates/shelly-plus-i4dc.ts | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/device-delegates/shelly-plus-i4dc.ts diff --git a/src/device-delegates/shelly-plus-i4dc.ts b/src/device-delegates/shelly-plus-i4dc.ts new file mode 100644 index 0000000..3a8b4d7 --- /dev/null +++ b/src/device-delegates/shelly-plus-i4dc.ts @@ -0,0 +1,42 @@ +import { ShellyPlusI4DC } from 'shellies-ng'; + +import { DeviceDelegate } from './base'; +import { + ReadonlySwitchAbility, + ServiceLabelAbility, + StatelessProgrammableSwitchAbility, +} from '../abilities'; + +/** + * Handles Shelly Plus I4DC devices. + */ +export class ShellyPlusI4DCDelegate extends DeviceDelegate { + protected setup() { + const d = this.device as ShellyPlusI4DC; + + // determine each input type + const input0IsButton = d.input0.config?.type === 'button'; + const input1IsButton = d.input1.config?.type === 'button'; + const input2IsButton = d.input2.config?.type === 'button'; + const input3IsButton = d.input3.config?.type === 'button'; + + // create an accessory for all button inputs + this.createAccessory( + 'buttons', + null, + new StatelessProgrammableSwitchAbility(d.input0).setActive(input0IsButton), + new StatelessProgrammableSwitchAbility(d.input1).setActive(input1IsButton), + new StatelessProgrammableSwitchAbility(d.input2).setActive(input2IsButton), + new StatelessProgrammableSwitchAbility(d.input3).setActive(input3IsButton), + new ServiceLabelAbility(), + ).setActive(input0IsButton || input1IsButton || input2IsButton || input3IsButton); + + // create accessories for all switch inputs + this.createAccessory('switch0', null, new ReadonlySwitchAbility(d.input0)).setActive(!input0IsButton); + this.createAccessory('switch1', null, new ReadonlySwitchAbility(d.input1)).setActive(!input1IsButton); + this.createAccessory('switch2', null, new ReadonlySwitchAbility(d.input2)).setActive(!input2IsButton); + this.createAccessory('switch3', null, new ReadonlySwitchAbility(d.input3)).setActive(!input3IsButton); + } +} + +DeviceDelegate.registerDelegate(ShellyPlusI4DCDelegate, ShellyPlusI4DC); From c65a0821436986094d5e251bc1db0dcd35109b45 Mon Sep 17 00:00:00 2001 From: Nick Moone <33722387+nickmoone@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:33:47 +0100 Subject: [PATCH 2/2] Export device delegate for Shelly Plus I4DC. --- src/device-delegates/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/device-delegates/index.ts b/src/device-delegates/index.ts index 22e19d4..daa007b 100644 --- a/src/device-delegates/index.ts +++ b/src/device-delegates/index.ts @@ -4,6 +4,7 @@ export * from './shelly-plus-1'; export * from './shelly-plus-1-pm'; export * from './shelly-plus-2-pm'; export * from './shelly-plus-i4'; +export * from './shelly-plus-i4dc'; export * from './shelly-plus-plug-us'; export * from './shelly-pro-1'; export * from './shelly-pro-1-pm';