From 1f471ad308028d92af30b63a524b7e1e2e782b32 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Fri, 24 May 2024 05:03:53 +0200 Subject: [PATCH] Add custom_state_subtopic #611 --- src/custom/my_custom_fan_template.cpp | 4 ++++ src/custom/my_custom_template.cpp | 5 +++++ src/custom/my_custom_template.h | 5 +++++ src/hasp/hasp_dispatch.cpp | 12 +++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/custom/my_custom_fan_template.cpp b/src/custom/my_custom_fan_template.cpp index b7bed86da..a87752428 100644 --- a/src/custom/my_custom_fan_template.cpp +++ b/src/custom/my_custom_fan_template.cpp @@ -98,4 +98,8 @@ void custom_topic_payload(const char* topic, const char* payload, uint8_t source // LOG_VERBOSE(TAG_CUSTOM, "Handled custom message: %s => %s", topic, payload); } +void custom_state_subtopic(const char* subtopic, const char* payload){ + // Not used +} + #endif // HASP_USE_CUSTOM diff --git a/src/custom/my_custom_template.cpp b/src/custom/my_custom_template.cpp index b41da916b..358bbd0f5 100644 --- a/src/custom/my_custom_template.cpp +++ b/src/custom/my_custom_template.cpp @@ -53,4 +53,9 @@ void custom_topic_payload(const char* topic, const char* payload, uint8_t source // Not used } +void custom_state_subtopic(const char* subtopic, const char* payload){ + // Not used +} + + #endif // HASP_USE_CUSTOM \ No newline at end of file diff --git a/src/custom/my_custom_template.h b/src/custom/my_custom_template.h index 111df88fe..3e25c0311 100644 --- a/src/custom/my_custom_template.h +++ b/src/custom/my_custom_template.h @@ -32,6 +32,11 @@ void custom_get_sensors(JsonDocument& doc); /* Receive custom topic & payload messages */ void custom_topic_payload(const char* topic, const char* payload, uint8_t source); +/* Get notified when a state message is sent out */ +/* Can be used to send state changes through other means then MQTT, e.g. Serial2 */ +/* https://github.com/HASwitchPlate/openHASP/issues/611 */ +void custom_state_subtopic(const char* subtopic, const char* payload); + #endif // HASP_USE_CUSTOM #endif // HASP_CUSTOM_H diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index 03b0da9de..39ddae76e 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -43,7 +43,7 @@ uint16_t dispatchSecondsToNextTeleperiod = 0; uint16_t dispatchSecondsToNextSensordata = 0; uint16_t dispatchSecondsToNextDiscovery = 0; uint8_t nCommands = 0; -haspCommand_t commands[28]; +haspCommand_t commands[29]; moodlight_t moodlight = {.brightness = 255}; uint8_t saved_jsonl_page = 0; @@ -74,6 +74,10 @@ void dispatch_state_subtopic(const char* subtopic, const char* payload) } #endif +#if HASP_USE_CUSTOM > 0 + custom_state_subtopic(subtopic, payload); +#endif + #if HASP_USE_TASMOTA_CLIENT > 0 slave_send_state(subtopic, payload); #endif @@ -864,6 +868,11 @@ void dispatch_run_script(const char*, const char* payload, uint8_t source) #endif } +void dispatch_dir(const char*, const char* payload, uint8_t source) +{ + filesystem_list_path(payload); +} + #if HASP_TARGET_PC static void shell_command_thread(char* cmdline) { @@ -1592,6 +1601,7 @@ void dispatchSetup() dispatch_add_command(PSTR("sensors"), dispatch_send_sensordata); dispatch_add_command(PSTR("theme"), dispatch_theme); dispatch_add_command(PSTR("run"), dispatch_run_script); + dispatch_add_command(PSTR("dir"), dispatch_dir); #if HASP_TARGET_PC dispatch_add_command(PSTR("shell"), dispatch_shell_execute); #endif