-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add buttons header-footer #4601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import "../header-footer/hui-picture-header-footer"; | ||
| import "../header-footer/hui-buttons-header-footer"; | ||
| import { LovelaceHeaderFooterConfig } from "../header-footer/types"; | ||
| import { createLovelaceElement } from "./create-element-base"; | ||
|
|
||
| const SPECIAL_TYPES = new Set(["picture"]); | ||
| const SPECIAL_TYPES = new Set(["picture", "buttons"]); | ||
|
|
||
| export const createHeaderFooterElement = (config: LovelaceHeaderFooterConfig) => | ||
| createLovelaceElement("header-footer", config, SPECIAL_TYPES); |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||
| import { | ||||||||
| html, | ||||||||
| LitElement, | ||||||||
| TemplateResult, | ||||||||
| customElement, | ||||||||
| css, | ||||||||
| CSSResult, | ||||||||
| queryAll, | ||||||||
| } from "lit-element"; | ||||||||
| import "@material/mwc-ripple"; | ||||||||
|
|
||||||||
| import "../../../components/entity/state-badge"; | ||||||||
| import "../../../components/ha-card"; | ||||||||
| import "../../../components/ha-icon"; | ||||||||
| import "../components/hui-warning-element"; | ||||||||
|
|
||||||||
| import { HomeAssistant } from "../../../types"; | ||||||||
| import { LovelaceHeaderFooter } from "../types"; | ||||||||
| import { ButtonsHeaderFooterConfig } from "./types"; | ||||||||
| import { EntityConfig } from "../entity-rows/types"; | ||||||||
| import { processConfigEntities } from "../common/process-config-entities"; | ||||||||
| import { toggleEntity } from "../common/entity/toggle-entity"; | ||||||||
| import { computeTooltip } from "../common/compute-tooltip"; | ||||||||
| // tslint:disable-next-line: no-duplicate-imports | ||||||||
| import { StateBadge } from "../../../components/entity/state-badge"; | ||||||||
|
|
||||||||
| @customElement("hui-buttons-header-footer") | ||||||||
| export class HuiButtonsHeaderFooter extends LitElement | ||||||||
| implements LovelaceHeaderFooter { | ||||||||
| public static getStubConfig(): object { | ||||||||
| return { entities: [] }; | ||||||||
| } | ||||||||
|
|
||||||||
| private _configEntities?: EntityConfig[]; | ||||||||
| private _hass?: HomeAssistant; | ||||||||
| @queryAll("state-badge") private _badges!: StateBadge[]; | ||||||||
|
|
||||||||
| public setConfig(config: ButtonsHeaderFooterConfig): void { | ||||||||
| this._configEntities = processConfigEntities(config.entities); | ||||||||
| this.requestUpdate(); | ||||||||
| } | ||||||||
|
|
||||||||
| set hass(hass: HomeAssistant) { | ||||||||
| this._hass = hass; | ||||||||
| this._badges.forEach((badge, index: number) => { | ||||||||
| badge.hass = hass; | ||||||||
| badge.stateObj = hass.states[this._configEntities![index].entity]; | ||||||||
| }); | ||||||||
| } | ||||||||
|
|
||||||||
| protected render(): TemplateResult | void { | ||||||||
| return html` | ||||||||
| ${(this._configEntities || []).map((entityConf) => { | ||||||||
| const stateObj = this._hass!.states[entityConf.entity]; | ||||||||
| if (!stateObj) { | ||||||||
| return html`<div class='missing'><iron-icon icon="hass:alert"></div>`; | ||||||||
| } | ||||||||
|
|
||||||||
| return html` | ||||||||
| <div> | ||||||||
| <state-badge | ||||||||
| title=${computeTooltip(this._hass!, entityConf)} | ||||||||
| @click=${this._toggle} | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this, but was this your strategy so that I would fix
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😂 it didn't work? No, I had no idea
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only works if you had an action defined. I currently only do toggle. |
||||||||
| .hass=${this._hass} | ||||||||
| .stateObj=${stateObj} | ||||||||
| .overrideIcon=${entityConf.icon} | ||||||||
| .overrideImage=${entityConf.image} | ||||||||
| stateColor | ||||||||
| tabindex="0" | ||||||||
| ></state-badge> | ||||||||
| <mwc-ripple unbounded></mwc-ripple> | ||||||||
| </div> | ||||||||
| `; | ||||||||
| })} | ||||||||
| `; | ||||||||
| } | ||||||||
|
|
||||||||
| private async _toggle(ev) { | ||||||||
| await toggleEntity(this._hass!, ev.target.stateObj.entity_id); | ||||||||
| } | ||||||||
|
|
||||||||
| static get styles(): CSSResult { | ||||||||
| return css` | ||||||||
| :host { | ||||||||
| display: flex; | ||||||||
| justify-content: space-evenly; | ||||||||
| } | ||||||||
| .missing { | ||||||||
| color: #fce588; | ||||||||
| } | ||||||||
| state-badge { | ||||||||
| cursor: pointer; | ||||||||
| } | ||||||||
| `; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| declare global { | ||||||||
| interface HTMLElementTagNameMap { | ||||||||
| "hui-buttons-header-footer": HuiButtonsHeaderFooter; | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
@queryAll(".header-footer > *")decorator