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

Commit

Permalink
fix(light): fix light brightness adjustment buttons after HA update (#…
Browse files Browse the repository at this point in the history
…746)

Take into account the new "supported_color_modes" attributes when
checking if light supports brightness adjustment.

Fixes #743
  • Loading branch information
rchl committed Aug 6, 2021
1 parent 8ba7e04 commit dd9510f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
14 changes: 3 additions & 11 deletions scripts/directives/tile.html
Expand Up @@ -142,19 +142,11 @@

<div ng-if="item.type === TYPES.LIGHT" class="item-entity-container">
<div ng-if="!item.controlsEnabled">
<div ng-if="entity.state === 'on'">
<div
ng-if="supportsFeature(FEATURES.LIGHT.BRIGHTNESS, entity)"
class="item-button -center-right"
ng-click="increaseBrightness($event, item, entity)"
>
<div ng-if="entity.state === 'on' && FEATURES.LIGHT.supportsBrightness(entity)">
<div class="item-button -center-right" ng-click="increaseBrightness($event, item, entity)">
<i class="mdi mdi-plus"></i>
</div>
<div
ng-if="supportsFeature(FEATURES.LIGHT.BRIGHTNESS, entity)"
class="item-button -bottom-right"
ng-click="decreaseBrightness($event, item, entity)"
>
<div class="item-button -bottom-right" ng-click="decreaseBrightness($event, item, entity)">
<i class="mdi mdi-minus"></i>
</div>
</div>
Expand Down
26 changes: 26 additions & 0 deletions scripts/globals/constants.js
Expand Up @@ -95,6 +95,32 @@ export const FEATURES = {
COLOR: 16,
TRANSITION: 32,
WHITE_VALUE: 128,
COLOR_MODES_BRIGHTNESS: ['brightness', 'color_temp', 'hs', 'xy', 'rgb', 'rgbw', 'rgbww', 'white'],
supportsBrightness (entity) {
const { attributes } = entity;
let { supported_color_modes: supportedColorModes } = attributes;
const { supported_features: supportedFeatures } = attributes;

if (supportedColorModes === undefined) {
// Backwards compatibility for supported_color_modes added in 2021.4
supportedColorModes = [];

if (supportedFeatures & FEATURES.LIGHT.COLOR_TEMP) {
supportedColorModes.push('color_temp');
}
if (supportedFeatures & FEATURES.LIGHT.COLOR) {
supportedColorModes.push('hs');
}
if (supportedFeatures & FEATURES.LIGHT.WHITE_VALUE) {
supportedColorModes.push('rgbw');
}
if (supportedFeatures & FEATURES.LIGHT.BRIGHTNESS && supportedColorModes.length === 0) {
supportedColorModes = ['brightness'];
}
}

return supportedColorModes.some(mode => FEATURES.LIGHT.COLOR_MODES_BRIGHTNESS.includes(mode));
},
},
MEDIA_PLAYER: {
PAUSE: 1,
Expand Down

0 comments on commit dd9510f

Please sign in to comment.