mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-10 10:25:48 +00:00
illuminance channel type for Homa Assistant Discovery
This commit is contained in:
@ -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", "%");
|
||||
|
||||
@ -61,6 +61,8 @@ typedef enum {
|
||||
SMOKE_SENSOR,
|
||||
/// @brief
|
||||
READONLYLOWMIDHIGH_SENSOR,
|
||||
// lx unit
|
||||
ILLUMINANCE_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.
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user