mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-09 00:37:59 +01:00
flag for adding relays as lights in hA discovery
This commit is contained in:
@@ -29,10 +29,10 @@ void hass_populate_unique_id(ENTITY_TYPE type, int index, char* uniq_id) {
|
||||
const char* longDeviceName = CFG_GetDeviceName();
|
||||
|
||||
switch (type) {
|
||||
case LIGHT_ON_OFF:
|
||||
case LIGHT_PWM:
|
||||
sprintf(uniq_id, "%s_%s_%d", longDeviceName, "light", index);
|
||||
break;
|
||||
|
||||
case LIGHT_PWMCW:
|
||||
case LIGHT_RGB:
|
||||
case LIGHT_RGBCW:
|
||||
@@ -77,6 +77,7 @@ void hass_print_unique_id(http_request_t* request, const char* fmt, ENTITY_TYPE
|
||||
/// @param info Device info
|
||||
void hass_populate_device_config_channel(ENTITY_TYPE type, char* uniq_id, HassDeviceInfo* info) {
|
||||
switch (type) {
|
||||
case LIGHT_ON_OFF:
|
||||
case LIGHT_PWM:
|
||||
case LIGHT_PWMCW:
|
||||
case LIGHT_RGB:
|
||||
@@ -145,6 +146,7 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload
|
||||
|
||||
//Build the `name`
|
||||
switch (type) {
|
||||
case LIGHT_ON_OFF:
|
||||
case LIGHT_PWM:
|
||||
case RELAY:
|
||||
case BINARY_SENSOR:
|
||||
@@ -195,8 +197,8 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload
|
||||
/// @brief Initializes HomeAssistant relay device discovery storage.
|
||||
/// @param index
|
||||
/// @return
|
||||
HassDeviceInfo* hass_init_relay_device_info(int index) {
|
||||
HassDeviceInfo* info = hass_init_device_info(RELAY, index, "1", "0");
|
||||
HassDeviceInfo* hass_init_relay_device_info(int index, ENTITY_TYPE type) {
|
||||
HassDeviceInfo* info = hass_init_device_info(type, index, "1", "0");
|
||||
|
||||
sprintf(g_hassBuffer, "~/%i/get", index);
|
||||
cJSON_AddStringToObject(info->root, STATE_TOPIC_KEY, g_hassBuffer); //state_topic
|
||||
@@ -229,6 +231,7 @@ HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type) {
|
||||
cJSON_AddStringToObject(info->root, "rgb_cmd_t", g_hassBuffer); //rgb_command_topic
|
||||
break;
|
||||
|
||||
case LIGHT_ON_OFF:
|
||||
case LIGHT_PWM:
|
||||
brightness_scale = 100;
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,9 @@ typedef enum {
|
||||
/// @brief Switch
|
||||
RELAY = 0,
|
||||
|
||||
/// @brief
|
||||
LIGHT_ON_OFF,
|
||||
|
||||
/// @brief Single PWM
|
||||
LIGHT_PWM,
|
||||
|
||||
@@ -55,7 +58,7 @@ typedef struct HassDeviceInfo_s {
|
||||
} HassDeviceInfo;
|
||||
|
||||
void hass_print_unique_id(http_request_t* request, const char* fmt, ENTITY_TYPE type, int index);
|
||||
HassDeviceInfo* hass_init_relay_device_info(int index);
|
||||
HassDeviceInfo* hass_init_relay_device_info(int index, ENTITY_TYPE type);
|
||||
HassDeviceInfo* hass_init_light_device_info(ENTITY_TYPE type);
|
||||
HassDeviceInfo* hass_init_power_sensor_device_info(int index);
|
||||
HassDeviceInfo* hass_init_binary_sensor_device_info(int index);
|
||||
|
||||
@@ -1638,7 +1638,12 @@ void doHomeAssistantDiscovery(const char *topic, http_request_t *request) {
|
||||
if (relayCount > 0) {
|
||||
for (i = 0; i < CHANNEL_MAX; i++) {
|
||||
if (h_isChannelRelay(i)) {
|
||||
dev_info = hass_init_relay_device_info(i);
|
||||
if (CFG_HasFlag(OBK_FLAG_MQTT_HASS_ADD_RELAYS_AS_LIGHTS)) {
|
||||
dev_info = hass_init_relay_device_info(i, LIGHT_ON_OFF);
|
||||
}
|
||||
else {
|
||||
dev_info = hass_init_relay_device_info(i, RELAY);
|
||||
}
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
hass_free_device_info(dev_info);
|
||||
dev_info = NULL;
|
||||
@@ -2238,7 +2243,7 @@ const char* g_obk_flagNames[] = {
|
||||
"[UART] Enable UART command line",
|
||||
"[LED] Use old linear brightness mode, ignore gamma ramp",
|
||||
"[MQTT] Apply channel type multiplier on (if any) on channel value before publishing it",
|
||||
"error",
|
||||
"[MQTT] In HA discovery, add relays as lights",
|
||||
"error",
|
||||
"error",
|
||||
"error",
|
||||
|
||||
Reference in New Issue
Block a user