mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[shelly] Fix timeDuration handling in DTOs (#17689)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
+3
-3
@@ -605,12 +605,12 @@ public class Shelly2ApiClient extends ShellyHttpClient {
|
||||
return channelUpdate ? ShellyComponents.updateDimmers(getThing(), status) : false;
|
||||
}
|
||||
|
||||
protected @Nullable Integer getDuration(@Nullable Double timerStartedAt, @Nullable Integer timerDuration) {
|
||||
protected @Nullable Integer getDuration(@Nullable Double timerStartedAt, @Nullable Double timerDuration) {
|
||||
if (timerStartedAt == null || timerDuration == null) {
|
||||
return null;
|
||||
}
|
||||
int duration = (int) (now() - timerStartedAt.longValue());
|
||||
return duration <= timerDuration ? timerDuration - duration : 0;
|
||||
double duration = now() - timerStartedAt;
|
||||
return duration <= timerDuration ? (int) (timerDuration - duration) : 0;
|
||||
}
|
||||
|
||||
// Addon
|
||||
|
||||
+2
-2
@@ -580,7 +580,7 @@ public class Shelly2ApiJsonDTO {
|
||||
@SerializedName("timer_started_at")
|
||||
public Double timerStartedAt;
|
||||
@SerializedName("timer_duration")
|
||||
public Integer timerDuration;
|
||||
public Double timerDuration;
|
||||
}
|
||||
|
||||
public static class Shelly2DeviceStatusResult {
|
||||
@@ -882,7 +882,7 @@ public class Shelly2ApiJsonDTO {
|
||||
@SerializedName("timer_started_at")
|
||||
public Double timerStartetAt;
|
||||
@SerializedName("timer_duration")
|
||||
public Integer timerDuration;
|
||||
public Double timerDuration;
|
||||
public Double apower;
|
||||
public Double voltage;
|
||||
public Double current;
|
||||
|
||||
+5
-5
@@ -120,7 +120,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||
private String lastWakeupReason = "";
|
||||
|
||||
// Scheduler
|
||||
private long watchdog = now();
|
||||
private double watchdog = now();
|
||||
protected int scheduledUpdates = 0;
|
||||
private int skipCount = UPDATE_SKIP_COUNT;
|
||||
private int skipUpdate = 0;
|
||||
@@ -724,9 +724,9 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||
}
|
||||
|
||||
private boolean isWatchdogExpired() {
|
||||
long delta = now() - watchdog;
|
||||
double delta = now() - watchdog;
|
||||
if ((watchdog > 0) && (delta > profile.updatePeriod)) {
|
||||
stats.remainingWatchdog = delta;
|
||||
stats.remainingWatchdog = (long) delta;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -761,7 +761,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||
stats.timeoutErrors = api.getTimeoutErrors();
|
||||
stats.timeoutsRecorvered = api.getTimeoutsRecovered();
|
||||
}
|
||||
stats.remainingWatchdog = watchdog > 0 ? now() - watchdog : 0;
|
||||
stats.remainingWatchdog = watchdog > 0 ? (long) (now() - watchdog) : 0;
|
||||
|
||||
// Check various device indicators like overheating
|
||||
if (checkRestarted(status)) {
|
||||
@@ -855,7 +855,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||
triggerChannel(channelId, event);
|
||||
cache.updateChannel(channelId, getStringType(event.toUpperCase()));
|
||||
stats.lastAlarm = event;
|
||||
stats.lastAlarmTs = now();
|
||||
stats.lastAlarmTs = (long) now();
|
||||
stats.alarms++;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -27,6 +27,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import javax.measure.Unit;
|
||||
|
||||
@@ -290,12 +291,12 @@ public class ShellyUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Long now() {
|
||||
return System.currentTimeMillis() / 1000L;
|
||||
public static double now() {
|
||||
return System.currentTimeMillis() / 1000.0;
|
||||
}
|
||||
|
||||
public static DateTimeType getTimestamp() {
|
||||
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(now()), ZoneId.systemDefault()));
|
||||
return new DateTimeType(ZonedDateTime.now().truncatedTo(ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
public static DateTimeType getTimestamp(String zone, long timestamp) {
|
||||
|
||||
Reference in New Issue
Block a user