Skip to content

Commit

Permalink
Add button handling to Soda-S8
Browse files Browse the repository at this point in the history
  • Loading branch information
theimo1221 committed Oct 12, 2024
1 parent 4f41b49 commit 90d8b7b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* (theimo1221) Generalize Handle Sensor
* (theimo1221) Prepare Zigbee window handle
* (theimo1221) Implement SodaHandle (https://www.zigbee2mqtt.io/devices/S8.html#soda-s8) a window handle with
temp-/humidity sensor
temp-/humidity sensor and buttons for up/down

## 3.0.0-alpha.89 (2024-10-03)

Expand Down
44 changes: 43 additions & 1 deletion src/server/devices/zigbee/zigbeeSodaHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { DeviceType } from '../deviceType';
import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
import { DeviceCapability } from '../DeviceCapability';
import { HumiditySensor, TemperatureSensor } from '../sharedFunctions';
import { HumiditySensorChangeAction, TemperatureSensorChangeAction } from '../../../models';
import {
CommandSource,
HumiditySensorChangeAction,
LogLevel,
TemperatureSensorChangeAction,
WindowSetDesiredPositionCommand,
} from '../../../models';

export class ZigbeeSodaHandle extends ZigbeeWindowHandle implements iTemperatureSensor, iHumiditySensor {
/** @inheritDoc */
Expand Down Expand Up @@ -53,6 +59,16 @@ export class ZigbeeSodaHandle extends ZigbeeWindowHandle implements iTemperature
case 'temperature':
this.temperatureSensor.temperature = state.val as number;
break;
case 'button_left':
if (!initial && (state.val as string) === 'pressed') {
this.onButtonLeftPressed();
}
break;
case 'button_right':
if (!initial && (state.val as string) === 'pressed') {
this.onButtonRightPressed();
}
break;
}
}

Expand All @@ -77,4 +93,30 @@ export class ZigbeeSodaHandle extends ZigbeeWindowHandle implements iTemperature
this.humiditySensor.dispose();
super.dispose();
}

private onButtonLeftPressed(): void {
this.log(LogLevel.Info, 'Button left pressed');
if (!this.window) {
return;
}
const command: WindowSetDesiredPositionCommand = new WindowSetDesiredPositionCommand(
CommandSource.Manual,
0,
'Button on handle was pressed',
);
this.window.setDesiredPosition(command);
}

private onButtonRightPressed(): void {
this.log(LogLevel.Info, 'Button right pressed');
if (!this.window) {
return;
}
const command: WindowSetDesiredPositionCommand = new WindowSetDesiredPositionCommand(
CommandSource.Manual,
100,
'Button on handle was pressed',
);
this.window.setDesiredPosition(command);
}
}

0 comments on commit 90d8b7b

Please sign in to comment.