change uptime value

This commit is contained in:
Stephan Mühl
2023-04-09 19:41:01 +02:00
parent 2a8149400b
commit d8fe5095f0
2 changed files with 3 additions and 8 deletions

View File

@@ -399,6 +399,7 @@ void MQTTManager_::setup()
uptime = new HASensor(upID); uptime = new HASensor(upID);
uptime->setName(HAupName); uptime->setName(HAupName);
uptime->setDeviceClass(HAupClass); uptime->setDeviceClass(HAupClass);
uptime->setUnitOfMeasurement("s");
sprintf(btnLID, HAbtnLID, macStr); sprintf(btnLID, HAbtnLID, macStr);
btnleft = new HABinarySensor(btnLID); btnleft = new HABinarySensor(btnLID);

View File

@@ -363,18 +363,12 @@ void PeripheryManager_::checkAlarms()
} }
} }
const char *PeripheryManager_::readUptime() const char* PeripheryManager_::readUptime()
{ {
static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns static char uptime[25]; // Make the array static to keep it from being destroyed when the function returns
unsigned long currentTime = millis(); unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime; unsigned long elapsedTime = currentTime - startTime;
unsigned long uptimeSeconds = elapsedTime / 1000; unsigned long uptimeSeconds = elapsedTime / 1000;
unsigned long uptimeMinutes = uptimeSeconds / 60; sprintf(uptime, "%lu", uptimeSeconds);
unsigned long uptimeHours = uptimeMinutes / 60;
unsigned long uptimeDays = uptimeHours / 24;
unsigned long hours = uptimeHours % 24;
unsigned long minutes = uptimeMinutes % 60;
unsigned long seconds = uptimeSeconds % 60;
sprintf(uptime, "P%dDT%dH%dM%dS", uptimeDays, hours, minutes, seconds);
return uptime; return uptime;
} }