Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions src/panels/lovelace/cards/hui-light-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
css,
CSSResult,
} 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 "@thomasloven/round-slider";

Expand All @@ -16,20 +18,17 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";

import "../../../components/ha-card";
import "../../../components/ha-icon";
import "../components/hui-warning";
import "../components/hui-unavailable";

import { fireEvent } from "../../../common/dom/fire_event";
import { styleMap } from "lit-html/directives/style-map";
import { HomeAssistant, LightEntity } from "../../../types";
import { LovelaceCard, LovelaceCardEditor } from "../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import { toggleEntity } from "../common/entity/toggle-entity";
import { LightCardConfig } from "./types";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { SUPPORT_BRIGHTNESS } from "../../../data/light";
import { actionHandler } from "../common/directives/action-handler-directive";

@customElement("hui-light-card")
export class HuiLightCard extends LitElement implements LovelaceCard {
Expand Down Expand Up @@ -65,8 +64,6 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
}

const stateObj = this.hass.states[this._config!.entity] as LightEntity;
const brightness =
Math.round((stateObj.attributes.brightness / 254) * 100) || 0;

if (!stateObj) {
return html`
Expand All @@ -80,6 +77,9 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
`;
}

const brightness =
Math.round((stateObj.attributes.brightness / 254) * 100) || 0;

return html`
<ha-card>
${stateObj.state === "unavailable"
Expand All @@ -100,30 +100,31 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
${supportsFeature(stateObj, SUPPORT_BRIGHTNESS)
? html`
<round-slider
min="1"
min="0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the function of the slider.
Now sliding to the bottom will turn the light off as opposed to setting it to minimum brightness.
This results in the handle disappearing, which might be confusing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the handle disappearing, but yeah it does turn the light off when sliding all the way down. I think I prefer it this way. Do we have more options? Old behaviour was not turning off but still showing the handle?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Min was 1 with the old slider too. https://github.com/home-assistant/home-assistant-polymer/pull/3634/files#diff-f2231026bfc2c43209404df9b7bbb679L35

It's probably better this way. I just didn't want it to slide by without comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in the old version the handle did stay, is that something that was changed in round-slider?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. The slider is disabled if the value is outside of the range.
Maybe the old one drew it outside the bar, or just clamped it to the min-max range?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of slider turning off the light. Getting to 1% brightness is going to take skill now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to make this change now, so we have the handle back when the light is off, and check if we can get the old behaviour of round slider back.

.value=${brightness}
@value-changing=${this._dragEvent}
@value-changed=${this._setBrightness}
></round-slider>
`
: ""}
<ha-icon
class="slider-center"
data-state="${stateObj.state}"
.icon="${this._config.icon || stateIcon(stateObj)}"
style="${styleMap({
<paper-icon-button
class="light-button ${classMap({
"slider-center": supportsFeature(stateObj, SUPPORT_BRIGHTNESS),
"state-on": stateObj.state === "on",
"state-unavailable": stateObj.state === "unavailable",
})}"
.icon=${this._config.icon || stateIcon(stateObj)}
style=${styleMap({
filter: this._computeBrightness(stateObj),
color: this._computeColor(stateObj),
})}"
@action="${this._handleClick}"
.actionHandler=${actionHandler()}
tabindex="0"
></ha-icon>
})}
@click=${this._handleClick}
></paper-icon-button>
</div>
</div>

<div id="info">
<div class="brightness" @ha-click="${this._handleClick}">
<div class="brightness">
%
</div>
${this._config.name || computeStateName(stateObj)}
Expand Down Expand Up @@ -231,6 +232,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
ha-card {
position: relative;
overflow: hidden;
text-align: center;
--name-font-size: 1.2rem;
--brightness-font-size: 1.2rem;
}
Expand Down Expand Up @@ -266,32 +268,29 @@ export class HuiLightCard extends LitElement implements LovelaceCard {
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 {
position: absolute;
width: 70%;
height: 70%;
max-height: calc(100% - 40px);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with icons of different aspect ratios?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icons are always square

max-width: calc(100% - 40px);
box-sizing: border-box;
border-radius: 100%;
top: 50%;
left: 50%;
color: var(--paper-item-icon-color, #44739e);
cursor: pointer;
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 {
display: flex-vertical;
Expand Down