mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 20:56:36 +00:00
Fix light card (#4257)
* Fix light card * Remove unused class * Fix for when entity is not available * Fix active state
This commit is contained in:
parent
444cbd00d9
commit
85ca73db84
@ -8,6 +8,8 @@ import {
|
|||||||
css,
|
css,
|
||||||
CSSResult,
|
CSSResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
|
import { classMap } from "lit-html/directives/class-map";
|
||||||
|
import { styleMap } from "lit-html/directives/style-map";
|
||||||
import "@polymer/paper-icon-button/paper-icon-button";
|
import "@polymer/paper-icon-button/paper-icon-button";
|
||||||
import "@thomasloven/round-slider";
|
import "@thomasloven/round-slider";
|
||||||
|
|
||||||
@ -16,12 +18,10 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
|
|||||||
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
|
||||||
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-icon";
|
|
||||||
import "../components/hui-warning";
|
import "../components/hui-warning";
|
||||||
import "../components/hui-unavailable";
|
import "../components/hui-unavailable";
|
||||||
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { styleMap } from "lit-html/directives/style-map";
|
|
||||||
import { HomeAssistant, LightEntity } from "../../../types";
|
import { HomeAssistant, LightEntity } from "../../../types";
|
||||||
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
import { LovelaceCard, LovelaceCardEditor } from "../types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
@ -29,7 +29,6 @@ import { toggleEntity } from "../common/entity/toggle-entity";
|
|||||||
import { LightCardConfig } from "./types";
|
import { LightCardConfig } from "./types";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
import { SUPPORT_BRIGHTNESS } from "../../../data/light";
|
import { SUPPORT_BRIGHTNESS } from "../../../data/light";
|
||||||
import { actionHandler } from "../common/directives/action-handler-directive";
|
|
||||||
|
|
||||||
@customElement("hui-light-card")
|
@customElement("hui-light-card")
|
||||||
export class HuiLightCard extends LitElement implements LovelaceCard {
|
export class HuiLightCard extends LitElement implements LovelaceCard {
|
||||||
@ -65,8 +64,6 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const stateObj = this.hass.states[this._config!.entity] as LightEntity;
|
const stateObj = this.hass.states[this._config!.entity] as LightEntity;
|
||||||
const brightness =
|
|
||||||
Math.round((stateObj.attributes.brightness / 254) * 100) || 0;
|
|
||||||
|
|
||||||
if (!stateObj) {
|
if (!stateObj) {
|
||||||
return html`
|
return html`
|
||||||
@ -80,6 +77,9 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const brightness =
|
||||||
|
Math.round((stateObj.attributes.brightness / 254) * 100) || 0;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card>
|
<ha-card>
|
||||||
${stateObj.state === "unavailable"
|
${stateObj.state === "unavailable"
|
||||||
@ -100,30 +100,31 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
${supportsFeature(stateObj, SUPPORT_BRIGHTNESS)
|
${supportsFeature(stateObj, SUPPORT_BRIGHTNESS)
|
||||||
? html`
|
? html`
|
||||||
<round-slider
|
<round-slider
|
||||||
min="1"
|
min="0"
|
||||||
.value=${brightness}
|
.value=${brightness}
|
||||||
@value-changing=${this._dragEvent}
|
@value-changing=${this._dragEvent}
|
||||||
@value-changed=${this._setBrightness}
|
@value-changed=${this._setBrightness}
|
||||||
></round-slider>
|
></round-slider>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-icon
|
<paper-icon-button
|
||||||
class="slider-center"
|
class="light-button ${classMap({
|
||||||
data-state="${stateObj.state}"
|
"slider-center": supportsFeature(stateObj, SUPPORT_BRIGHTNESS),
|
||||||
.icon="${this._config.icon || stateIcon(stateObj)}"
|
"state-on": stateObj.state === "on",
|
||||||
style="${styleMap({
|
"state-unavailable": stateObj.state === "unavailable",
|
||||||
|
})}"
|
||||||
|
.icon=${this._config.icon || stateIcon(stateObj)}
|
||||||
|
style=${styleMap({
|
||||||
filter: this._computeBrightness(stateObj),
|
filter: this._computeBrightness(stateObj),
|
||||||
color: this._computeColor(stateObj),
|
color: this._computeColor(stateObj),
|
||||||
})}"
|
})}
|
||||||
@action="${this._handleClick}"
|
@click=${this._handleClick}
|
||||||
.actionHandler=${actionHandler()}
|
></paper-icon-button>
|
||||||
tabindex="0"
|
|
||||||
></ha-icon>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="info">
|
<div id="info">
|
||||||
<div class="brightness" @ha-click="${this._handleClick}">
|
<div class="brightness">
|
||||||
%
|
%
|
||||||
</div>
|
</div>
|
||||||
${this._config.name || computeStateName(stateObj)}
|
${this._config.name || computeStateName(stateObj)}
|
||||||
@ -231,6 +232,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
ha-card {
|
ha-card {
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
--name-font-size: 1.2rem;
|
--name-font-size: 1.2rem;
|
||||||
--brightness-font-size: 1.2rem;
|
--brightness-font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
@ -266,32 +268,29 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
|
|||||||
padding-bottom: 10%;
|
padding-bottom: 10%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.light-button {
|
||||||
|
color: var(--paper-item-icon-color, #44739e);
|
||||||
|
width: 60%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.light-button.state-on {
|
||||||
|
color: var(--paper-item-icon-active-color, #fdd835);
|
||||||
|
}
|
||||||
|
|
||||||
|
.light-button.state-unavailable {
|
||||||
|
color: var(--state-icon-unavailable-color);
|
||||||
|
}
|
||||||
|
|
||||||
.slider-center {
|
.slider-center {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 70%;
|
|
||||||
height: 70%;
|
|
||||||
max-height: calc(100% - 40px);
|
|
||||||
max-width: calc(100% - 40px);
|
max-width: calc(100% - 40px);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border-radius: 100%;
|
border-radius: 100%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
color: var(--paper-item-icon-color, #44739e);
|
|
||||||
cursor: pointer;
|
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
.slider-center:focus {
|
|
||||||
outline: none;
|
|
||||||
background: var(--divider-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider-center[data-state="on"] {
|
|
||||||
color: var(--paper-item-icon-active-color, #fdd835);
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider-center[data-state="unavailable"] {
|
|
||||||
color: var(--state-icon-unavailable-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
#info {
|
#info {
|
||||||
display: flex-vertical;
|
display: flex-vertical;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user