Don't wait for slider release to update color temp (#15914)

This commit is contained in:
Paul Bottein 2023-03-27 10:34:05 +02:00 committed by GitHub
parent 8ea350a488
commit 1b2eaedba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import {
PropertyValues,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { throttle } from "../../../../common/util/throttle";
import "../../../../components/ha-button-toggle-group";
import "../../../../components/ha-color-picker";
import "../../../../components/ha-control-slider";
@ -297,17 +298,26 @@ class MoreInfoViewLightColorPicker extends LitElement {
private _ctSliderMoved(ev: CustomEvent) {
const ct = ev.detail.value;
if (isNaN(ct)) {
if (isNaN(ct) || this._ctSliderValue === ct) {
return;
}
this._ctSliderValue = ct;
this._throttleUpdateColorTemp();
}
private _throttleUpdateColorTemp = throttle(() => {
this.hass.callService("light", "turn_on", {
entity_id: this.stateObj!.entity_id,
color_temp_kelvin: this._ctSliderValue,
});
}, 500);
private _ctSliderChanged(ev: CustomEvent) {
const ct = ev.detail.value;
if (isNaN(ct)) {
if (isNaN(ct) || this._ctSliderValue === ct) {
return;
}