mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[shelly] Fix timeDuration handling in DTOs (#17689)
Signed-off-by: Jan N. Klug <github@klug.nrw> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
fce9509a99
commit
9c5bd0e057
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user