mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-08 11:35:52 +00:00
Generate better uniqued id, fixed payload
This commit is contained in:
@ -1240,6 +1240,19 @@ int http_fn_cfg_quick(http_request_t *request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Generate HomeAssistant unique id based
|
||||
char *build_hass_unique_id(char *type, int index){
|
||||
//https://developers.home-assistant.io/docs/entity_registry_index/#unique-id-requirements mentions that mac can be used for
|
||||
//unique_id and I would think that longDeviceName should contain that.
|
||||
|
||||
//e.g. longDeviceName_relay_1
|
||||
int length = strlen(g_cfg.longDeviceName) + strlen(type)+ 1 + 3;
|
||||
char *unique_id = (char*)malloc (length * sizeof (char));
|
||||
|
||||
sprintf(unique_id,"%s_%s_%d",g_cfg.longDeviceName,type,index);
|
||||
return unique_id;
|
||||
}
|
||||
|
||||
int http_fn_cfg_ha(http_request_t *request) {
|
||||
int relayCount = 0;
|
||||
int pwmCount = 0;
|
||||
@ -1285,13 +1298,13 @@ int http_fn_cfg_ha(http_request_t *request) {
|
||||
switchAdded=1;
|
||||
}
|
||||
|
||||
hprintf128(request," - unique_id: \"%s %i\"\n",baseName,i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",build_hass_unique_id("relay",i));
|
||||
hprintf128(request," name: \"%s %i\"\n",baseName,i);
|
||||
hprintf128(request," state_topic: \"%s/%i/get\"\n",baseName,i);
|
||||
hprintf128(request," command_topic: \"%s/%i/set\"\n",baseName,i);
|
||||
poststr(request, " qos: 1\n");
|
||||
poststr(request, " payload_on: 0\n");
|
||||
poststr(request, " payload_off: 1\n");
|
||||
poststr(request, " payload_on: 1\n");
|
||||
poststr(request, " payload_off: 0\n");
|
||||
poststr(request, " retain: true\n");
|
||||
hprintf128(request," availability:\n");
|
||||
hprintf128(request," - topic: \"%s/connected\"\n",baseName);
|
||||
@ -1312,7 +1325,7 @@ int http_fn_cfg_ha(http_request_t *request) {
|
||||
lightAdded=1;
|
||||
}
|
||||
|
||||
hprintf128(request," - unique_id: \"%s %i\"\n",baseName,i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",build_hass_unique_id("light",i));
|
||||
hprintf128(request," name: \"%s %i\"\n",baseName,i);
|
||||
hprintf128(request," state_topic: \"%s/%i/get\"\n",baseName,i);
|
||||
hprintf128(request," command_topic: \"%s/%i/set\"\n",baseName,i);
|
||||
|
||||
Reference in New Issue
Block a user