diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6893c34 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Custom cards for Home Assistant + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 846bb5a..64efb3b 100644 --- a/README.md +++ b/README.md @@ -1 +1,76 @@ -

Config Template Card for Home Assistant

+# Config Template Card Card +📝 Templatable Configuration Card + +[![GitHub Release][releases-shield]][releases] +[![License][license-shield]](LICENSE.md) + +![Project Maintenance][maintenance-shield] +[![GitHub Activity][commits-shield]][commits] + +[![Discord][discord-shield]][discord] +[![Community Forum][forum-shield]][forum] + +## Support +Hey dude! 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/zJtVxUAgH) + +This card is for [Lovelace](https://www.home-assistant.io/lovelace) on [Home Assistant](https://www.home-assistant.io/) that allows you to use pretty much any valid Javascript on the hass object in your configuration + +## Options + +| Name | Type | Requirement | Description +| ---- | ---- | ------- | ----------- +| type | string | **Required** | `custom:config-template-card` +| config | object | **Required** | Card object + +## Installation + +### Step 1 + +Save [config-template-card](https://github.com/custom-cards/config-template-card/raw/master/dist/config-template-card.js) to `/www/config-template-card.js` on your Home Assistant instanse. + +**Example:** + +```bash +wget https://raw.githubusercontent.com/custom-cards/config-template-card/master/dist/config-template-card.js +mv pc-card.js /config/www/ +``` + +### Step 2 + +Link `config-template-card` inside your `ui-lovelace.yaml` or Raw Editor in the UI Editor + +```yaml +resources: + - url: /local/config-template-card.js + type: module +``` + +### Step 3 + +Add a custom element in your `ui-lovelace.yaml` or in the UI Editor as a Manual Card + +```yaml + - type: custom:config-template-card + card: + type: entity-button + name: "${this.hass.states['media_player.office'].state === 'playing' ? 'Rocking' : 'Not Rocking'}" + entity: + icon: "${this.hass.states['media_player.office'].state === 'playing' ? 'mdi:music' : 'mdi:sleep'}" +``` + +More examples to come, but you can pretty much go crazy using the [this.hass](https://developers.home-assistant.io/docs/en/frontend_data.html) object + +[Troubleshooting](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins) + +[commits-shield]: https://img.shields.io/github/commit-activity/y/custom-cards/config-template-card.svg?style=for-the-badge +[commits]: https://github.com/custom-cards/config-template-card/commits/master +[discord]: https://discord.gg/Qa5fW2R +[discord-shield]: https://img.shields.io/discord/478094546522079232.svg?style=for-the-badge +[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=for-the-badge +[forum]: https://community.home-assistant.io/t/lovelace-personal-capital-component-card/91463 +[license-shield]: https://img.shields.io/github/license/custom-cards/config-template-card.svg?style=for-the-badge +[maintenance-shield]: https://img.shields.io/badge/maintainer-Ian%20Richardson%20%40iantrich-blue.svg?style=for-the-badge +[releases-shield]: https://img.shields.io/github/release/custom-cards/config-template-card.svg?style=for-the-badge +[releases]: https://github.com/custom-cards/config-template-card/releases diff --git a/dist/config-template-card.js b/dist/config-template-card.js index 66eb3e8..829dc59 100644 --- a/dist/config-template-card.js +++ b/dist/config-template-card.js @@ -2255,6 +2255,22 @@ LitElement.finalized = true; */ LitElement.render = render$1; +function deepcopy(value) { + if (!(!!value && typeof value == 'object')) { + return value; + } + if (Object.prototype.toString.call(value) == '[object Date]') { + return new Date(value.getTime()); + } + if (Array.isArray(value)) { + return value.map(deepcopy); + } + var result = {}; + Object.keys(value).forEach( + function(key) { result[key] = deepcopy(value[key]); }); + return result; +} + const fireEvent = (node, type, detail, options) => { options = options || {}; detail = detail === null || detail === undefined ? {} : detail; @@ -2281,7 +2297,7 @@ let ConfigTemplateCard = class ConfigTemplateCard extends LitElement { } // this.hass.states // this.hass.user.name - let cardConfig = this._config.config; + let cardConfig = deepcopy(this._config.config); cardConfig = this._evaluateConfig(cardConfig); console.log(this._config.config); console.log(cardConfig); diff --git a/src/config-template-card.ts b/src/config-template-card.ts index a996010..cc9b9f9 100644 --- a/src/config-template-card.ts +++ b/src/config-template-card.ts @@ -7,6 +7,7 @@ import { TemplateResult, css } from "lit-element"; +import deepClone from "deep-clone-simple"; import { ConfigTemplateConfig, HomeAssistant } from "./types"; import { fireEvent } from "./fire-event"; @@ -33,7 +34,7 @@ class ConfigTemplateCard extends LitElement { // this.hass.states // this.hass.user.name - let cardConfig = this._config.config; + let cardConfig = deepClone(this._config.config); cardConfig = this._evaluateConfig(cardConfig); console.log(this._config.config);