Allow selecting light effect. Fix #67

This commit is contained in:
Thomas Lovén 2019-08-28 15:38:57 +02:00
parent 77eedac4ad
commit 77378ab468
3 changed files with 30 additions and 1 deletions

View File

@ -89,6 +89,7 @@ Currently, the following attribute settings are supported.
- `red` - `red`
- `green` - `green`
- `blue` - `blue`
- `effect`
**For `cover` domain:** **For `cover` domain:**

File diff suppressed because one or more lines are too long

View File

@ -23,11 +23,24 @@ export class LightController extends Controller {
return this.stateObj.attributes.hs_color ? Math.ceil(this.stateObj.attributes.hs_color[0]): 0; return this.stateObj.attributes.hs_color ? Math.ceil(this.stateObj.attributes.hs_color[0]): 0;
case "saturation": case "saturation":
return this.stateObj.attributes.hs_color ? Math.ceil(this.stateObj.attributes.hs_color[1]): 0; return this.stateObj.attributes.hs_color ? Math.ceil(this.stateObj.attributes.hs_color[1]): 0;
case "effect":
if(this.stateObj.attributes.effect_list)
return (this.stateObj.attributes.effect_list.indexOf(this.stateObj.attributes.effect));
return 0;
default: default:
return 0; return 0;
} }
} }
get _step() {
switch (this.attribute) {
case "effect":
return 1;
default:
return 5;
}
}
get _min() { get _min() {
switch (this.attribute) { switch (this.attribute) {
case "color_temp": case "color_temp":
@ -46,6 +59,8 @@ export class LightController extends Controller {
return 255; return 255;
case "hue": case "hue":
return 360; return 360;
case "effect":
return this.stateObj.attributes.effect_list ? this.stateObj.attributes.effect_list.length - 1 : 0;
default: default:
return 100; return 100;
} }
@ -78,6 +93,10 @@ export class LightController extends Controller {
value = _value; value = _value;
attr = "hs_color"; attr = "hs_color";
break; break;
case "effect":
value = this.stateObj.attributes.effect_list[value];
attr = "effect";
break;
} }
if (on) { if (on) {
@ -103,6 +122,8 @@ export class LightController extends Controller {
return `${this.value} %`; return `${this.value} %`;
case "hue": case "hue":
return `${this.value} °`; return `${this.value} °`;
case "effect":
return this.stateObj.attributes.effect;
default: default:
return this.value; return this.value;
} }
@ -114,21 +135,28 @@ export class LightController extends Controller {
if ("brightness" in this.stateObj.attributes) return true; if ("brightness" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) && if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 1)) return true; (this.stateObj.attributes.supported_features & 1)) return true;
return false;
case "color_temp": case "color_temp":
if ("color_temp" in this.stateObj.attributes) return true; if ("color_temp" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) && if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 2)) return true; (this.stateObj.attributes.supported_features & 2)) return true;
return false;
case "red": case "red":
case "green": case "green":
case "blue": case "blue":
if ("rgb_color" in this.stateObj.attributes) return true; if ("rgb_color" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) && if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 16)) return true; (this.stateObj.attributes.supported_features & 16)) return true;
return false;
case "hue": case "hue":
case "saturation": case "saturation":
if ("hs_color" in this.stateObj.attributes) return true; if ("hs_color" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) && if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 16)) return true; (this.stateObj.attributes.supported_features & 16)) return true;
return false;
case "effect":
if ("effect" in this.stateObj.attributes) return true;
return false;
default: default:
return false; return false;
} }