Don't assume that effect list is not null (#15764)

* Don't assume that effect list is not null

* Don't assume that rgb, rgbw and rgbww are defined
pull/15779/head
Paul Bottein 2023-03-08 10:24:28 +01:00 committed by GitHub
parent 4f1c4bdcb9
commit 4ab1723c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -201,10 +201,11 @@ class MoreInfoViewLightColorPicker extends LitElement {
this._brightnessAdjusted = undefined; this._brightnessAdjusted = undefined;
if ( if (
stateObj.attributes.color_mode === LightColorMode.RGB && stateObj.attributes.color_mode === LightColorMode.RGB &&
stateObj.attributes.rgb_color &&
!lightSupportsColorMode(stateObj, LightColorMode.RGBWW) && !lightSupportsColorMode(stateObj, LightColorMode.RGBWW) &&
!lightSupportsColorMode(stateObj, LightColorMode.RGBW) !lightSupportsColorMode(stateObj, LightColorMode.RGBW)
) { ) {
const maxVal = Math.max(...stateObj.attributes.rgb_color!); const maxVal = Math.max(...stateObj.attributes.rgb_color);
if (maxVal < 255) { if (maxVal < 255) {
this._brightnessAdjusted = maxVal; this._brightnessAdjusted = maxVal;
@ -216,16 +217,19 @@ class MoreInfoViewLightColorPicker extends LitElement {
: undefined; : undefined;
this._wvSliderValue = this._wvSliderValue =
stateObj.attributes.color_mode === LightColorMode.RGBW stateObj.attributes.color_mode === LightColorMode.RGBW &&
? Math.round((stateObj.attributes.rgbw_color![3] * 100) / 255) stateObj.attributes.rgbw_color
? Math.round((stateObj.attributes.rgbw_color[3] * 100) / 255)
: undefined; : undefined;
this._cwSliderValue = this._cwSliderValue =
stateObj.attributes.color_mode === LightColorMode.RGBWW stateObj.attributes.color_mode === LightColorMode.RGBWW &&
? Math.round((stateObj.attributes.rgbww_color![3] * 100) / 255) stateObj.attributes.rgbww_color
? Math.round((stateObj.attributes.rgbww_color[3] * 100) / 255)
: undefined; : undefined;
this._wwSliderValue = this._wwSliderValue =
stateObj.attributes.color_mode === LightColorMode.RGBWW stateObj.attributes.color_mode === LightColorMode.RGBWW &&
? Math.round((stateObj.attributes.rgbww_color![4] * 100) / 255) stateObj.attributes.rgbww_color
? Math.round((stateObj.attributes.rgbww_color[4] * 100) / 255)
: undefined; : undefined;
const currentRgbColor = getLightCurrentModeRgbColor(stateObj); const currentRgbColor = getLightCurrentModeRgbColor(stateObj);

View File

@ -148,7 +148,7 @@ class MoreInfoLight extends LitElement {
</md-outlined-icon-button> </md-outlined-icon-button>
` `
: null} : null}
${supportsEffects ${supportsEffects && this.stateObj.attributes.effect_list
? html` ? html`
<ha-button-menu <ha-button-menu
corner="BOTTOM_START" corner="BOTTOM_START"
@ -169,7 +169,7 @@ class MoreInfoLight extends LitElement {
> >
<ha-svg-icon .path=${mdiCreation}></ha-svg-icon> <ha-svg-icon .path=${mdiCreation}></ha-svg-icon>
</md-outlined-icon-button> </md-outlined-icon-button>
${this.stateObj.attributes.effect_list!.map( ${this.stateObj.attributes.effect_list.map(
(effect: string) => html` (effect: string) => html`
<mwc-list-item <mwc-list-item
.value=${effect} .value=${effect}