mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-23 03:06:42 +00:00
Prevent redundant idle messages
This commit is contained in:
parent
e3a6391496
commit
b073983275
@ -114,25 +114,23 @@ HASP_ATTRIBUTE_FAST_MEM void hasp_update_sleep_state()
|
|||||||
|
|
||||||
if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong)) {
|
if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong)) {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_LONG) {
|
if(hasp_sleep_state != HASP_SLEEP_LONG) {
|
||||||
hasp_sleep_state = HASP_SLEEP_LONG;
|
|
||||||
gui_hide_pointer(true);
|
gui_hide_pointer(true);
|
||||||
dispatch_idle(NULL, NULL, TAG_HASP);
|
hasp_sleep_state = HASP_SLEEP_LONG;
|
||||||
|
dispatch_idle_state(HASP_SLEEP_LONG);
|
||||||
}
|
}
|
||||||
} else if(sleepTimeShort > 0 && idle >= sleepTimeShort) {
|
} else if(sleepTimeShort > 0 && idle >= sleepTimeShort) {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_SHORT) {
|
if(hasp_sleep_state != HASP_SLEEP_SHORT) {
|
||||||
hasp_sleep_state = HASP_SLEEP_SHORT;
|
|
||||||
gui_hide_pointer(true);
|
gui_hide_pointer(true);
|
||||||
dispatch_idle(NULL, NULL, TAG_HASP);
|
hasp_sleep_state = HASP_SLEEP_SHORT;
|
||||||
|
dispatch_idle_state(HASP_SLEEP_SHORT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(hasp_sleep_state != HASP_SLEEP_OFF) {
|
if(hasp_sleep_state != HASP_SLEEP_OFF) {
|
||||||
hasp_sleep_state = HASP_SLEEP_OFF;
|
|
||||||
gui_hide_pointer(false);
|
gui_hide_pointer(false);
|
||||||
dispatch_idle(NULL, NULL, TAG_HASP);
|
hasp_sleep_state = HASP_SLEEP_OFF;
|
||||||
|
dispatch_idle_state(HASP_SLEEP_OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return (hasp_sleep_state != HASP_SLEEP_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasp_set_sleep_offset(uint32_t offset)
|
void hasp_set_sleep_offset(uint32_t offset)
|
||||||
@ -140,6 +138,11 @@ void hasp_set_sleep_offset(uint32_t offset)
|
|||||||
sleepTimeOffset = offset;
|
sleepTimeOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t hasp_get_sleep_state()
|
||||||
|
{
|
||||||
|
return hasp_sleep_state;
|
||||||
|
}
|
||||||
|
|
||||||
void hasp_set_sleep_state(uint8_t state)
|
void hasp_set_sleep_state(uint8_t state)
|
||||||
{
|
{
|
||||||
switch(state) {
|
switch(state) {
|
||||||
@ -151,6 +154,7 @@ void hasp_set_sleep_state(uint8_t state)
|
|||||||
break;
|
break;
|
||||||
case HASP_SLEEP_OFF:
|
case HASP_SLEEP_OFF:
|
||||||
hasp_set_sleep_offset(0);
|
hasp_set_sleep_offset(0);
|
||||||
|
hasp_set_wakeup_touch(false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -159,9 +163,9 @@ void hasp_set_sleep_state(uint8_t state)
|
|||||||
hasp_sleep_state = state;
|
hasp_sleep_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasp_get_sleep_state(char* payload)
|
void hasp_get_sleep_payload(uint8_t state, char* payload)
|
||||||
{
|
{
|
||||||
switch(hasp_sleep_state) {
|
switch(state) {
|
||||||
case HASP_SLEEP_LONG:
|
case HASP_SLEEP_LONG:
|
||||||
memcpy_P(payload, PSTR("long"), 5);
|
memcpy_P(payload, PSTR("long"), 5);
|
||||||
break;
|
break;
|
||||||
@ -712,7 +716,7 @@ void hasp_get_info(JsonDocument& doc)
|
|||||||
buffer += "s";
|
buffer += "s";
|
||||||
info[F(D_INFO_ENVIRONMENT)] = PIOENV;
|
info[F(D_INFO_ENVIRONMENT)] = PIOENV;
|
||||||
info[F(D_INFO_UPTIME)] = buffer;
|
info[F(D_INFO_UPTIME)] = buffer;
|
||||||
hasp_get_sleep_state(size_buf);
|
hasp_get_sleep_payload(hasp_get_sleep_state(), size_buf);
|
||||||
info[F("Idle")] = size_buf;
|
info[F("Idle")] = size_buf;
|
||||||
info[F("Active Page")] = haspPages.get();
|
info[F("Active Page")] = haspPages.get();
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ bool haspSetConfig(const JsonObject& settings);
|
|||||||
lv_font_t* hasp_get_font(uint8_t fontid);
|
lv_font_t* hasp_get_font(uint8_t fontid);
|
||||||
|
|
||||||
HASP_ATTRIBUTE_FAST_MEM void hasp_update_sleep_state();
|
HASP_ATTRIBUTE_FAST_MEM void hasp_update_sleep_state();
|
||||||
void hasp_get_sleep_state(char* payload);
|
void hasp_get_sleep_payload(uint8_t state, char* payload);
|
||||||
|
uint8_t hasp_get_sleep_state();
|
||||||
void hasp_set_sleep_state(uint8_t state);
|
void hasp_set_sleep_state(uint8_t state);
|
||||||
void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time);
|
void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time);
|
||||||
void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time);
|
void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time);
|
||||||
|
@ -1169,7 +1169,7 @@ void dispatch_statusupdate(const char*, const char*, uint8_t source)
|
|||||||
{
|
{
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
|
|
||||||
hasp_get_sleep_state(topic);
|
hasp_get_sleep_payload(hasp_get_sleep_state(), topic);
|
||||||
snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"),
|
snprintf_P(data, sizeof(data), PSTR("{\"node\":\"%s\",\"idle\":\"%s\",\"version\":\"%s\",\"uptime\":%lu,"),
|
||||||
haspDevice.get_hostname(), topic, haspDevice.get_version(),
|
haspDevice.get_hostname(), topic, haspDevice.get_version(),
|
||||||
long(millis() / 1000)); // \"status\":\"available\",
|
long(millis() / 1000)); // \"status\":\"available\",
|
||||||
@ -1216,8 +1216,8 @@ void dispatch_statusupdate(const char*, const char*, uint8_t source)
|
|||||||
|
|
||||||
void dispatch_current_state(uint8_t source)
|
void dispatch_current_state(uint8_t source)
|
||||||
{
|
{
|
||||||
dispatch_idle(NULL, NULL, source);
|
|
||||||
dispatch_current_page();
|
dispatch_current_page();
|
||||||
|
dispatch_idle_state(hasp_get_sleep_state());
|
||||||
dispatch_state_antiburn(hasp_get_antiburn());
|
dispatch_state_antiburn(hasp_get_antiburn());
|
||||||
|
|
||||||
// delayed published topic
|
// delayed published topic
|
||||||
@ -1249,11 +1249,18 @@ void dispatch_calibrate(const char*, const char*, uint8_t source)
|
|||||||
guiCalibrate();
|
guiCalibrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispatch_wakeup()
|
||||||
|
{
|
||||||
|
if(hasp_get_sleep_state() == HASP_SLEEP_OFF) return;
|
||||||
|
hasp_set_sleep_state(HASP_SLEEP_OFF);
|
||||||
|
dispatch_idle_state(HASP_SLEEP_OFF);
|
||||||
|
}
|
||||||
|
|
||||||
void dispatch_wakeup_obsolete(const char* topic, const char*, uint8_t source)
|
void dispatch_wakeup_obsolete(const char* topic, const char*, uint8_t source)
|
||||||
{
|
{
|
||||||
LOG_WARNING(TAG_MSGR, F(D_ATTRIBUTE_OBSOLETE D_ATTRIBUTE_INSTEAD), topic,
|
LOG_WARNING(TAG_MSGR, F(D_ATTRIBUTE_OBSOLETE D_ATTRIBUTE_INSTEAD), topic,
|
||||||
"idle=off"); // TODO: obsolete dim, light and brightness
|
"idle=off"); // TODO: obsolete dim, light and brightness
|
||||||
lv_disp_trig_activity(NULL);
|
dispatch_wakeup();
|
||||||
hasp_set_wakeup_touch(false);
|
hasp_set_wakeup_touch(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1262,31 +1269,32 @@ void dispatch_sleep(const char*, const char*, uint8_t source)
|
|||||||
hasp_set_wakeup_touch(false);
|
hasp_set_wakeup_touch(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_idle(const char*, const char* payload, uint8_t source)
|
void dispatch_idle_state(uint8_t state)
|
||||||
{
|
{
|
||||||
char topic[8];
|
char topic[8];
|
||||||
char buffer[8];
|
char buffer[8];
|
||||||
|
memcpy_P(topic, PSTR("idle"), 8);
|
||||||
|
hasp_get_sleep_payload(state, buffer);
|
||||||
|
dispatch_state_subtopic(topic, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
// idle off command
|
void dispatch_idle(const char*, const char* payload, uint8_t source)
|
||||||
|
{
|
||||||
if(payload && strlen(payload)) {
|
if(payload && strlen(payload)) {
|
||||||
uint8_t state = HASP_SLEEP_LAST;
|
uint8_t state = HASP_SLEEP_LAST;
|
||||||
if(!strcmp_P(payload, "off")) {
|
if(!strcmp_P(payload, "off")) {
|
||||||
hasp_set_wakeup_touch(false);
|
hasp_set_sleep_state(HASP_SLEEP_OFF);
|
||||||
state = HASP_SLEEP_OFF;
|
|
||||||
} else if(!strcmp_P(payload, "short")) {
|
} else if(!strcmp_P(payload, "short")) {
|
||||||
state = HASP_SLEEP_SHORT;
|
hasp_set_sleep_state(HASP_SLEEP_SHORT);
|
||||||
} else if(!strcmp_P(payload, "long")) {
|
} else if(!strcmp_P(payload, "long")) {
|
||||||
state = HASP_SLEEP_LONG;
|
hasp_set_sleep_state(HASP_SLEEP_LONG);
|
||||||
} else {
|
} else {
|
||||||
state = HASP_SLEEP_LAST;
|
LOG_WARNING(TAG_MSGR, F("Invalid idle value %s"), payload);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
hasp_set_sleep_state(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// idle state
|
dispatch_idle_state(hasp_get_sleep_state()); // always send the current state
|
||||||
memcpy_P(topic, PSTR("idle"), 8);
|
|
||||||
hasp_get_sleep_state(buffer);
|
|
||||||
dispatch_state_subtopic(topic, buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_reboot(const char*, const char*, uint8_t source)
|
void dispatch_reboot(const char*, const char*, uint8_t source)
|
||||||
|
@ -72,10 +72,11 @@ void dispatch_web_update(const char*, const char* espOtaUrl, uint8_t source);
|
|||||||
void dispatch_statusupdate(const char*, const char*, uint8_t source);
|
void dispatch_statusupdate(const char*, const char*, uint8_t source);
|
||||||
void dispatch_send_discovery(const char*, const char*, uint8_t source);
|
void dispatch_send_discovery(const char*, const char*, uint8_t source);
|
||||||
void dispatch_send_sensordata(const char*, const char*, uint8_t source);
|
void dispatch_send_sensordata(const char*, const char*, uint8_t source);
|
||||||
void dispatch_idle(const char*, const char*, uint8_t source);
|
// void dispatch_idle(const char*, const char*, uint8_t source);
|
||||||
|
void dispatch_idle_state(uint8_t state);
|
||||||
void dispatch_calibrate(const char*, const char*, uint8_t source);
|
void dispatch_calibrate(const char*, const char*, uint8_t source);
|
||||||
void dispatch_antiburn(const char*, const char* payload, uint8_t source);
|
void dispatch_antiburn(const char*, const char* payload, uint8_t source);
|
||||||
void dispatch_wakeup(const char*, const char*, uint8_t source);
|
void dispatch_wakeup();
|
||||||
void dispatch_exec(const char*, const char* payload, uint8_t source);
|
void dispatch_exec(const char*, const char* payload, uint8_t source);
|
||||||
void dispatch_config(const char* topic, const char* payload, uint8_t source);
|
void dispatch_config(const char* topic, const char* payload, uint8_t source);
|
||||||
|
|
||||||
|
@ -961,16 +961,16 @@ static void handleFileCreate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(webServer.hasArg(F("init"))) {
|
if(webServer.hasArg(F("init"))) {
|
||||||
dispatch_idle(NULL, "0", TAG_HTTP);
|
dispatch_wakeup();
|
||||||
hasp_init();
|
hasp_init();
|
||||||
}
|
}
|
||||||
if(webServer.hasArg(F("load"))) {
|
if(webServer.hasArg(F("load"))) {
|
||||||
dispatch_idle(NULL, "0", TAG_HTTP);
|
dispatch_wakeup();
|
||||||
hasp_load_json();
|
hasp_load_json();
|
||||||
}
|
}
|
||||||
if(webServer.hasArg(F("page"))) {
|
if(webServer.hasArg(F("page"))) {
|
||||||
|
dispatch_wakeup();
|
||||||
uint8_t pageid = atoi(webServer.arg(F("page")).c_str());
|
uint8_t pageid = atoi(webServer.arg(F("page")).c_str());
|
||||||
dispatch_idle(NULL, "0", TAG_HTTP);
|
|
||||||
dispatch_set_page(pageid, LV_SCR_LOAD_ANIM_NONE);
|
dispatch_set_page(pageid, LV_SCR_LOAD_ANIM_NONE);
|
||||||
}
|
}
|
||||||
webServer.send(200, PSTR("text/plain"), "");
|
webServer.send(200, PSTR("text/plain"), "");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user