Skip to content

Commit

Permalink
πŸŽ‰ We're in business
Browse files Browse the repository at this point in the history
This is nuts
  • Loading branch information
iantrich committed Mar 13, 2019
1 parent 26f8982 commit 6177ab6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
77 changes: 76 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
<h1 align="center"> Config Template Card for Home Assistant</h1>
# 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 `<config directory>/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
18 changes: 17 additions & 1 deletion dist/config-template-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/config-template-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down

0 comments on commit 6177ab6

Please sign in to comment.