mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-14 11:18:41 +01:00
Merge pull request #157 from iprak/fix_hass_unique_id
Generate better uniqued id, fixed payload
This commit is contained in:
@@ -1241,12 +1241,27 @@ int http_fn_cfg_quick(http_request_t *request) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates HomeAssistant unique id
|
||||
* @param outBuffer Output buffer (128 char)
|
||||
* @param type Entity type (relay, light)
|
||||
* @param index Entity index
|
||||
*/
|
||||
void build_hass_unique_id(char *outBuffer, 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
|
||||
sprintf(outBuffer,"%s_%s_%d",g_cfg.longDeviceName,type,index);
|
||||
}
|
||||
|
||||
int http_fn_cfg_ha(http_request_t *request) {
|
||||
int relayCount = 0;
|
||||
int pwmCount = 0;
|
||||
const char *baseName;
|
||||
int i;
|
||||
char mqttAdded = 0;
|
||||
char unique_id[128]; //64 for longDeviceName, 10 for type,3 for index .. 128 would be sufficient
|
||||
|
||||
baseName = CFG_GetShortDeviceName();
|
||||
|
||||
@@ -1286,13 +1301,14 @@ int http_fn_cfg_ha(http_request_t *request) {
|
||||
switchAdded=1;
|
||||
}
|
||||
|
||||
hprintf128(request," - unique_id: \"%s %i\"\n",baseName,i);
|
||||
build_hass_unique_id(unique_id,"relay",i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",unique_id);
|
||||
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);
|
||||
@@ -1313,7 +1329,8 @@ int http_fn_cfg_ha(http_request_t *request) {
|
||||
lightAdded=1;
|
||||
}
|
||||
|
||||
hprintf128(request," - unique_id: \"%s %i\"\n",baseName,i);
|
||||
build_hass_unique_id(unique_id,"light",i);
|
||||
hprintf128(request," - unique_id: \"%s\"\n",unique_id);
|
||||
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