mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Handle Brightness & Black
This commit is contained in:
		@@ -24,13 +24,11 @@ const char CONFIG_ENITYIDS[] = "entityIds";
 | 
				
			|||||||
	const char CONFIG_BRIGHTNESS[] = "brightness";
 | 
						const char CONFIG_BRIGHTNESS[] = "brightness";
 | 
				
			||||||
	const char CONFIG_BRIGHTNESS_OVERWRITE[] = "overwriteBrightness";
 | 
						const char CONFIG_BRIGHTNESS_OVERWRITE[] = "overwriteBrightness";
 | 
				
			||||||
	const char CONFIG_FULL_BRIGHTNESS_AT_START[] = "fullBrightnessAtStart";
 | 
						const char CONFIG_FULL_BRIGHTNESS_AT_START[] = "fullBrightnessAtStart";
 | 
				
			||||||
const char CONFIG_ON_OFF_BLACK[] = "switchOffOnBlack";
 | 
					 | 
				
			||||||
	const char CONFIG_TRANSITIONTIME[] = "transitionTime";
 | 
						const char CONFIG_TRANSITIONTIME[] = "transitionTime";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const bool DEFAULT_IS_BRIGHTNESS_OVERWRITE = true;
 | 
						const bool DEFAULT_IS_BRIGHTNESS_OVERWRITE = true;
 | 
				
			||||||
	const bool DEFAULT_IS_FULL_BRIGHTNESS_AT_START = true;
 | 
						const bool DEFAULT_IS_FULL_BRIGHTNESS_AT_START = true;
 | 
				
			||||||
	const int  BRI_MAX = 255;
 | 
						const int  BRI_MAX = 255;
 | 
				
			||||||
const bool DEFAULT_IS_SWITCH_OFF_ON_BLACK = false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Home Assistant API
 | 
						// Home Assistant API
 | 
				
			||||||
	const int  API_DEFAULT_PORT = 8123;
 | 
						const int  API_DEFAULT_PORT = 8123;
 | 
				
			||||||
@@ -59,6 +57,7 @@ LedDeviceHomeAssistant::LedDeviceHomeAssistant(const QJsonObject& deviceConfig)
 | 
				
			|||||||
	, _isBrightnessOverwrite(DEFAULT_IS_BRIGHTNESS_OVERWRITE)
 | 
						, _isBrightnessOverwrite(DEFAULT_IS_BRIGHTNESS_OVERWRITE)
 | 
				
			||||||
	, _isFullBrightnessAtStart(DEFAULT_IS_FULL_BRIGHTNESS_AT_START)
 | 
						, _isFullBrightnessAtStart(DEFAULT_IS_FULL_BRIGHTNESS_AT_START)
 | 
				
			||||||
	, _brightness(BRI_MAX)
 | 
						, _brightness(BRI_MAX)
 | 
				
			||||||
 | 
						, _transitionTime(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef ENABLE_MDNS
 | 
					#ifdef ENABLE_MDNS
 | 
				
			||||||
	QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType",
 | 
						QMetaObject::invokeMethod(MdnsBrowser::getInstance().data(), "browseForServiceType",
 | 
				
			||||||
@@ -99,7 +98,6 @@ bool LedDeviceHomeAssistant::init(const QJsonObject& deviceConfig)
 | 
				
			|||||||
		_isBrightnessOverwrite = _devConfig[CONFIG_BRIGHTNESS_OVERWRITE].toBool(DEFAULT_IS_BRIGHTNESS_OVERWRITE);
 | 
							_isBrightnessOverwrite = _devConfig[CONFIG_BRIGHTNESS_OVERWRITE].toBool(DEFAULT_IS_BRIGHTNESS_OVERWRITE);
 | 
				
			||||||
		_isFullBrightnessAtStart = _devConfig[CONFIG_FULL_BRIGHTNESS_AT_START].toBool(DEFAULT_IS_FULL_BRIGHTNESS_AT_START);
 | 
							_isFullBrightnessAtStart = _devConfig[CONFIG_FULL_BRIGHTNESS_AT_START].toBool(DEFAULT_IS_FULL_BRIGHTNESS_AT_START);
 | 
				
			||||||
		_brightness = _devConfig[CONFIG_BRIGHTNESS].toInt(BRI_MAX);
 | 
							_brightness = _devConfig[CONFIG_BRIGHTNESS].toInt(BRI_MAX);
 | 
				
			||||||
		_switchOffOnBlack       = _devConfig[CONFIG_ON_OFF_BLACK].toBool(DEFAULT_IS_SWITCH_OFF_ON_BLACK);
 | 
					 | 
				
			||||||
		int transitionTimeMs = _devConfig[CONFIG_TRANSITIONTIME].toInt(0);
 | 
							int transitionTimeMs = _devConfig[CONFIG_TRANSITIONTIME].toInt(0);
 | 
				
			||||||
		_transitionTime = transitionTimeMs / 1000.0;
 | 
							_transitionTime = transitionTimeMs / 1000.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -109,7 +107,6 @@ bool LedDeviceHomeAssistant::init(const QJsonObject& deviceConfig)
 | 
				
			|||||||
		Debug(_log, "Overwrite Brightn.: %s", _isBrightnessOverwrite ? "Yes" : "No");
 | 
							Debug(_log, "Overwrite Brightn.: %s", _isBrightnessOverwrite ? "Yes" : "No");
 | 
				
			||||||
		Debug(_log, "Set Brightness to : %d", _brightness);
 | 
							Debug(_log, "Set Brightness to : %d", _brightness);
 | 
				
			||||||
		Debug(_log, "Full Bri. at start: %s", _isFullBrightnessAtStart ? "Yes" : "No");
 | 
							Debug(_log, "Full Bri. at start: %s", _isFullBrightnessAtStart ? "Yes" : "No");
 | 
				
			||||||
		Debug(_log, "Off on Black      : %s", _switchOffOnBlack ? "Yes" : "No" );
 | 
					 | 
				
			||||||
		Debug(_log, "Transition Time   : %d ms", transitionTimeMs);
 | 
							Debug(_log, "Transition Time   : %d ms", transitionTimeMs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_lightEntityIds = _devConfig[CONFIG_ENITYIDS].toVariant().toStringList();
 | 
							_lightEntityIds = _devConfig[CONFIG_ENITYIDS].toVariant().toStringList();
 | 
				
			||||||
@@ -408,12 +405,6 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
 | 
				
			|||||||
	QJsonObject serviceAttributes{ {ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)} };
 | 
						QJsonObject serviceAttributes{ {ENTITY_ID, QJsonArray::fromStringList(_lightEntityIds)} };
 | 
				
			||||||
	ColorRgb ledValue = ledValues.at(0);
 | 
						ColorRgb ledValue = ledValues.at(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_switchOffOnBlack && ledValue == ColorRgb::BLACK)
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		_restApi->setPath(API_LIGHT_TURN_OFF);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	//    http://hostname:port/api/services/light/turn_on
 | 
						//    http://hostname:port/api/services/light/turn_on
 | 
				
			||||||
	//    {
 | 
						//    {
 | 
				
			||||||
	//      "entity_id": [ entity-IDs ],
 | 
						//      "entity_id": [ entity-IDs ],
 | 
				
			||||||
@@ -421,19 +412,26 @@ int LedDeviceHomeAssistant::write(const std::vector<ColorRgb>& ledValues)
 | 
				
			|||||||
	//    }
 | 
						//    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_restApi->setPath(API_LIGHT_TURN_ON);
 | 
						_restApi->setPath(API_LIGHT_TURN_ON);
 | 
				
			||||||
		QJsonArray rgbColor {ledValue.red, ledValue.green, ledValue.blue};
 | 
						serviceAttributes.insert(RGB_COLOR, QJsonArray{ ledValue.red, ledValue.green, ledValue.blue });
 | 
				
			||||||
		serviceAttributes.insert(RGB_COLOR, rgbColor);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (_isBrightnessOverwrite)
 | 
						int brightness = _brightness;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Some devices cannot deal with a black color and brightness > 0
 | 
				
			||||||
 | 
						if (ledValue == ColorRgb::BLACK)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
			serviceAttributes.insert(BRIGHTNESS, _brightness);
 | 
							brightness = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Add brightness attribute if applicable
 | 
				
			||||||
 | 
						if (brightness == 0 || _isBrightnessOverwrite)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							serviceAttributes.insert(BRIGHTNESS, brightness);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_transitionTime > 0)
 | 
						if (_transitionTime > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
			// Transition time in seconds
 | 
					 | 
				
			||||||
		serviceAttributes.insert(TRANSITION, _transitionTime);
 | 
							serviceAttributes.insert(TRANSITION, _transitionTime);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	httpResponse response = _restApi->post(serviceAttributes);
 | 
						httpResponse response = _restApi->post(serviceAttributes);
 | 
				
			||||||
	if (response.error())
 | 
						if (response.error())
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -172,7 +172,6 @@ private:
 | 
				
			|||||||
	bool _isBrightnessOverwrite;
 | 
						bool _isBrightnessOverwrite;
 | 
				
			||||||
	bool _isFullBrightnessAtStart;
 | 
						bool _isFullBrightnessAtStart;
 | 
				
			||||||
	int _brightness;
 | 
						int _brightness;
 | 
				
			||||||
	bool _switchOffOnBlack;
 | 
					 | 
				
			||||||
	/// Transition time in seconds
 | 
						/// Transition time in seconds
 | 
				
			||||||
	double _transitionTime;
 | 
						double _transitionTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,18 +40,6 @@
 | 
				
			|||||||
      },
 | 
					      },
 | 
				
			||||||
      "propertyOrder": 4
 | 
					      "propertyOrder": 4
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "restoreOriginalState": {
 | 
					 | 
				
			||||||
      "type": "boolean",
 | 
					 | 
				
			||||||
      "format": "checkbox",
 | 
					 | 
				
			||||||
      "title": "edt_dev_spec_restoreOriginalState_title",
 | 
					 | 
				
			||||||
      "default": true,
 | 
					 | 
				
			||||||
      "required": true,
 | 
					 | 
				
			||||||
      "options": {
 | 
					 | 
				
			||||||
        "hidden": true,
 | 
					 | 
				
			||||||
        "infoText": "edt_dev_spec_restoreOriginalState_title_info"
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      "propertyOrder": 5
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "overwriteBrightness": {
 | 
					    "overwriteBrightness": {
 | 
				
			||||||
      "type": "boolean",
 | 
					      "type": "boolean",
 | 
				
			||||||
      "format": "checkbox",
 | 
					      "format": "checkbox",
 | 
				
			||||||
@@ -84,14 +72,6 @@
 | 
				
			|||||||
      "access": "advanced",
 | 
					      "access": "advanced",
 | 
				
			||||||
      "propertyOrder": 7
 | 
					      "propertyOrder": 7
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "switchOffOnBlack": {
 | 
					 | 
				
			||||||
      "type": "boolean",
 | 
					 | 
				
			||||||
      "format": "checkbox",
 | 
					 | 
				
			||||||
      "title": "edt_dev_spec_switchOffOnBlack_title",
 | 
					 | 
				
			||||||
      "default": false,
 | 
					 | 
				
			||||||
      "access": "advanced",
 | 
					 | 
				
			||||||
      "propertyOrder": 8
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    "transitionTime": {
 | 
					    "transitionTime": {
 | 
				
			||||||
      "type": "integer",
 | 
					      "type": "integer",
 | 
				
			||||||
      "title": "edt_dev_spec_transistionTime_title",
 | 
					      "title": "edt_dev_spec_transistionTime_title",
 | 
				
			||||||
@@ -101,7 +81,7 @@
 | 
				
			|||||||
      "maximum": 2000,
 | 
					      "maximum": 2000,
 | 
				
			||||||
      "required": false,
 | 
					      "required": false,
 | 
				
			||||||
      "access": "advanced",
 | 
					      "access": "advanced",
 | 
				
			||||||
      "propertyOrder": 9
 | 
					      "propertyOrder": 8
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "entityIds": {
 | 
					    "entityIds": {
 | 
				
			||||||
      "title": "edt_dev_spec_lightid_title",
 | 
					      "title": "edt_dev_spec_lightid_title",
 | 
				
			||||||
@@ -115,7 +95,7 @@
 | 
				
			|||||||
        "type": "string",
 | 
					        "type": "string",
 | 
				
			||||||
        "title": "edt_dev_spec_lights_itemtitle"
 | 
					        "title": "edt_dev_spec_lights_itemtitle"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "propertyOrder": 10
 | 
					      "propertyOrder": 9
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "latchTime": {
 | 
					    "latchTime": {
 | 
				
			||||||
      "type": "integer",
 | 
					      "type": "integer",
 | 
				
			||||||
@@ -128,7 +108,7 @@
 | 
				
			|||||||
      "options": {
 | 
					      "options": {
 | 
				
			||||||
        "infoText": "edt_dev_spec_latchtime_title_info"
 | 
					        "infoText": "edt_dev_spec_latchtime_title_info"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "propertyOrder": 11
 | 
					      "propertyOrder": 10
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "additionalProperties": true
 | 
					  "additionalProperties": true
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user