Skip to content

Commit

Permalink
Create a deep copy of the config instead of editing it
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub committed Feb 20, 2020
1 parent ebf7bb7 commit 7766de8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions card.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class RGBLightCard extends HTMLElement {
return style;
}

setConfig(config) {
config = RGBLightCard.ensureBackwardCompatibility(config);
setConfig(haConfig) {
const config = RGBLightCard.ensureBackwardCompatibility(haConfig);

// Colors must be a defined array
if (!Array.isArray(config.colors)) {
Expand Down Expand Up @@ -109,7 +109,9 @@ class RGBLightCard extends HTMLElement {
}

// Transform a deprecated config into a more recent one
static ensureBackwardCompatibility(config) {
static ensureBackwardCompatibility(originalConfig) {
// Create a deep copy of the config
const config = JSON.parse(JSON.stringify(originalConfig));
if (!config.colors || !Array.isArray(config.colors)) {
return config;
}
Expand Down Expand Up @@ -163,7 +165,7 @@ class RGBLightCard extends HTMLElement {
customElements.define('rgb-light-card', RGBLightCard);

console.info(
'\n %c RGB Light Card %c v1.4.0 %c \n',
'\n %c RGB Light Card %c v1.4.1 %c \n',
'background-color: #555;color: #fff;padding: 4px 2px 4px 4px;border-radius: 3px 0 0 3px;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)',
'background-color: #bc81e0;background-image: linear-gradient(90deg, #b65cff, #11cbfa);color: #fff;padding: 4px 4px 4px 2px;border-radius: 0 3px 3px 0;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)',
'background-color: transparent'
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rgb-light-card",
"description": "A Lovelace custom card for RGB lights",
"version": "1.4.0",
"version": "1.4.1",
"author": "Boris K",
"bugs": "https://github.com/bokub/rgb-light-card/issues",
"devDependencies": {
Expand All @@ -14,8 +14,7 @@
"yamljs": "^0.3.0"
},
"files": [
"card.js",
"hacs.json"
"card.js"
],
"homepage": "https://github.com/bokub/rgb-light-card",
"keywords": [
Expand Down

0 comments on commit 7766de8

Please sign in to comment.