Skip to content

Commit

Permalink
Add custom_state_subtopic HASwitchPlate#611
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanroie authored and marcoose committed Jul 7, 2024
1 parent ef15489 commit dd9e077
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/custom/my_custom_fan_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/custom/my_custom_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/custom/my_custom_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion src/hasp/hasp_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dd9e077

Please sign in to comment.