Skip to content

Commit

Permalink
moved to webpack; added editor card
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmerza committed Apr 9, 2019
1 parent 0f72edb commit 56f9933
Show file tree
Hide file tree
Showing 13 changed files with 613 additions and 131 deletions.
36 changes: 26 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<h1 align="center">Light Entity Card</h1>
<h4 align="center">Control any light/switch entity through lovelace</h4>
# Light Entity Card</h1>
#### Control any light/switch entity through lovelace</h4>

<p align="center">
<img src='https://i.imgur.com/5An8qQD.png' />
</p>
<img src='https://i.imgur.com/5An8qQD.png' />

<h2>Features</h2>
[![GitHub Release][releases-shield]][releases]
[![License][license-shield]](LICENSE.md)

![Project Maintenance][maintenance-shield]
[![GitHub Activity][commits-shield]][commits]

## Features

* Works on any light and switch based entity
* Toggle on/off
Expand All @@ -17,7 +21,7 @@
* use `effects_list` to add custom effects list or use `input_select` entity
* always show or hide header and each input

<h2>Track Updates</h2>
## Track Updates

This custom card can be tracked with the help of [custom-updater](https://github.com/custom-components/custom_updater).

Expand All @@ -36,14 +40,14 @@ custom_updater:
entity: light.downstairs
```
<h2>Options</h2>
## Options
| Name | Type | Requirement | `Default value` Description
| ---- | ---- | ------- | -----------
| type | string | **Required** | `custom:light-entity-card`
| entity | string | **Required** | The entity name of the light entity to control
| group | boolean | **Optional** | `false` Compacts card
| colorWheel | boolean | **Optional** | `true` Show color-picker if entity has support
| color_wheel | boolean | **Optional** | `true` Show color-picker if entity has support
| persist_features | boolean | **Optional** | `false` always show entity features
| effects_list | list|string|boolean | **Optional** | custom list of effects, an input_select entity, or set false to always hide
| header | boolean | string | **Optional** | custom header name or `false` to hide header
Expand All @@ -53,7 +57,7 @@ custom_updater:
| color_picker | boolean | **Optional** | `true` show color picker wheel if available


<h2>Configuration</h2>
## Configuration

Download `light-entity-card.js` from the [latest release](https://github.com/ljmerza/light-entity-card/releases/latest/) and upload it your /www folder of your Home Assistant config directory.

Expand Down Expand Up @@ -96,3 +100,15 @@ views:
group: true
persist_features: true
```

Enjoy my card? Help me out for a couple of :beers: or a :coffee:!

[![coffee](https://www.buymeacoffee.com/assets/img/custom_images/black_img.png)](https://www.buymeacoffee.com/JMISm06AD)


[commits-shield]: https://img.shields.io/github/commit-activity/y/ljmerza/light-entity-card.svg?style=for-the-badge
[commits]: https://github.com/ljmerza/light-entity-card/commits/master
[license-shield]: https://img.shields.io/github/license/ljmerza/light-entity-card.svg?style=for-the-badge
[maintenance-shield]: https://img.shields.io/badge/maintainer-Leonardo%20Merza%20%40ljmerza-blue.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/ljmerza/light-entity-card.svg?style=for-the-badge
[releases]: https://github.com/ljmerza/light-entity-card/releases
4 changes: 2 additions & 2 deletions custom_updater.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"light-entity-card": {
"updated_at": "2019-04-03",
"version": "2.3.1",
"updated_at": "2019-04-09",
"version": "2.4.0",
"remote_location": "https://raw.githubusercontent.com/ljmerza/light-entity-card/master/light-entity-card.js",
"visit_repo": "https://github.com/ljmerza/light-entity-card",
"changelog": "https://github.com/ljmerza/light-entity-card/releases/latest"
Expand Down
321 changes: 281 additions & 40 deletions light-entity-card.js

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions package.json
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",
Expand All @@ -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"
}
}
16 changes: 0 additions & 16 deletions rollup.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/defaults.js
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,
};
157 changes: 157 additions & 0 deletions src/index-editor.js
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 });
}
}

Loading

0 comments on commit 56f9933

Please sign in to comment.