Skip to content
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

Fix for when the value doesnt get changed by the backend when we send it #9105

Merged
merged 4 commits into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/data/light.ts
Expand Up @@ -51,9 +51,7 @@ export const lightSupportsDimming = (entity: LightEntity) =>
modesSupportingDimming.includes(mode)
);

export const getLightCurrentModeRgbColor = (
entity: LightEntity
): number[] | undefined =>
export const getLightCurrentModeRgbColor = (entity: LightEntity): number[] =>
entity.attributes.color_mode === LightColorModes.RGBWW
? entity.attributes.rgbww_color
: entity.attributes.color_mode === LightColorModes.RGBW
Expand Down
45 changes: 24 additions & 21 deletions src/dialogs/more-info/controls/more-info-light.ts
Expand Up @@ -154,7 +154,7 @@ class MoreInfoLight extends LitElement {
)}
icon="hass:brightness-7"
max="100"
.value=${this._colorBrightnessSliderValue ?? 100}
.value=${this._colorBrightnessSliderValue}
@change=${this._colorBrightnessSliderChanged}
pin
></ha-labeled-slider>`
Expand Down Expand Up @@ -282,23 +282,15 @@ class MoreInfoLight extends LitElement {
stateObj.attributes.color_mode === LightColorModes.RGBWW
? Math.round((stateObj.attributes.rgbww_color[4] * 100) / 255)
: undefined;
this._colorBrightnessSliderValue =
stateObj.attributes.color_mode === LightColorModes.RGBWW
? Math.round(
(Math.max(...stateObj.attributes.rgbww_color.slice(0, 3)) * 100) /
255
)
: stateObj.attributes.color_mode === LightColorModes.RGBW
? Math.round(
(Math.max(...stateObj.attributes.rgbw_color.slice(0, 3)) * 100) /
255
)
: undefined;
this._colorBrightnessSliderValue = Math.round(
(Math.max(...getLightCurrentModeRgbColor(stateObj).slice(0, 3)) * 100) /
255
);

this._colorPickerColor = getLightCurrentModeRgbColor(stateObj)?.slice(
this._colorPickerColor = getLightCurrentModeRgbColor(stateObj).slice(
0,
3
) as [number, number, number] | undefined;
) as [number, number, number];
} else {
this._brightnessSliderValue = 0;
}
Expand Down Expand Up @@ -328,6 +320,8 @@ class MoreInfoLight extends LitElement {
return;
}

this._brightnessSliderValue = bri;

if (this._brightnessAdjusted) {
const rgb =
this.stateObj!.attributes.rgb_color ||
Expand Down Expand Up @@ -358,6 +352,8 @@ class MoreInfoLight extends LitElement {
return;
}

this._ctSliderValue = ct;

this.hass.callService("light", "turn_on", {
entity_id: this.stateObj!.entity_id,
color_temp: ct,
Expand All @@ -373,6 +369,8 @@ class MoreInfoLight extends LitElement {
return;
}

this._wvSliderValue = wv;
ludeeus marked this conversation as resolved.
Show resolved Hide resolved

wv = Math.min(255, Math.round((wv * 255) / 100));

const rgb = getLightCurrentModeRgbColor(this.stateObj!);
Expand Down Expand Up @@ -406,6 +404,9 @@ class MoreInfoLight extends LitElement {
return;
}

const oldValue = this._colorBrightnessSliderValue;
this._colorBrightnessSliderValue = value;

value = (value * 255) / 100;

const rgb = (getLightCurrentModeRgbColor(this.stateObj!)?.slice(0, 3) || [
Expand All @@ -417,12 +418,8 @@ class MoreInfoLight extends LitElement {
this._setRgbWColor(
this._adjustColorBrightness(
// first normalize the value
this._colorBrightnessSliderValue
? this._adjustColorBrightness(
rgb,
(this._colorBrightnessSliderValue * 255) / 100,
true
)
oldValue
? this._adjustColorBrightness(rgb, (oldValue * 255) / 100, true)
: rgb,
value
)
Expand Down Expand Up @@ -488,6 +485,12 @@ class MoreInfoLight extends LitElement {
rgb: { r: number; g: number; b: number };
}>
) {
this._colorPickerColor = [
ev.detail.rgb.r,
ev.detail.rgb.g,
ev.detail.rgb.b,
];

if (
lightSupportsColorMode(this.stateObj!, LightColorModes.RGBWW) ||
lightSupportsColorMode(this.stateObj!, LightColorModes.RGBW)
Expand Down
8 changes: 7 additions & 1 deletion src/dialogs/more-info/more-info-content.ts
Expand Up @@ -8,7 +8,7 @@ import { stateMoreInfoType } from "./state_more_info_control";
class MoreInfoContent extends UpdatingElement {
@property({ attribute: false }) public hass?: HomeAssistant;

@property() public stateObj?: HassEntity;
@property({ attribute: false }) public stateObj?: HassEntity;

private _detachedChild?: ChildNode;

Expand Down Expand Up @@ -54,3 +54,9 @@ class MoreInfoContent extends UpdatingElement {
}

customElements.define("more-info-content", MoreInfoContent);

declare global {
interface HTMLElementTagNameMap {
"more-info-content": MoreInfoContent;
}
}