forked from ljmerza/light-entity-card
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
613 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "light-entity-card", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"description": "A light-entity card for Home Assistant Lovelace UI", | ||
"keywords": [ | ||
"home-assistant", | ||
|
@@ -11,28 +11,29 @@ | |
"custom-cards", | ||
"light-entity" | ||
], | ||
"main": "main.js", | ||
"module": "main.js", | ||
"repository": "[email protected]:ljmerza/light-entity-card.git", | ||
"author": "Leonardo Merza <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"lit-element": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/plugin-transform-modules-umd": "^7.2.0", | ||
"@babel/polyfill": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"babel-loader": "^8.0.5", | ||
"eslint": "^5.13.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-replace": "^2.1.0", | ||
"rollup-plugin-terser": "^3.0.0" | ||
"webpack": "^4.29.6", | ||
"webpack-cli": "^3.3.0", | ||
"webpack-merge": "^4.2.1" | ||
}, | ||
"scripts": { | ||
"build": "npm run lint && npm run rollup", | ||
"rollup": "rollup -c", | ||
"lint": "eslint main.js style.js", | ||
"watch": "rollup -c --watch" | ||
"lint": "eslint ./src", | ||
"start": "webpack --watch --config webpack/config.dev.js", | ||
"build": "webpack --config webpack/config.prod.js" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
group: false, | ||
color_wheel: true, | ||
persist_features: false, | ||
brightness: true, | ||
color_temp: true, | ||
white_value: true, | ||
color_picker: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { LitElement, html } from 'lit-element'; | ||
import style from './style-editor'; | ||
import defaultConfig from './defaults'; | ||
|
||
|
||
const fireEvent = (node, type, detail = {}, options = {}) => { | ||
const event = new Event(type, { | ||
bubbles: options.bubbles === undefined ? true : options.bubbles, | ||
cancelable: Boolean(options.cancelable), | ||
composed: options.composed === undefined ? true : options.composed, | ||
}); | ||
|
||
event.detail = detail; | ||
node.dispatchEvent(event); | ||
return event; | ||
}; | ||
|
||
|
||
export default class LightEntityCardEditor extends LitElement { | ||
static get styles() { | ||
return style; | ||
} | ||
|
||
static get properties() { | ||
return { hass: {}, _config: {} }; | ||
} | ||
|
||
setConfig(config) { | ||
this._config = { | ||
...defaultConfig, | ||
...config | ||
}; | ||
} | ||
|
||
get entityOptions() { | ||
return Object.keys(this.hass.states).filter(eid => { | ||
return ['switch', 'light', 'group'].includes( eid.substr(0, eid.indexOf('.')) ) | ||
}); | ||
} | ||
|
||
firstUpdated(){ | ||
this._firstRendered = true; | ||
} | ||
|
||
render() { | ||
if (!this.hass) { | ||
return html``; | ||
} | ||
|
||
return html` | ||
<div class="card-config"> | ||
<div class=overall-config'> | ||
<paper-input | ||
label="Header (Optional)" | ||
.value="${this._config.header}" | ||
.configValue="${"header"}" | ||
@value-changed="${this._valueChanged}" | ||
></paper-input> | ||
</div> | ||
<div class='entities'> | ||
<paper-dropdown-menu | ||
label="Entity" | ||
@value-changed="${this._valueChanged}" | ||
.configValue="${"entity"}" | ||
> | ||
<paper-listbox | ||
slot="dropdown-content" | ||
.selected="${this.entityOptions.indexOf(this._config.entity)}" | ||
> | ||
${ | ||
this.entityOptions.map(entity => { | ||
return html`<paper-item>${entity}</paper-item>`; | ||
}) | ||
} | ||
</paper-listbox> | ||
</paper-dropdown-menu> | ||
</div> | ||
<div class=overall-config'> | ||
<div class='checkbox-options'> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.color_wheel} | ||
.configValue="${"color_wheel"}" | ||
>Show Color Wheel</paper-checkbox> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.group} | ||
.configValue="${"group"}" | ||
>Group Entities</paper-checkbox> | ||
</div> | ||
<div class='checkbox-options'> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.persist_features} | ||
.configValue="${"persist_features"}" | ||
>Persist Features</paper-checkbox> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.brightness} | ||
.configValue="${"brightness"}" | ||
>Show Brightness</paper-checkbox> | ||
</div> | ||
<div class='checkbox-options'> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.color_temp} | ||
.configValue="${"color_temp"}" | ||
>Show Color Temp</paper-checkbox> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.white_value} | ||
.configValue="${"white_value"}" | ||
>Show White Value</paper-checkbox> | ||
</div> | ||
<div class='checkbox-options'> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.color_picker} | ||
.configValue="${"color_picker"}" | ||
>Show Color Picker</paper-checkbox> | ||
<paper-checkbox | ||
@checked-changed="${this._valueChanged}" | ||
.checked=${this._config.effects_list} | ||
.configValue="${"effects_list"}" | ||
>Show Effects List</paper-checkbox> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
_valueChanged(ev) { | ||
console.log({ ev }); | ||
|
||
if (!this._config || !this.hass || !this._firstRendered) return; | ||
const { target: { configValue, value }, detail: { value: checkedValue} } = ev; | ||
|
||
if (checkedValue !== undefined || checkedValue !== null){ | ||
this._config = { ...this._config, [configValue]: checkedValue }; | ||
} else { | ||
this._config = { ...this._config, [configValue]: value }; | ||
} | ||
|
||
console.log(this._config); | ||
fireEvent(this, 'config-changed', { config: this._config }); | ||
} | ||
} | ||
|
Oops, something went wrong.