Skip to content

Commit

Permalink
HA - allow to overwrite brightness by HA yes or no
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed Aug 21, 2024
1 parent f8a3396 commit efaa0ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@
"edt_dev_spec_devices_discovery_inprogress": "Discovery in progress",
"edt_dev_spec_dithering_title": "Dithering",
"edt_dev_spec_dmaNumber_title": "DMA channel",
"edt_dev_spec_fullBrightnessAtStart_title": "Full brightness at start",
"edt_dev_spec_gamma_title": "Gamma",
"edt_dev_spec_globalBrightnessControlMaxLevel_title": "Max Current Level",
"edt_dev_spec_globalBrightnessControlThreshold_title": "Adaptive Current Threshold",
Expand Down
15 changes: 13 additions & 2 deletions libsrc/leddevice/dev_net/LedDeviceHomeAssistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const char CONFIG_AUTH_TOKEN[] = "token";
const char CONFIG_ENITYIDS[] = "entityIds";
const char CONFIG_BRIGHTNESS[] = "brightness";
const char CONFIG_BRIGHTNESS_OVERWRITE[] = "overwriteBrightness";
const char CONFIG_FULL_BRIGHTNESS_AT_START[] = "fullBrightnessAtStart";

const bool DEFAULT_IS_BRIGHTNESS_OVERWRITE = true;
const bool DEFAULT_IS_FULL_BRIGHTNESS_AT_START = true;
const int BRI_MAX = 255;

// Home Assistant API
Expand All @@ -50,6 +52,7 @@ LedDeviceHomeAssistant::LedDeviceHomeAssistant(const QJsonObject& deviceConfig)
, _restApi(nullptr)
, _apiPort(API_DEFAULT_PORT)
, _isBrightnessOverwrite(DEFAULT_IS_BRIGHTNESS_OVERWRITE)
, _isFullBrightnessAtStart(DEFAULT_IS_FULL_BRIGHTNESS_AT_START)
, _brightness (BRI_MAX)
{
#ifdef ENABLE_MDNS
Expand Down Expand Up @@ -89,13 +92,15 @@ bool LedDeviceHomeAssistant::init(const QJsonObject& deviceConfig)
_bearerToken = deviceConfig[CONFIG_AUTH_TOKEN].toString();

_isBrightnessOverwrite = _devConfig[CONFIG_BRIGHTNESS_OVERWRITE].toBool(DEFAULT_IS_BRIGHTNESS_OVERWRITE);
_isFullBrightnessAtStart = _devConfig[CONFIG_FULL_BRIGHTNESS_AT_START].toBool(DEFAULT_IS_FULL_BRIGHTNESS_AT_START);
_brightness = _devConfig[CONFIG_BRIGHTNESS].toInt(BRI_MAX);

Debug(_log, "Hostname/IP : %s", QSTRING_CSTR(_hostName));
Debug(_log, "Port : %d", _apiPort );

Debug(_log, "Overwrite Brightn.: %d", _isBrightnessOverwrite);
Debug(_log, "Set Brightness to : %d", _brightness);
Debug(_log, "Full Bri. at start: %d", _isFullBrightnessAtStart);

_lightEntityIds = _devConfig[ CONFIG_ENITYIDS ].toVariant().toStringList();
int configuredLightsCount = _lightEntityIds.size();
Expand Down Expand Up @@ -349,9 +354,9 @@ bool LedDeviceHomeAssistant::powerOn()
_restApi->setPath(API_LIGHT_TURN_ON);
QJsonObject serviceAttributes {{ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)}};

if (_isBrightnessOverwrite)
if (_isFullBrightnessAtStart)
{
serviceAttributes.insert(BRIGHTNESS, _brightness);
serviceAttributes.insert(BRIGHTNESS, BRI_MAX);
}

httpResponse response = _restApi->post(serviceAttributes);
Expand Down Expand Up @@ -402,6 +407,12 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
ColorRgb ledValue = ledValues.at(0);
QJsonArray rgbColor {ledValue.red, ledValue.green, ledValue.blue};
serviceAttributes.insert(RGB_COLOR, rgbColor);

if (_isBrightnessOverwrite)
{
serviceAttributes.insert(BRIGHTNESS, _brightness);
}

httpResponse response = _restApi->post(serviceAttributes);
if (response.error())
{
Expand Down
1 change: 1 addition & 0 deletions libsrc/leddevice/dev_net/LedDeviceHomeAssistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class LedDeviceHomeAssistant : LedDevice
QStringList _lightEntityIds;

bool _isBrightnessOverwrite;
bool _isFullBrightnessAtStart;
int _brightness;
};

Expand Down
13 changes: 11 additions & 2 deletions libsrc/leddevice/schemas/schema-homeassistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
"access": "advanced",
"propertyOrder": 6
},
"fullBrightnessAtStart": {
"type": "boolean",
"format": "checkbox",
"title": "edt_dev_spec_fullBrightnessAtStart_title",
"default": true,
"required": true,
"access": "advanced",
"propertyOrder": 7
},
"entityIds": {
"title": "edt_dev_spec_lightid_title",
"type": "array",
Expand All @@ -87,7 +96,7 @@
"type": "string",
"title": "edt_dev_spec_lights_itemtitle"
},
"propertyOrder": 7
"propertyOrder": 8
},
"latchTime": {
"type": "integer",
Expand All @@ -100,7 +109,7 @@
"options": {
"infoText": "edt_dev_spec_latchtime_title_info"
},
"propertyOrder": 8
"propertyOrder": 9
}
},
"additionalProperties": true
Expand Down

0 comments on commit efaa0ce

Please sign in to comment.