Skip to content

Commit

Permalink
Change default color_temp to kelvin. Add color_temp_mired. Fix #259
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Dec 26, 2022
1 parent bc03d50 commit c9cb302
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ Currently, the following attribute settings are supported.
- `brightness_pct` - default
- `brightness`
- `color_temp`
- `color_temp_mired`
- `hue`
- `saturation`
- `red`
- `green`
- `blue`
- `effect`
- `white_value` - deprecated
- `white` - for RGBW lights only
- `cold_white` - for RGBWW lights only
- `warm_white` - for RGBWW lights only
Expand Down
24 changes: 23 additions & 1 deletion slider-entity-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class LightController extends Controller {
const attr = this.stateObj.attributes;
switch (this.attribute) {
case "color_temp":
return Math.round(attr.color_temp_kelvin);
case "color_temp_mired":
return Math.round(attr.color_temp);
case "white_value":
return Math.round(attr.white_value);
Expand Down Expand Up @@ -202,6 +204,10 @@ class LightController extends Controller {
get _min() {
switch (this.attribute) {
case "color_temp":
return this.stateObj
? this.stateObj.attributes.min_color_temp_kelvin
: 0;
case "color_temp_mired":
return this.stateObj ? this.stateObj.attributes.min_mireds : 0;
default:
return 0;
Expand All @@ -210,6 +216,10 @@ class LightController extends Controller {
get _max() {
switch (this.attribute) {
case "color_temp":
return this.stateObj
? this.stateObj.attributes.max_color_temp_kelvin
: 0;
case "color_temp_mired":
return this.stateObj ? this.stateObj.attributes.max_mireds : 0;
case "red":
case "green":
Expand Down Expand Up @@ -292,6 +302,12 @@ class LightController extends Controller {
value = this.stateObj.attributes.effect_list[value];
attr = "effect";
break;
case "color_temp":
attr = "kelvin";
break;
case "color_temp_mired":
attr = "color_temp";
break;
}
if (on) {
this._hass.callService("light", "turn_on", {
Expand All @@ -309,9 +325,11 @@ class LightController extends Controller {
if (this.stateObj && this.stateObj.state === "off")
return this._hass.localize("component.light.state._.off");
switch (this.attribute) {
case "color_temp":
case "color_temp_mired":
case "brightness":
return `${this.value}`;
case "color_temp":
return `${this.value} K`;
case "brightness_pct":
case "saturation":
return `${this.value} %`;
Expand Down Expand Up @@ -354,6 +372,10 @@ class LightController extends Controller {
if ("color_temp" in this.stateObj.attributes || support_temp)
return true;
return false;
case "color_temp_mired":
if ("color_temp" in this.stateObj.attributes || support_temp)
return true;
return false;
case "white_value":
if (attr.supported_features & 128 ||
"white_value" in this.stateObj.attributes)
Expand Down
24 changes: 23 additions & 1 deletion src/controllers/light-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class LightController extends Controller {
const attr = this.stateObj.attributes;
switch (this.attribute) {
case "color_temp":
return Math.round(attr.color_temp_kelvin);
case "color_temp_mired":
return Math.round(attr.color_temp);
case "white_value":
return Math.round(attr.white_value);
Expand Down Expand Up @@ -83,6 +85,10 @@ export class LightController extends Controller {
get _min() {
switch (this.attribute) {
case "color_temp":
return this.stateObj
? this.stateObj.attributes.min_color_temp_kelvin
: 0;
case "color_temp_mired":
return this.stateObj ? this.stateObj.attributes.min_mireds : 0;
default:
return 0;
Expand All @@ -91,6 +97,10 @@ export class LightController extends Controller {
get _max() {
switch (this.attribute) {
case "color_temp":
return this.stateObj
? this.stateObj.attributes.max_color_temp_kelvin
: 0;
case "color_temp_mired":
return this.stateObj ? this.stateObj.attributes.max_mireds : 0;
case "red":
case "green":
Expand Down Expand Up @@ -173,6 +183,12 @@ export class LightController extends Controller {
value = this.stateObj.attributes.effect_list[value];
attr = "effect";
break;
case "color_temp":
attr = "kelvin";
break;
case "color_temp_mired":
attr = "color_temp";
break;
}

if (on) {
Expand All @@ -191,9 +207,11 @@ export class LightController extends Controller {
if (this.stateObj && this.stateObj.state === "off")
return this._hass.localize("component.light.state._.off");
switch (this.attribute) {
case "color_temp":
case "color_temp_mired":
case "brightness":
return `${this.value}`;
case "color_temp":
return `${this.value} K`;
case "brightness_pct":
case "saturation":
return `${this.value} %`;
Expand Down Expand Up @@ -248,6 +266,10 @@ export class LightController extends Controller {
if ("color_temp" in this.stateObj.attributes || support_temp)
return true;
return false;
case "color_temp_mired":
if ("color_temp" in this.stateObj.attributes || support_temp)
return true;
return false;
case "white_value":
if (
attr.supported_features & 128 ||
Expand Down
3 changes: 3 additions & 0 deletions test/views/3_attributes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ cards:
- <<: *light
name: color_temp
attribute: color_temp
- <<: *light
name: color_temp_mired
attribute: color_temp_mired
- <<: *light
name: hue
attribute: hue
Expand Down

0 comments on commit c9cb302

Please sign in to comment.