Skip to content

Commit f88d979

Browse files
committed
HA: Apply luminance formula (#1922)
1 parent 703c16a commit f88d979

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Hue Bridge - Alternate certificate support
2020
- Linux: New DRM/KMS screen grabber with plane-based capture - not feature complete yet
2121
- Logging/Tracing: Introduced qlogging categories to enable dynamic tracing
22+
- Home Assistent: dynamically set brightness for higher dynamic range (#1922)
2223

2324
---
2425

libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ bool LedDeviceHomeAssistant::powerOff()
401401

402402
int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
403403
{
404-
int retVal = 0;
405-
406404
QJsonObject serviceAttributes{ {ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)} };
407405
ColorRgb ledValue = ledValues.at(0);
408406

@@ -415,20 +413,18 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
415413
_restApi->setPath(API_LIGHT_TURN_ON);
416414
serviceAttributes.insert(RGB_COLOR, QJsonArray{ ledValue.red, ledValue.green, ledValue.blue });
417415

418-
int brightness = _brightness;
419-
420-
// Some devices cannot deal with a black color and brightness > 0
421-
if (ledValue == ColorRgb::BLACK)
416+
int brightness;
417+
if (!_isBrightnessOverwrite)
422418
{
423-
brightness = 0;
419+
brightness = qBound(0, qRound(0.2126 * ledValue.red + 0.7152 * ledValue.green + 0.0722 * ledValue.blue), 255);
424420
}
425-
426-
// Add brightness attribute if applicable
427-
if (brightness == 0 || _isBrightnessOverwrite)
421+
else
428422
{
429-
serviceAttributes.insert(BRIGHTNESS, brightness);
423+
brightness = _brightness;
430424
}
431425

426+
serviceAttributes.insert(BRIGHTNESS, brightness);
427+
432428
if (_transitionTime > 0)
433429
{
434430
serviceAttributes.insert(TRANSITION, _transitionTime);
@@ -438,8 +434,8 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
438434
if (response.error())
439435
{
440436
Warning(_log, "Updating lights failed with error: '%s'", QSTRING_CSTR(response.getErrorReason()));
441-
retVal = -1;
437+
return -1;
442438
}
443439

444-
return retVal;
440+
return 0;
445441
}

libsrc/leddevice/schemas/schema-homeassistant.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"type": "boolean",
5454
"format": "checkbox",
5555
"title": "edt_dev_spec_brightnessOverwrite_title",
56-
"default": true,
56+
"default": false,
5757
"required": true,
5858
"access": "advanced",
5959
"propertyOrder": 6

0 commit comments

Comments
 (0)