diff --git a/package.json b/package.json index a9af1595db..bef9fe4631 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "@material/mwc-textfield": "^0.27.0", "@material/mwc-top-app-bar-fixed": "^0.27.0", "@material/top-app-bar": "=14.0.0-canary.53b3cad2f.0", + "@material/web": "=1.0.0-pre.2", "@mdi/js": "7.1.96", "@mdi/svg": "7.1.96", "@polymer/app-layout": "^3.1.0", diff --git a/src/components/ha-control-slider.ts b/src/components/ha-control-slider.ts index 34cdf0bb6b..2b761d4c30 100644 --- a/src/components/ha-control-slider.ts +++ b/src/components/ha-control-slider.ts @@ -44,7 +44,7 @@ const getPercentageFromEvent = (e: HammerInput, vertical: boolean) => { @customElement("ha-control-slider") export class HaControlSlider extends LitElement { - @property({ type: Boolean }) + @property({ type: Boolean, reflect: true }) public disabled = false; @property() @@ -245,14 +245,16 @@ export class HaControlSlider extends LitElement { >
${this.mode === "cursor" - ? html` - - ` + ? this.value != null + ? html` + + ` + : null : html`${name}
+${stateDisplay}
+ `; + } + + static get styles(): CSSResultGroup { + return css` + p { + text-align: center; + margin: 0; + } + .name { + font-style: normal; + font-weight: 400; + font-size: 28px; + line-height: 36px; + margin-bottom: 4px; + } + .state { + font-style: normal; + font-weight: 500; + font-size: 16px; + line-height: 24px; + letter-spacing: 0.1px; + margin-bottom: 24px; + } + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-more-info-state-header": HaMoreInfoStateHeader; + } +} diff --git a/src/dialogs/more-info/components/ha-more-info-toggle.ts b/src/dialogs/more-info/components/ha-more-info-toggle.ts new file mode 100644 index 0000000000..fabf68d407 --- /dev/null +++ b/src/dialogs/more-info/components/ha-more-info-toggle.ts @@ -0,0 +1,149 @@ +import { mdiFlash, mdiFlashOff } from "@mdi/js"; +import { HassEntity } from "home-assistant-js-websocket"; +import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; +import { customElement, property } from "lit/decorators"; +import { classMap } from "lit/directives/class-map"; +import { styleMap } from "lit/directives/style-map"; +import { computeDomain } from "../../../common/entity/compute_domain"; +import { stateActive } from "../../../common/entity/state_active"; +import { stateColorCss } from "../../../common/entity/state_color"; +import "../../../components/ha-control-button"; +import "../../../components/ha-control-switch"; +import { UNAVAILABLE, UNKNOWN } from "../../../data/entity"; +import { HomeAssistant } from "../../../types"; + +@customElement("ha-more-info-toggle") +export class HaMoreInfoToggle extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @property({ attribute: false }) public stateObj!: HassEntity; + + @property({ attribute: false }) public iconPathOn?: string; + + @property({ attribute: false }) public iconPathOff?: string; + + private _valueChanged(ev) { + const checked = ev.target.checked as boolean; + + if (checked) { + this._turnOn(); + } else { + this._turnOff(); + } + } + + private _turnOn() { + const domain = computeDomain(this.stateObj!.entity_id); + this.hass.callService(domain, "turn_on", { + entity_id: this.stateObj!.entity_id, + }); + } + + private _turnOff() { + const domain = computeDomain(this.stateObj!.entity_id); + this.hass.callService(domain, "turn_off", { + entity_id: this.stateObj!.entity_id, + }); + } + + protected render(): TemplateResult { + const color = stateColorCss(this.stateObj); + const isOn = this.stateObj.state === "on"; + const isOff = this.stateObj.state === "off"; + + if ( + this.stateObj.attributes.assumed_state || + this.stateObj.state === UNKNOWN + ) { + return html` + + `; + } + + return html` +