Skip to content

Commit

Permalink
availability, cosmetics, hw for server
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Aug 22, 2023
1 parent d9593c7 commit 8844506
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/home_assistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct s_ha_info
char sw[MAX_LEN];
char hw[MAX_LEN];
char via[MAX_LEN];
char availability_topic[MAX_LEN];
t_ha_entity entities[MAX_ENTITIES];
int entitiy_count;
};
Expand Down
11 changes: 6 additions & 5 deletions src/home_assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void ha_publish(t_ha_info *ha_info)
ha_addstr(json_str, "ic", ha_info->entities[pos].ic, false);
ha_addstr(json_str, "mode", ha_info->entities[pos].mode, false);
ha_addstr(json_str, "ent_cat", ha_info->entities[pos].ent_cat, false);
ha_addstr(json_str, "avty_t", ha_info->availability_topic, false);
ha_addmqtt(ha_info, json_str, "cmd_t", ha_info->entities[pos].cmd_t, &ha_info->entities[pos], false);
ha_addmqtt(ha_info, json_str, "stat_t", ha_info->entities[pos].stat_t, &ha_info->entities[pos], false);
ha_addmqtt(ha_info, json_str, "rgbw_cmd_t", ha_info->entities[pos].rgbw_t, &ha_info->entities[pos], false);
Expand All @@ -188,8 +189,6 @@ void ha_publish(t_ha_info *ha_info)
ha_addint(json_str, "max", ha_info->entities[pos].max, false);
break;
case ha_switch:
ha_addstr(json_str, "pl_on", "TRUE", false);
ha_addstr(json_str, "pl_off", "FALSE", false);
ha_addstr(json_str, "stat_on", "TRUE", false);
ha_addstr(json_str, "stat_off", "FALSE", false);
break;
Expand Down Expand Up @@ -324,13 +323,15 @@ void ha_setup(t_ha_info *ha_info)
{
osMemset(ha_info, 0x00, sizeof(t_ha_info));

osSnprintf(ha_info->base_topic, sizeof(ha_info->base_topic), "%s", "teddyCloud");
osSnprintf(ha_info->base_topic, sizeof(ha_info->base_topic), "teddyCloud");
osSnprintf(ha_info->name, sizeof(ha_info->name), "%s", ha_info->base_topic);
osSnprintf(ha_info->id, sizeof(ha_info->id), "%s", "teddyCloud");
osSnprintf(ha_info->id, sizeof(ha_info->id), "teddyCloud");
osSnprintf(ha_info->cu, sizeof(ha_info->cu), "%s", settings_get_string("core.host_url"));
osSnprintf(ha_info->mf, sizeof(ha_info->mf), "Team RevvoX");
osSnprintf(ha_info->mdl, sizeof(ha_info->mdl), "%s", "teddyCloud");
osSnprintf(ha_info->mdl, sizeof(ha_info->mdl), "teddyCloud");
osSnprintf(ha_info->sw, sizeof(ha_info->sw), "%s (%s)", get_settings()->internal.version.id, get_settings()->internal.version.git_sha_short);
osSnprintf(ha_info->hw, sizeof(ha_info->hw), "%s %s", get_settings()->internal.version.platform, get_settings()->internal.version.architecture);

ha_info->entitiy_count = 0;
ha_info->initialized = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,8 @@ error_t mqtt_init_box(t_ha_info *ha_box_instance, client_ctx_t *client_ctx)
osSprintf(ha_box_instance->base_topic, "%s/box/%s", settings_get_string("mqtt.topic"), box_id);
osSprintf(ha_box_instance->mf, "%s", "tonies");
osSprintf(ha_box_instance->mdl, "%s", "Toniebox");
osSprintf(ha_box_instance->sw, "%s", "Unknown"); // TODO
osStrcpy(ha_box_instance->via, ha_server_instance.id);
osStrcpy(ha_box_instance->availability_topic, ha_server_instance.availability_topic); // TODO for each box individually
TRACE_INFO("Registered new box '%s' (cn: '%s')\r\n", box_name, box_id);
TRACE_INFO("Using base path '%s' and id '%s'\r\n", ha_box_instance->base_topic, ha_box_instance->id);

Expand Down Expand Up @@ -906,6 +906,7 @@ void mqtt_init()
osStrcpy(ha_server_instance.name, settings_get_string("hass.name"));
osStrcpy(ha_server_instance.id, settings_get_string("hass.id"));
osStrcpy(ha_server_instance.base_topic, settings_get_string("mqtt.topic"));
osStrcpy(ha_server_instance.availability_topic, (const char *)mqtt_prefix("status", ha_server_instance.base_topic));

for (size_t index = 0; index < settings_get_size(); index++)
{
Expand Down

0 comments on commit 8844506

Please sign in to comment.