Skip to content

Commit

Permalink
Merge branch 'master' of github.com:denysdovhan/purifier-card
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Aug 17, 2021
2 parents 7610929 + 1ce2ad0 commit 37d2383
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 74 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ compact_view: false

Here is what every option means:

| Name | Type | Default | Description |
| -------------- | :-------: | ------------ | ------------------------------------------------ |
| `type` | `string` | **Required** | `custom:purifier-card` |
| `entity` | `string` | **Required** | An entity_id within the `fan` domain. |
| `show_name` | `boolean` | `true` | Show friendly name of the purifier. |
| `show_status` | `boolean` | `true` | Show status of the purifier. |
| `show_toolbar` | `boolean` | `true` | Show toolbar with actions. |
| `compact_view` | `boolean` | `false` | Compact view without image. |
| `aqi` | `object` | Optional | Custom entity or attribute for AQI value. |
| `stats` | `object` | Optional | Custom per state stats for your purifier cleaner |
| `actions` | `object` | Optional | Custom actions for your purifier cleaner. |
| Name | Type | Default | Description |
| ----------------- | :-------: | ------------ | ------------------------------------------------ |
| `type` | `string` | **Required** | `custom:purifier-card` |
| `entity` | `string` | **Required** | An entity_id within the `fan` domain. |
| `show_name` | `boolean` | `true` | Show friendly name of the purifier. |
| `show_status` | `boolean` | `true` | Show status of the purifier. |
| `show_speed` | `boolean` | `false` | Show speed of the purifier in the header. |
| `show_preset_mode`| `boolean` | `true` | Show preset mode of the purifier in the header. |
| `show_toolbar` | `boolean` | `true` | Show toolbar with actions. |
| `compact_view` | `boolean` | `false` | Compact view without image. |
| `aqi` | `object` | Optional | Custom entity or attribute for AQI value. |
| `stats` | `object` | Optional | Custom per state stats for your purifier cleaner |
| `actions` | `object` | Optional | Custom actions for your purifier cleaner. |

### `aqi` object

Expand Down
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purifier-card",
"version": "0.10.0",
"version": "0.10.3",
"description": "Air Purifier card for Home Assistant Lovelace UI",
"main": "dist/purifier-card.js",
"scripts": {
Expand Down
126 changes: 73 additions & 53 deletions src/purifier-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ class PurifierCard extends LitElement {
get entity() {
return this.hass.states[this.config.entity];
}

get showSpeed() {
if (this.config.show_speed === undefined) {
return false;
}

return this.config.show_speed;
}

get showPresetMode() {
if (this.config.show_preset_mode === undefined) {
return true;
}

return this.config.show_preset_mode;
}

get showName() {
if (this.config.show_name === undefined) {
return true;
Expand Down Expand Up @@ -151,38 +167,40 @@ class PurifierCard extends LitElement {
} = this.entity;

// TODO handle percentages
if (!speed_list || !(supported_features & SUPPORT_SET_SPEED)) {
if (!this.showSpeed || !speed_list || !(supported_features & SUPPORT_SET_SPEED)) {
return html``;
}

const selected = speed_list.indexOf(speed);

return html`
<paper-menu-button
slot="dropdown-trigger"
.horizontalAlign=${'right'}
.verticalAlign=${'top'}
.verticalOffset=${40}
.noAnimations=${true}
@click="${(e) => e.stopPropagation()}"
>
<paper-button slot="dropdown-trigger">
<ha-icon icon="mdi:fan"></ha-icon>
<span show=${true}> ${localize(`speed.${speed}`) || speed} </span>
</paper-button>
<paper-listbox
slot="dropdown-content"
selected=${selected}
@click="${(e) => this.handleSpeed(e)}"
<div class="speed>
<paper-menu-button
slot="dropdown-trigger"
.horizontalAlign=${'right'}
.verticalAlign=${'top'}
.verticalOffset=${40}
.noAnimations=${true}
@click="${(e) => e.stopPropagation()}"
>
${speed_list.map(
(item) =>
html`<paper-item value=${item}
>${localize(`speed.${item}`) || item}</paper-item
>`
)}
</paper-listbox>
</paper-menu-button>
<paper-button slot="dropdown-trigger">
<ha-icon icon="mdi:fan"></ha-icon>
<span show=${true}> ${localize(`speed.${speed}`) || speed} </span>
</paper-button>
<paper-listbox
slot="dropdown-content"
selected=${selected}
@click="${(e) => this.handleSpeed(e)}"
>
${speed_list.map(
(item) =>
html`<paper-item value=${item}
>${localize(`speed.${item}`) || item}</paper-item
>`
)}
</paper-listbox>
</paper-menu-button>
</div>
`;
}

Expand All @@ -191,40 +209,42 @@ class PurifierCard extends LitElement {
attributes: { preset_mode, preset_modes, supported_features },
} = this.entity;

if (!preset_modes || !(supported_features & SUPPORT_PRESET_MODE)) {
if (!this.showPresetMode || !preset_modes || !(supported_features & SUPPORT_PRESET_MODE)) {
return html``;
}

const selected = preset_modes.indexOf(preset_mode);

return html`
<paper-menu-button
slot="dropdown-trigger"
.horizontalAlign=${'right'}
.verticalAlign=${'top'}
.verticalOffset=${40}
.noAnimations=${true}
@click="${(e) => e.stopPropagation()}"
>
<paper-button slot="dropdown-trigger">
<ha-icon icon="mdi:fan"></ha-icon>
<span show=${true}
>${localize(`preset_mode.${preset_mode}`) || preset_mode}
</span>
</paper-button>
<paper-listbox
slot="dropdown-content"
selected=${selected}
@click="${(e) => this.handlePresetMode(e)}"
<div class="preset-mode">
<paper-menu-button
slot="dropdown-trigger"
.horizontalAlign=${'right'}
.verticalAlign=${'top'}
.verticalOffset=${40}
.noAnimations=${true}
@click="${(e) => e.stopPropagation()}"
>
${preset_modes.map(
(item) =>
html`<paper-item value=${item}
>${localize(`preset_mode.${item}`) || item}</paper-item
>`
)}
</paper-listbox>
</paper-menu-button>
<paper-button slot="dropdown-trigger">
<ha-icon icon="mdi:fan"></ha-icon>
<span show=${true}
>${localize(`preset_mode.${preset_mode}`) || preset_mode}
</span>
</paper-button>
<paper-listbox
slot="dropdown-content"
selected=${selected}
@click="${(e) => this.handlePresetMode(e)}"
>
${preset_modes.map(
(item) =>
html`<paper-item value=${item}
>${localize(`preset_mode.${item}`) || item}</paper-item
>`
)}
</paper-listbox>
</paper-menu-button>
</div>
`;
}

Expand Down Expand Up @@ -421,7 +441,7 @@ class PurifierCard extends LitElement {
>
<div class="header">
<div class="speed">${this.renderSpeed()}</div>
<div class="preset-mode">${this.renderPresetMode()}</div>
<div class="preset-mode">${this.renderPresetMode()}</div>
</div>
<div class="image ${className}">${this.renderAQI()}</div>
Expand Down
1 change: 1 addition & 0 deletions src/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default css`
.header {
display: flex;
color: var(--text-primary-color);
margin-top: 5px;
}
.image {
Expand Down

0 comments on commit 37d2383

Please sign in to comment.