All files / src/models scene.ts

63.83% Statements 30/47
25% Branches 2/8
50% Functions 8/16
64.52% Lines 20/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66  1x     1x 1x     1x     1x     1x 1x 1x   1x 1x   1x     1x       1x     1x         1x                 1x     1x     1x                   1x       1x
import { Color } from "./color";
import { SceneType, StartFlowAction } from "./enums";
import { FlowState } from "./flow-state";
 
export class Scene {
    constructor(public type: SceneType) {
 
    }
    public getData(): any[] {
        return null;
    }
}
 
// tslint:disable-next-line:max-classes-per-file
export class ColorScene extends Scene {
    constructor(public color: Color, public bright: number) {
        super(SceneType.COLOR);
    }
    public getData() {
        return [this.type, this.color.getValue(), this.bright];
    }
}
 
// tslint:disable-next-line:max-classes-per-file
export class HsvScene extends Scene {
    constructor(public hue: number, public satuation: number, public brightness: number) {
        super(SceneType.HSV);
    }
    public getData() {
        return [this.type, this.hue, this.satuation, this.brightness];
    }
}
/**
 * change the smart LED to specified ct and brightness
 */
// tslint:disable-next-line:max-classes-per-file
export class CtScene extends Scene {
    /**
     * @constructor
     * @param temperature : K temperature value
     * @param brightness  max brightness level
     */
    constructor(public temperature: number, public brightness: number) {
        super(SceneType.CT);
    }
    public getData() {
        return [this.type, this.temperature, this.brightness];
    }
}
 
// tslint:disable-next-line:max-classes-per-file
export class CfScene extends Scene {
    /**
     * @constructor
     * @param flowAction The LED behavior after flow finish
     * @param states : The set of state changes
     * @param repeat : number of repeas. 0 is infinity
     */
    constructor(public flowAction: StartFlowAction, public states: FlowState[], public repeat: number) {
        super(SceneType.CF);
    }
    public getData() {
        const list = this.states.reduce((a, b) => [...a, ...b.getState()], []);
        return [this.type, this.repeat, this.flowAction, list.join(",")];
    }
}