mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-11 01:55:42 +00:00
generate better (valid?) RGBCW and RGB HA configs for bulbs
This commit is contained in:
@ -1277,6 +1277,9 @@ int http_fn_ha_cfg(http_request_t *request) {
|
||||
int i;
|
||||
char mqttAdded = 0;
|
||||
char *uniq_id;
|
||||
char switchAdded = 0;
|
||||
char lightAdded = 0;
|
||||
int bLedDriverChipRunning;
|
||||
|
||||
shortDeviceName = CFG_GetShortDeviceName();
|
||||
clientId = CFG_GetMQTTClientId();
|
||||
@ -1293,8 +1296,9 @@ int http_fn_ha_cfg(http_request_t *request) {
|
||||
|
||||
get_Relay_PWM_Count(&relayCount, &pwmCount);
|
||||
|
||||
bLedDriverChipRunning = DRV_IsRunning("SM2135") || DRV_IsRunning("BP5758D");
|
||||
|
||||
if(relayCount > 0) {
|
||||
char switchAdded = 0;
|
||||
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
if(h_isChannelRelay(i)) {
|
||||
@ -1323,8 +1327,70 @@ int http_fn_ha_cfg(http_request_t *request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pwmCount > 0) {
|
||||
char lightAdded = 0;
|
||||
if(pwmCount == 5 || bLedDriverChipRunning) {
|
||||
// Enable + RGB control + CW control
|
||||
if (mqttAdded == 0){
|
||||
poststr(request,"mqtt:\n");
|
||||
mqttAdded=1;
|
||||
}
|
||||
if (switchAdded == 0){
|
||||
poststr(request," light:\n");
|
||||
switchAdded=1;
|
||||
}
|
||||
|
||||
uniq_id = hass_build_unique_id(ENTITY_LIGHT,i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",uniq_id);
|
||||
os_free(uniq_id);
|
||||
|
||||
hprintf128(request," name: \"%s %i\"\n",shortDeviceName,i);
|
||||
|
||||
|
||||
hprintf128(request," rgb_command_template: \"{{ '#%02x%02x%02x0000' | format(red, green, blue)}}\"\n");
|
||||
hprintf128(request," rgb_state_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
|
||||
hprintf128(request," rgb_command_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
|
||||
hprintf128(request," command_topic: \"cmnd/%s/led_enableAll\"\n",clientId);
|
||||
hprintf128(request," availability_topic: \"%s/connected\"\n",clientId);
|
||||
hprintf128(request," payload_on: 1\n");
|
||||
hprintf128(request," payload_off: 0\n");
|
||||
hprintf128(request," brightness_command_topic: \"cmnd/%s/led_dimmer\"\n",clientId);
|
||||
hprintf128(request," brightness_scale: 100\n");
|
||||
hprintf128(request," brightness_value_template: \"{{ value_json.Dimmer }}\"\n");
|
||||
hprintf128(request," color_temp_command_topic: \"cmnd/%s/led_temperature\"\n",clientId);
|
||||
hprintf128(request," color_temp_state_topic: \"cmnd/%s/ctr\"\n",clientId);
|
||||
hprintf128(request," color_temp_value_template: \"{{ value_json.CT }}\"\n");
|
||||
} else
|
||||
if(pwmCount == 3) {
|
||||
// Enable + RGB control
|
||||
if (mqttAdded == 0){
|
||||
poststr(request,"mqtt:\n");
|
||||
mqttAdded=1;
|
||||
}
|
||||
if (switchAdded == 0){
|
||||
poststr(request," light:\n");
|
||||
switchAdded=1;
|
||||
}
|
||||
|
||||
uniq_id = hass_build_unique_id(ENTITY_LIGHT,i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",uniq_id);
|
||||
os_free(uniq_id);
|
||||
|
||||
hprintf128(request," name: \"%s %i\"\n",shortDeviceName,i);
|
||||
|
||||
|
||||
hprintf128(request," rgb_command_template: \"{{ '#%02x%02x%02x0000' | format(red, green, blue)}}\"\n");
|
||||
hprintf128(request," rgb_state_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
|
||||
hprintf128(request," rgb_command_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
|
||||
hprintf128(request," command_topic: \"cmnd/%s/led_enableAll\"\n",clientId);
|
||||
hprintf128(request," availability_topic: \"%s/connected\"\n",clientId);
|
||||
hprintf128(request," payload_on: 1\n");
|
||||
hprintf128(request," payload_off: 0\n");
|
||||
hprintf128(request," brightness_command_topic: \"cmnd/%s/led_dimmer\"\n",clientId);
|
||||
hprintf128(request," brightness_scale: 100\n");
|
||||
hprintf128(request," brightness_value_template: \"{{ value_json.Dimmer }}\"\n");
|
||||
//hprintf128(request," color_temp_command_topic: \"cmnd/%s/led_temperature\"\n",clientId);
|
||||
//hprintf128(request," color_temp_state_topic: \"cmnd/%s/ctr\"\n",clientId);
|
||||
//hprintf128(request," color_temp_value_template: \"{{ value_json.CT }}\"\n");
|
||||
} else if(pwmCount > 0) {
|
||||
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
if(h_isChannelPWM(i)) {
|
||||
|
||||
Reference in New Issue
Block a user