Skip to content

Commit

Permalink
Added useRGB besides the temperature and brightness option to disable…
Browse files Browse the repository at this point in the history
… icon color change based on light color
  • Loading branch information
DBuit committed Apr 21, 2021
1 parent ff42817 commit b2755ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ in the card we can define some global configuration below you can find these opt
| `rulesColor` | string | optional | "#FFF" | Default the text is white and this can be overwritten with a new color |
| `tileHoldAnimation` | boolean | optional | false | When true the tile with grow in size when holding :) |
| `title` | string | optional | "" | When home is true you can give your page a title |
| `useRGB` | boolean | optional | true | When true the lights rgb value is used to color the icon |
| `useBrightness` | boolean | optional | true | When true the lights brightness is used to color the icon |
| `useTemperature` | boolean | optional | false | When true the temperature is used to color the icon |
| `titleColor` | number | optional | | Titles above a row of tiles is colored by them this can overwrite this color |
Expand Down Expand Up @@ -602,6 +603,7 @@ views:
title: "Home"
useBrightness: false
useTemperature: false
useRGB: false
titleColor: "#FFF"
entities:
- title: Navigatie
Expand Down Expand Up @@ -755,6 +757,7 @@ views:
title: "Home"
useBrightness: false
useTemperature: false
useRGB: false
titleColor: "#FFF"
enableColumns: true
statePositionTop: true
Expand Down
14 changes: 9 additions & 5 deletions dist/homekit-panel-card.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/homekit-panel-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class HomeKitCard extends LitElement {
rulesColor: any;
useTemperature = false;
useBrightness = false;
useRGB = false;
CUSTOM_TYPE_PREFIX = "custom:";
masonry = false;

Expand All @@ -53,6 +54,7 @@ class HomeKitCard extends LitElement {
this.config = config;
this.useTemperature = "useTemperature" in this.config ? this.config.useTemperature : false;
this.useBrightness = "useBrightness" in this.config ? this.config.useBrightness : true;
this.useRGB = "useRGB" in this.config ? this.config.useRGB : true;
this.rowTitleColor = this.config.titleColor ? this.config.titleColor : false;
this.horizontalScroll = "horizontalScroll" in this.config ? this.config.fullscreen : false;
this.enableColumns = "enableColumns" in this.config ? this.config.enableColumns : false;
Expand Down Expand Up @@ -370,7 +372,7 @@ class HomeKitCard extends LitElement {
if (ent.color) {
color = ent.color
} else {
color = this._getColorForLightEntity(stateObj, this.useTemperature, this.useBrightness);
color = this._getColorForLightEntity(stateObj, this.useTemperature, this.useBrightness, this.useRGB);
}
const type = ent.entity.split('.')[0];
if (type == "light") {
Expand Down Expand Up @@ -813,11 +815,13 @@ class HomeKitCard extends LitElement {
}


_getColorForLightEntity(stateObj, useTemperature, useBrightness) {
let color = this.config.default_color ? this.config.default_color : undefined;
_getColorForLightEntity(stateObj, useTemperature, useBrightness, useRGB) {
let color = this.config.default_color ? this.config.default_color : this._getDefaultColorForState();
if (stateObj) {
if (stateObj.attributes.rgb_color) {
color = `rgb(${stateObj.attributes.rgb_color.join(',')})`;
if(useRGB) {
color = `rgb(${stateObj.attributes.rgb_color.join(',')})`;
}
if (useBrightness && stateObj.attributes.brightness) {
color = this._applyBrightnessToColor(color, (stateObj.attributes.brightness + 245) / 5);
}
Expand Down

0 comments on commit b2755ec

Please sign in to comment.