move code to get allowed weekdays code into helper class

This commit is contained in:
technyon
2025-10-06 20:10:36 +07:00
parent ce781f8f5b
commit b6e6b4400c
4 changed files with 54 additions and 90 deletions

View File

@@ -1045,51 +1045,7 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
uint8_t allowedWeekdaysInt = entry.allowedWeekdays; uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>(); JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
while(allowedWeekdaysInt > 0) NukiHelper::weekdaysToJsonArray(allowedWeekdaysInt, weekdays);
{
if(allowedWeekdaysInt >= 64)
{
weekdays.add("mon");
allowedWeekdaysInt -= 64;
continue;
}
if(allowedWeekdaysInt >= 32)
{
weekdays.add("tue");
allowedWeekdaysInt -= 32;
continue;
}
if(allowedWeekdaysInt >= 16)
{
weekdays.add("wed");
allowedWeekdaysInt -= 16;
continue;
}
if(allowedWeekdaysInt >= 8)
{
weekdays.add("thu");
allowedWeekdaysInt -= 8;
continue;
}
if(allowedWeekdaysInt >= 4)
{
weekdays.add("fri");
allowedWeekdaysInt -= 4;
continue;
}
if(allowedWeekdaysInt >= 2)
{
weekdays.add("sat");
allowedWeekdaysInt -= 2;
continue;
}
if(allowedWeekdaysInt >= 1)
{
weekdays.add("sun");
allowedWeekdaysInt -= 1;
continue;
}
}
char allowedFromTimeT[5]; char allowedFromTimeT[5];
sprintf(allowedFromTimeT, "%02d:%02d", entry.allowedFromTimeHour, entry.allowedFromTimeMin); sprintf(allowedFromTimeT, "%02d:%02d", entry.allowedFromTimeHour, entry.allowedFromTimeMin);

View File

@@ -6,6 +6,7 @@
#include "Config.h" #include "Config.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "hal/wdt_hal.h" #include "hal/wdt_hal.h"
#include "util/NukiHelper.h"
#include "util/NukiOpenerHelper.h" #include "util/NukiOpenerHelper.h"
NukiNetworkOpener::NukiNetworkOpener(NukiNetwork* network, Preferences* preferences, char* buffer, size_t bufferSize) NukiNetworkOpener::NukiNetworkOpener(NukiNetwork* network, Preferences* preferences, char* buffer, size_t bufferSize)
@@ -1273,51 +1274,7 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
uint8_t allowedWeekdaysInt = entry.allowedWeekdays; uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>(); JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
while(allowedWeekdaysInt > 0) NukiHelper::weekdaysToJsonArray(allowedWeekdaysInt, weekdays);
{
if(allowedWeekdaysInt >= 64)
{
weekdays.add("mon");
allowedWeekdaysInt -= 64;
continue;
}
if(allowedWeekdaysInt >= 32)
{
weekdays.add("tue");
allowedWeekdaysInt -= 32;
continue;
}
if(allowedWeekdaysInt >= 16)
{
weekdays.add("wed");
allowedWeekdaysInt -= 16;
continue;
}
if(allowedWeekdaysInt >= 8)
{
weekdays.add("thu");
allowedWeekdaysInt -= 8;
continue;
}
if(allowedWeekdaysInt >= 4)
{
weekdays.add("fri");
allowedWeekdaysInt -= 4;
continue;
}
if(allowedWeekdaysInt >= 2)
{
weekdays.add("sat");
allowedWeekdaysInt -= 2;
continue;
}
if(allowedWeekdaysInt >= 1)
{
weekdays.add("sun");
allowedWeekdaysInt -= 1;
continue;
}
}
char allowedFromTimeT[5]; char allowedFromTimeT[5];
sprintf(allowedFromTimeT, "%02d:%02d", entry.allowedFromTimeHour, entry.allowedFromTimeMin); sprintf(allowedFromTimeT, "%02d:%02d", entry.allowedFromTimeHour, entry.allowedFromTimeMin);

View File

@@ -446,6 +446,54 @@ void NukiHelper::fobActionToString(const int fobact, char* str)
} }
} }
void NukiHelper::weekdaysToJsonArray(int weekdaysInt, JsonArray& weekdays)
{
while(weekdaysInt > 0)
{
if(weekdaysInt >= 64)
{
weekdays.add("mon");
weekdaysInt -= 64;
continue;
}
if(weekdaysInt >= 32)
{
weekdays.add("tue");
weekdaysInt -= 32;
continue;
}
if(weekdaysInt >= 16)
{
weekdays.add("wed");
weekdaysInt -= 16;
continue;
}
if(weekdaysInt >= 8)
{
weekdays.add("thu");
weekdaysInt -= 8;
continue;
}
if(weekdaysInt >= 4)
{
weekdays.add("fri");
weekdaysInt -= 4;
continue;
}
if(weekdaysInt >= 2)
{
weekdays.add("sat");
weekdaysInt -= 2;
continue;
}
if(weekdaysInt >= 1)
{
weekdays.add("sun");
weekdaysInt -= 1;
}
}
}
void NukiHelper::printCommandResult(Nuki::CmdResult result) void NukiHelper::printCommandResult(Nuki::CmdResult result)
{ {

View File

@@ -2,6 +2,7 @@
#include "NukiConstants.h" #include "NukiConstants.h"
#include "NukiLock.h" #include "NukiLock.h"
#include <ArduinoJson.h>
class NukiHelper class NukiHelper
{ {
@@ -19,5 +20,7 @@ public:
static void homeKitStatusToString(const int hkstatus, char* str); static void homeKitStatusToString(const int hkstatus, char* str);
static void fobActionToString(const int fobact, char* str); static void fobActionToString(const int fobact, char* str);
static void weekdaysToJsonArray(int weekdaysInt, JsonArray& weekdays);
static void printCommandResult(Nuki::CmdResult result); static void printCommandResult(Nuki::CmdResult result);
}; };