Skip to content

Commit

Permalink
Added ioBroker Devices
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Oct 21, 2023
1 parent e0ba494 commit 419e6c3
Show file tree
Hide file tree
Showing 44 changed files with 3,459 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ nbproject
package-lock.json
build
*.map
devices
main.js

.dev-server
Expand Down
181 changes: 181 additions & 0 deletions src/lib/devices/AirCondition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import GenericDevice, {
DetectedDevice,
DeviceStateObject,
PropertyType,
StateAccessType,
ValueType
} from './GenericDevice';

enum AirConditionerMode {
Auto = 'AUTO',
Cool = 'COOL',
Dry = 'DRY',
Eco = 'ECO',
FanOnly = 'FAN_ONLY',
Heat = 'HEAT',
Off = 'OFF',
}

enum AirConditionerSpeed {
Auto = 'AUTO',
High = 'HIGH',
Low = 'LOW',
Medium = 'MEDIUM',
Quiet = 'QUIET',
Turbo = 'TURBO',
}

enum AirConditionerSwing {
Auto = 'AUTO',
Horizontal = 'HORIZONTAL',
Stationary = 'STATIONARY',
Vertical = 'VERTICAL',
}

class AirCondition extends GenericDevice {
private _levelState: DeviceStateObject<number> | undefined;
private _getTemperatureState: DeviceStateObject<number> | undefined;
private _powerState: DeviceStateObject<boolean> | undefined;
private _getHumidityState: DeviceStateObject<number> | undefined;
private _speedState: DeviceStateObject<AirConditionerSpeed> | undefined;
private _boostState: DeviceStateObject<boolean | number> | undefined;
private _SwingState: DeviceStateObject<AirConditionerSwing> | undefined;
private _modeState: DeviceStateObject<AirConditionerMode> | undefined;

constructor(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter) {
super(detectedDevice, adapter);

this._ready.push(this.addDeviceStates([
{ name: 'SET', valueType: ValueType.NumberMinMax, accessType: StateAccessType.ReadWrite, type: PropertyType.Level, callback: state => this._levelState = state },

{ name: 'ACTUAL', valueType: ValueType.Number, accessType: StateAccessType.Read, type: PropertyType.Temperature, callback: state => this._getTemperatureState = state },
{ name: 'POWER', valueType: ValueType.Boolean, accessType: StateAccessType.ReadWrite, type: PropertyType.Power, callback: state => this._powerState = state },
{ name: 'HUMIDITY', valueType: ValueType.NumberPercent, accessType: StateAccessType.Read, type: PropertyType.Humidity, callback: state => this._getHumidityState = state },
{ name: 'SPEED', valueType: ValueType.Enum, accessType: StateAccessType.ReadWrite, type: PropertyType.Speed, callback: state => this._speedState = state },
{ name: 'BOOST', valueType: ValueType.Boolean, accessType: StateAccessType.ReadWrite, type: PropertyType.Boost, callback: state => this._boostState = state },
{ name: 'SWING', valueType: ValueType.Boolean, accessType: StateAccessType.ReadWrite, type: PropertyType.Swing, callback: state => this._SwingState = state },
{ name: 'MODE', valueType: ValueType.Enum, accessType: StateAccessType.ReadWrite, type: PropertyType.Mode, callback: state => this._modeState = state },
]));
}

getLevel(): number | undefined {
if (!this._levelState) {
throw new Error('Level state not found');
}
return this._levelState.value;
}

async setLevel(value: number): Promise<void> {
if (!this._levelState) {
throw new Error('Level state not found');
}
return this._levelState.setValue(value);
}

getTemperature(): number | undefined {
if (!this._getTemperatureState) {
throw new Error('Temperature state not found');
}
return this._getTemperatureState.value;
}

getPower(): boolean | undefined {
if (!this._powerState) {
throw new Error('Power state not found');
}
return this._powerState.value;
}

async setPower(value: boolean): Promise<void> {
if (!this._powerState) {
throw new Error('Power state not found');
}
return this._powerState.setValue(value);
}

getHumidity(): number | undefined {
if (!this._getHumidityState) {
throw new Error('Humidity state not found');
}
return this._getHumidityState.value;
}

getBoost(): boolean | number | undefined {
if (!this._boostState) {
throw new Error('Boost state not found');
}
return this._boostState.value;
}

async setBoost(value: boolean | number): Promise<void> {
if (!this._boostState) {
throw new Error('Boost state not found');
}
return this._boostState.setValue(value);
}

getSpeed(): AirConditionerSpeed | undefined {
if (!this._speedState) {
throw new Error('Speed state not found');
}
return this._speedState.value;
}

async setSpeed(value: AirConditionerSpeed):Promise<void> {
if (!this._speedState) {
throw new Error('Speed state not found');
}
return this._speedState.setValue(value);
}

getSpeedModes(): Promise<AirConditionerSpeed[]> {
if (!this._speedState) {
throw new Error('Speed state not found');
}
return this._speedState.getModes();
}

getSwing(): AirConditionerSwing | undefined {
if (!this._SwingState) {
throw new Error('Swing state not found');
}
return this._SwingState.value;
}

async setSwing(value: AirConditionerSwing): Promise<void> {
if (!this._SwingState) {
throw new Error('Swing state not found');
}
return this._SwingState.setValue(value);
}

getSwingModes(): Promise<AirConditionerSwing[]> {
if (!this._SwingState) {
throw new Error('Swing state not found');
}
return this._SwingState.getModes();
}

getMode(): AirConditionerMode | undefined {
if (!this._modeState) {
throw new Error('Mode state not found');
}
return this._modeState.value;
}

async setMode(mode: AirConditionerMode): Promise<void> {
if (!this._modeState) {
throw new Error('Mode state not found');
}
await this._modeState.setValue(mode);
}

getModes(): Promise<AirConditionerMode[]> {
if (!this._modeState) {
throw new Error('Mode state not found');
}
return this._modeState.getModes();
}
}

export default AirCondition;
33 changes: 33 additions & 0 deletions src/lib/devices/Blind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import BlindButtons from './BlindButtons';
import { DetectedDevice, DeviceStateObject, PropertyType, StateAccessType, ValueType } from './GenericDevice';

class Blind extends BlindButtons {
private _setLevelState: DeviceStateObject<number> | undefined;
private _getLevelState: DeviceStateObject<number> | undefined;

constructor(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter) {
super(detectedDevice, adapter);

this._ready.push(this.addDeviceStates([
// actual value first, as it will be read first
{ name: 'ACTUAL', valueType: ValueType.NumberPercent, accessType: StateAccessType.Read, type: PropertyType.Level, callback: state => this._getLevelState = state },
{ name: 'SET', valueType: ValueType.NumberPercent, accessType: StateAccessType.ReadWrite, type: PropertyType.Level, callback: state => this._setLevelState = state },
]));
}

getLevel(): number | undefined {
if (!this._setLevelState && !this._getLevelState) {
throw new Error('Level state not found');
}
return (this._getLevelState || this._setLevelState)?.value;
}

async setLevel(value: number): Promise<void> {
if (!this._setLevelState) {
throw new Error('Level state not found');
}
return this._setLevelState.setValue(value);
}
}

export default Blind;
111 changes: 111 additions & 0 deletions src/lib/devices/BlindButtons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import GenericDevice, {
DetectedDevice,
DeviceStateObject,
PropertyType,
StateAccessType,
ValueType
} from './GenericDevice';

/*
Blinds controlled only by buttons [blindButtons]
R Name Role Type Wr Ind Mult Regex
* STOP button.stop.blind boolean W /^button\.stop(\.blind)?$|^action\.stop$/
* OPEN button.open.blind boolean W /^button\.open(\.blind)?$/
* CLOSE button.close.blind boolean W /^button\.close(\.blind)?$/
TILT_SET level.tilt number W /^level\.tilt$/
TILT_ACTUAL value.tilt number /^value\.tilt$/
TILT_STOP button.stop.tilt boolean W /^button\.stop\.tilt$/
TILT_OPEN button.open.tilt boolean W /^button\.open\.tilt$/
TILT_CLOSE button.close.tilt boolean W /^button\.close\.tilt$/
DIRECTION indicator.direction X /^indicator\.direction$/
WORKING indicator.working X /^indicator\.working$/
UNREACH indicator.maintenance.unreach boolean X /^indicator(\.maintenance)?\.unreach$/
LOWBAT indicator.maintenance.lowbat boolean X /^indicator(\.maintenance)?\.lowbat$|^indicator(\.maintenance)?\.battery$/
MAINTAIN indicator.maintenance boolean X /^indicator\.maintenance$/
ERROR indicator.error X /^indicator\.error$/
*/

class BlindButtons extends GenericDevice {
protected _setStopState: DeviceStateObject<boolean> | undefined;
protected _setOpenState: DeviceStateObject<boolean> | undefined;
protected _setCloseState: DeviceStateObject<boolean> | undefined;
protected _getTiltState: DeviceStateObject<number> | undefined;
protected _setTiltState: DeviceStateObject<number> | undefined;
protected _setTiltStopState: DeviceStateObject<boolean> | undefined;
protected _setTiltOpenState: DeviceStateObject<boolean> | undefined;
protected _setTiltCloseState: DeviceStateObject<boolean> | undefined;

constructor(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter) {
super(detectedDevice, adapter);

this._ready.push(this.addDeviceStates([
{ name: 'STOP', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.Stop, callback: state => this._setStopState = state },
{ name: 'OPEN', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.Open, callback: state => this._setOpenState = state },
{ name: 'CLOSE', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.Close, callback: state => this._setCloseState = state },
// actual value first, as it will be read first
{ name: 'TILT_ACTUAL', valueType: ValueType.NumberPercent, accessType: StateAccessType.Read, type: PropertyType.TiltLevel, callback: state => this._getTiltState = state },
{ name: 'TILT_SET', valueType: ValueType.NumberPercent, accessType: StateAccessType.ReadWrite, type: PropertyType.TiltLevel, callback: state => this._setTiltState = state },
{ name: 'TILT_STOP', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.TiltStop, callback: state => this._setTiltStopState = state },
{ name: 'TILT_OPEN', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.TiltOpen, callback: state => this._setTiltOpenState = state },
{ name: 'TILT_CLOSE', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.TiltClose, callback: state => this._setTiltCloseState = state },
]));
}

async setStop(): Promise<void> {
if (!this._setStopState) {
throw new Error('Stop state not found');
}
return this._setStopState.setValue(true);
}

async setOpen(): Promise<void> {
if (!this._setOpenState) {
throw new Error('Open state not found');
}
return this._setOpenState.setValue(true);
}

async setClose(): Promise<void> {
if (!this._setCloseState) {
throw new Error('Close state not found');
}
return this._setCloseState.setValue(true);
}

getTiltLevel(): number | undefined {
if (!this._getTiltState) {
throw new Error('Tilt state not found');
}
return this._getTiltState.value;
}

async setTiltLevel(value: number): Promise<void> {
if (!this._setTiltState) {
throw new Error('Tilt state not found');
}
return this._setTiltState.setValue(value);
}

async setTiltStop(): Promise<void> {
if (!this._setTiltStopState) {
throw new Error('Tilt stop state not found');
}
return this._setTiltStopState.setValue(true);
}

async setTiltOpen(): Promise<void> {
if (!this._setTiltOpenState) {
throw new Error('Tilt open state not found');
}
return this._setTiltOpenState.setValue(true);
}

async setTiltClose(): Promise<void> {
if (!this._setTiltCloseState) {
throw new Error('Tilt close state not found');
}
return this._setTiltCloseState.setValue(true);
}
}

export default BlindButtons;
28 changes: 28 additions & 0 deletions src/lib/devices/Button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import GenericDevice, {
DetectedDevice,
DeviceStateObject,
PropertyType,
StateAccessType,
ValueType
} from './GenericDevice';

class Button extends GenericDevice {
_setPressState: DeviceStateObject<boolean> | undefined;

constructor(detectedDevice: DetectedDevice, adapter: ioBroker.Adapter) {
super(detectedDevice, adapter);

this._ready.push(this.addDeviceStates([
{ name: 'SET', valueType: ValueType.Button, accessType: StateAccessType.Write, type: PropertyType.Press, callback: state => this._setPressState = state },
]));
}

async setPress(): Promise<void> {
if (!this._setPressState) {
throw new Error('Press state not found');
}
return this._setPressState.setValue(true);
}
}

export default Button;
Loading

0 comments on commit 419e6c3

Please sign in to comment.