Skip to content
This repository was archived by the owner on Nov 4, 2023. It is now read-only.

Commit dd9510f

Browse files
authored
fix(light): fix light brightness adjustment buttons after HA update (#746)
Take into account the new "supported_color_modes" attributes when checking if light supports brightness adjustment. Fixes #743
1 parent 8ba7e04 commit dd9510f

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

scripts/directives/tile.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,11 @@
142142

143143
<div ng-if="item.type === TYPES.LIGHT" class="item-entity-container">
144144
<div ng-if="!item.controlsEnabled">
145-
<div ng-if="entity.state === 'on'">
146-
<div
147-
ng-if="supportsFeature(FEATURES.LIGHT.BRIGHTNESS, entity)"
148-
class="item-button -center-right"
149-
ng-click="increaseBrightness($event, item, entity)"
150-
>
145+
<div ng-if="entity.state === 'on' && FEATURES.LIGHT.supportsBrightness(entity)">
146+
<div class="item-button -center-right" ng-click="increaseBrightness($event, item, entity)">
151147
<i class="mdi mdi-plus"></i>
152148
</div>
153-
<div
154-
ng-if="supportsFeature(FEATURES.LIGHT.BRIGHTNESS, entity)"
155-
class="item-button -bottom-right"
156-
ng-click="decreaseBrightness($event, item, entity)"
157-
>
149+
<div class="item-button -bottom-right" ng-click="decreaseBrightness($event, item, entity)">
158150
<i class="mdi mdi-minus"></i>
159151
</div>
160152
</div>

scripts/globals/constants.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ export const FEATURES = {
9595
COLOR: 16,
9696
TRANSITION: 32,
9797
WHITE_VALUE: 128,
98+
COLOR_MODES_BRIGHTNESS: ['brightness', 'color_temp', 'hs', 'xy', 'rgb', 'rgbw', 'rgbww', 'white'],
99+
supportsBrightness (entity) {
100+
const { attributes } = entity;
101+
let { supported_color_modes: supportedColorModes } = attributes;
102+
const { supported_features: supportedFeatures } = attributes;
103+
104+
if (supportedColorModes === undefined) {
105+
// Backwards compatibility for supported_color_modes added in 2021.4
106+
supportedColorModes = [];
107+
108+
if (supportedFeatures & FEATURES.LIGHT.COLOR_TEMP) {
109+
supportedColorModes.push('color_temp');
110+
}
111+
if (supportedFeatures & FEATURES.LIGHT.COLOR) {
112+
supportedColorModes.push('hs');
113+
}
114+
if (supportedFeatures & FEATURES.LIGHT.WHITE_VALUE) {
115+
supportedColorModes.push('rgbw');
116+
}
117+
if (supportedFeatures & FEATURES.LIGHT.BRIGHTNESS && supportedColorModes.length === 0) {
118+
supportedColorModes = ['brightness'];
119+
}
120+
}
121+
122+
return supportedColorModes.some(mode => FEATURES.LIGHT.COLOR_MODES_BRIGHTNESS.includes(mode));
123+
},
98124
},
99125
MEDIA_PLAYER: {
100126
PAUSE: 1,

0 commit comments

Comments
 (0)