This commit is contained in:
Tester
2023-08-11 09:43:28 +02:00
98 changed files with 3068 additions and 358 deletions

View File

@@ -67,6 +67,9 @@ void hass_populate_unique_id(ENTITY_TYPE type, int index, char* uniq_id) {
case CO2_SENSOR:
sprintf(uniq_id, "%s_%s_%d", longDeviceName, "co2", index);
break;
case ILLUMINANCE_SENSOR:
sprintf(uniq_id, "%s_%s_%d", longDeviceName, "illuminance", index);
break;
case SMOKE_SENSOR:
sprintf(uniq_id, "%s_%s_%d", longDeviceName, "smoke", index);
break;
@@ -235,6 +238,9 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload
case VOLTAGE_SENSOR:
sprintf(g_hassBuffer, "%s Voltage", CFG_GetShortDeviceName());
break;
case ILLUMINANCE_SENSOR:
sprintf(g_hassBuffer, "%s Illuminance", CFG_GetShortDeviceName());
break;
default:
sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), CHANNEL_GetLabel(index));
break;
@@ -499,6 +505,12 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int
sprintf(g_hassBuffer, "~/%d/get", channel);
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
break;
case ILLUMINANCE_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "illuminance");
cJSON_AddStringToObject(info->root, "unit_of_meas", "lx");
sprintf(g_hassBuffer, "~/%d/get", channel);
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
break;
case BATTERY_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "battery");
cJSON_AddStringToObject(info->root, "unit_of_meas", "%");
@@ -527,6 +539,13 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int
sprintf(g_hassBuffer, "~/%d/get", channel);
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
break;
case ENERGY_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "energy");
cJSON_AddStringToObject(info->root, "unit_of_meas", "kWh");
sprintf(g_hassBuffer, "~/%d/get", channel);
cJSON_AddStringToObject(info->root, "stat_cla", "total_increasing");
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
break;
case POWERFACTOR_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "power_factor");
//cJSON_AddStringToObject(info->root, "unit_of_meas", "W");
@@ -555,7 +574,7 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int
return NULL;
}
if (type != READONLYLOWMIDHIGH_SENSOR) {
if (type != READONLYLOWMIDHIGH_SENSOR && type != ENERGY_SENSOR) {
cJSON_AddStringToObject(info->root, "stat_cla", "measurement");
}

View File

@@ -61,6 +61,10 @@ typedef enum {
SMOKE_SENSOR,
/// @brief
READONLYLOWMIDHIGH_SENSOR,
// lx unit
ILLUMINANCE_SENSOR,
ENERGY_SENSOR,
} ENTITY_TYPE;
//unique_id is defined in hass_populate_unique_id and is based on CFG_GetDeviceName() whose size is CGF_DEVICE_NAME_SIZE.

View File

@@ -480,6 +480,13 @@ int http_fn_index(http_request_t* request) {
poststr(request, "</td></tr>");
}
else if (channelType == ChType_Illuminance) {
iValue = CHANNEL_Get(i);
poststr(request, "<tr><td>");
hprintf255(request, "Illuminance (%s) = %i Lux", CHANNEL_GetLabel(i), iValue);
poststr(request, "</td></tr>");
}
else if (channelType == ChType_ReadOnly) {
iValue = CHANNEL_Get(i);
@@ -1866,6 +1873,15 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
discoveryQueued = true;
}
break;
case ChType_Illuminance:
{
dev_info = hass_init_sensor_device_info(ILLUMINANCE_SENSOR, i, -1, -1);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
discoveryQueued = true;
}
break;
case ChType_ReadOnly:
{
dev_info = hass_init_sensor_device_info(CUSTOM_SENSOR, i, -1, -1);
@@ -1965,6 +1981,24 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
discoveryQueued = true;
}
break;
case ChType_EnergyTotal_kWh_div100:
{
dev_info = hass_init_sensor_device_info(ENERGY_SENSOR, i, 3, 2);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
discoveryQueued = true;
}
break;
case ChType_EnergyTotal_kWh_div1000:
{
dev_info = hass_init_sensor_device_info(ENERGY_SENSOR, i, 3, 3);
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
hass_free_device_info(dev_info);
discoveryQueued = true;
}
break;
}
}
#endif
@@ -2478,7 +2512,7 @@ const char* g_obk_flagNames[] = {
"[Power] Set power and current to zero if all relays are open",
"[MQTT] [Debug] Publish all channels (don't enable it, it will be publish all 64 possible channels on connect)",
"[MQTT] Use kWh unit for energy consumption (total, last hour, today) instead of Wh",
"error",
"[BTN] Ignore all button events (aka child lock)",
"error",
"error",
"error",

View File

@@ -10,7 +10,7 @@
SOCKET ListenSocket = INVALID_SOCKET;
int g_port = 80;
int g_httpPort = 80;
int HTTPServer_Start() {
@@ -30,7 +30,7 @@ int HTTPServer_Start() {
}
// Resolve the server address and port
char service[6];
snprintf(service, sizeof(service), "%u", g_port);
snprintf(service, sizeof(service), "%u", g_httpPort);
iResult = getaddrinfo(NULL, service, &hints, &result);
if ( iResult != 0 ) {

View File

@@ -937,6 +937,14 @@ int JSON_ProcessCommandReply(const char* cmd, const char* arg, void* request, js
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS4");
}
}
else if (!stricmp(arg, "11")) {
printer(request, "{");
http_tasmota_json_status_STS(request, printer, true);
printer(request, "}");
if (flags == COMMAND_FLAG_SOURCE_MQTT) {
MQTT_PublishPrinterContentsToStat((struct obk_mqtt_publishReplyPrinter_s*)request, "STATUS11");
}
}
else if (!stricmp(arg, "2")) {
printer(request, "{");
http_tasmota_json_status_FWR(request, printer);

View File

@@ -459,6 +459,10 @@ const char* htmlPinRoleNames[] = {
"TM1638_DAT",
"TM1638_STB",
"BAT_Relay_n",
"KP18058_CLK",
"KP18058_DAT",
"error",
"error",
"error",
"error",
};
@@ -573,6 +577,7 @@ int hprintf255(http_request_t* request, const char* fmt, ...) {
return postany(request, tmp, strlen(tmp));
}
int HUE_APICall(http_request_t* request);
int HTTP_ProcessPacket(http_request_t* request) {
int i;
@@ -698,6 +703,12 @@ int HTTP_ProcessPacket(http_request_t* request) {
return http_fn_empty_url(request);
#endif
#if ENABLE_DRIVER_HUE
if (HUE_APICall(request)) {
return 0;
}
#endif
// look for a callback with this URL and method, or HTTP_ANY
for (i = 0; i < numCallbacks; i++) {
char* url = callbacks[i]->url;

View File

@@ -348,6 +348,7 @@ static int http_rest_get_lfs_file(http_request_t* request) {
int lfsres;
int total = 0;
lfs_file_t* file;
char *args;
// don't start LFS just because we're trying to read a file -
// it won't exist anyway
@@ -366,6 +367,12 @@ static int http_rest_get_lfs_file(http_request_t* request) {
strcpy(fpath, request->url + strlen("api/lfs/"));
// strip HTTP args with ?
args = strchr(fpath, '?');
if (args) {
*args = 0;
}
ADDLOG_DEBUG(LOG_FEATURE_API, "LFS read of %s", fpath);
lfsres = lfs_file_open(&lfs, file, fpath, LFS_O_RDONLY);