Skip to content

Commit

Permalink
add "time" field
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 8, 2024
1 parent fb81d61 commit 1627463
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ bool isValidIntNumber(const char *str, const int maxValue, const int minValue=0)

std::string CommandProcessor::status() {
std::stringstream response;
const auto now = _env->time();
response << "{";
// send current time in milliseconds to synchronize time on client side
response << "\"time\": " << now << ", ";
// send water threshold
response << "\"water threshold\": " << _waterPumpSafeThreshold << ", ";
// send water pump status
const auto waterPumpStatus = _waterPump->status();
const auto now = _env->time();
const auto timeLeft = waterPumpStatus.isRunning ? waterPumpStatus.stopTime - now : 0;
response
<< "\"pump\": {"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TEST(CommandProcessor, status) {
CommandProcessor commandProcessor(123, env, waterPump);
const auto response = commandProcessor.status();
ASSERT_EQ(response, "{"
"\"time\": 0, "
"\"water threshold\": 123, "
"\"pump\": {"
" \"running\": false, "
Expand All @@ -69,6 +70,7 @@ TEST(CommandProcessor, status_running) {

const auto response = commandProcessor.status();
ASSERT_EQ(response, "{"
"\"time\": 123, "
"\"water threshold\": 12345, "
"\"pump\": {"
" \"running\": true, "
Expand Down

0 comments on commit 1627463

Please sign in to comment.