mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Simplify DateTimeType handling for Shelly
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
751bbf7495
commit
96b5ad2e55
@ -345,7 +345,6 @@ public class ShellyManagerPage {
|
|||||||
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
|
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value = getTimestamp(dateTimeState);
|
|
||||||
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
|
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -304,17 +304,13 @@ public class ShellyUtils {
|
|||||||
ZoneId zoneId = !zone.isEmpty() ? ZoneId.of(zone) : ZoneId.systemDefault();
|
ZoneId zoneId = !zone.isEmpty() ? ZoneId.of(zone) : ZoneId.systemDefault();
|
||||||
ZonedDateTime zdt = LocalDateTime.now().atZone(zoneId);
|
ZonedDateTime zdt = LocalDateTime.now().atZone(zoneId);
|
||||||
int delta = zdt.getOffset().getTotalSeconds();
|
int delta = zdt.getOffset().getTotalSeconds();
|
||||||
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp - delta), zoneId));
|
return new DateTimeType(Instant.ofEpochSecond(timestamp - delta));
|
||||||
} catch (DateTimeException e) {
|
} catch (DateTimeException e) {
|
||||||
// Unable to convert device's timezone, use system one
|
// Unable to convert device's timezone, use system one
|
||||||
return getTimestamp();
|
return getTimestamp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTimestamp(DateTimeType dt) {
|
|
||||||
return dt.getZonedDateTime().toString().replace('T', ' ').replace('-', '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String convertTimestamp(long ts) {
|
public static String convertTimestamp(long ts) {
|
||||||
if (ts == 0) {
|
if (ts == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
Loading…
Reference in New Issue
Block a user