Skip to content

Commit

Permalink
feat(dingz): ✨ implement support for WiFi Switch Zero
Browse files Browse the repository at this point in the history
This change implements support for WiFi Switch Zero (no temperature and power measurements).

Close #556
  • Loading branch information
johannrichard committed Dec 27, 2022
1 parent 5d69387 commit 786af0d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/lib/myStromTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export const MyStromSwitchTypes = {
'106': 'CH v2',
WSEU: 'EU',
'107': 'EU',
LCS: 'Zero',
'120': 'Zero',
};

export interface MyStromDeviceHWInfo {
version: string;
mac: string;
Expand Down
28 changes: 20 additions & 8 deletions src/myStromSwitchAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
)
.setCharacteristic(
this.platform.Characteristic.HardwareRevision,
this.mystromDeviceInfo ? 'EU/CH v2' : 'CH v1',
this.mystromDeviceInfo ? 'EU/CH v2/Zero' : 'CH v1',
)
.setCharacteristic(
this.platform.Characteristic.SerialNumber,
Expand All @@ -86,12 +86,11 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {

this.outletService
.getCharacteristic(this.platform.Characteristic.OutletInUse)
// .on(CharacteristicEventTypes.SET, this.setOutletInUse.bind(this)) // SET - bind to the `setOn` method below
.on(CharacteristicEventTypes.GET, this.getOutletInUse.bind(this)); // GET - bind to the `getOn` method below

if (this.device.hwInfo?.type !== undefined) {
// Only EU and CH v2 Switches have temperature sensor
if (this.device.model !== 'Zero' && this.device.model !== undefined) {
// Switch has a temperature sensor, make it available here
// create a new Temperature Sensor service
this.temperatureService =
this.accessory.getService(this.platform.Service.TemperatureSensor) ??
this.accessory.addService(this.platform.Service.TemperatureSensor);
Expand Down Expand Up @@ -121,9 +120,19 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
.getCharacteristic(this.platform.Characteristic.On)
.updateValue(this.outletState.relay);

this.outletService
.getCharacteristic(this.platform.Characteristic.OutletInUse)
.updateValue(this.outletState.power > 0);
switch (this.device.model ?? 'unknown') {
case 'CH v1':
case 'Zero':
this.outletService
.getCharacteristic(this.platform.Characteristic.OutletInUse)
.updateValue(this.outletState.relay);
break;
default:
this.outletService
.getCharacteristic(this.platform.Characteristic.OutletInUse)
.updateValue(this.outletState.power > 0);
break;
}

if (this.temperatureService) {
this.temperatureService
Expand Down Expand Up @@ -160,7 +169,10 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
}

private getOutletInUse(callback: CharacteristicGetCallback) {
const inUse: boolean = this.outletState?.power > 0;
const inUse: boolean =
this.device.model === 'Zero' // Zero does not measure power
? this.outletState?.relay
: this.outletState?.power > 0;
this.log.debug('Get Characteristic OutletInUse ->', inUse);
callback(this.reachabilityState, inUse);
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
info.type !== DeviceTypes.MYSTROM_SWITCH_CHV2 &&
info.type !== 'WSEU' &&
info.type !== DeviceTypes.MYSTROM_SWITCH_EU &&
info.type !== 'LCS' &&
info.type !== undefined // Switch V1 does not have a type
) {
throw new InvalidTypeError(
Expand Down Expand Up @@ -977,6 +978,7 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
case DeviceTypes.MYSTROM_SWITCH_CHV1:
case DeviceTypes.MYSTROM_SWITCH_CHV2:
case DeviceTypes.MYSTROM_SWITCH_EU:
case DeviceTypes.MYSTROM_SWITCH_ZERO:
retryWithBreaker
.execute(() => {
this.addMyStromSwitchDevice({
Expand Down

0 comments on commit 786af0d

Please sign in to comment.