From 31e7d6193cc16c03759a18b83935e2bb845f964f Mon Sep 17 00:00:00 2001 From: Markus Michels Date: Mon, 30 Dec 2019 20:06:09 +0100 Subject: [PATCH] Shelly EM #18: Compensate missing timestamp/lastUpdate with system timestamp (like for sensors) Signed-off-by: Markus Michels --- .../openhab/binding/shelly/internal/api/ShellyApiJsonDTO.java | 1 - .../binding/shelly/internal/coap/ShellyCoapHandler.java | 3 +++ .../binding/shelly/internal/handler/ShellyComponents.java | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiJsonDTO.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiJsonDTO.java index b4d47b33bce9f..3d8f4a3c52607 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiJsonDTO.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyApiJsonDTO.java @@ -310,7 +310,6 @@ public static class ShellySettingsEMeter { // ShellyEM meter public Double total; // Total consumed energy, Wh @SerializedName("total_returned") public Double totalReturned; // Total returned energy, Wh - public Long timestamp; } public static class ShellySettingsUpdate { diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java index c5d6cfbb8edd3..ff0d875353624 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/coap/ShellyCoapHandler.java @@ -389,6 +389,9 @@ private void handleStatusUpdate(String devId, String payload, int serial) throws String mGroup = profile.numMeters == 1 ? CHANNEL_GROUP_METER : CHANNEL_GROUP_METER + rIndex; updateChannel(updates, mGroup, CHANNEL_METER_CURRENTWATTS, toQuantityType(s.value, DIGITS_WATT, SmartHomeUnits.WATT)); + if (profile.isEMeter) { + updateChannel(updates, mGroup, CHANNEL_LAST_UPDATE, getTimestamp()); + } break; case "o": // Overtemp // will be handled by status update diff --git a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java index 08916ea5c57a1..ac201dc0bed61 100644 --- a/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java +++ b/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyComponents.java @@ -111,8 +111,7 @@ public static boolean updateMeters(ShellyBaseHandler th, ShellySettingsStatus st updated |= th.updateChannel(groupName, CHANNEL_EMETER_VOLTAGE, toQuantityType(getDouble(emeter.voltage), DIGITS_VOLT, SmartHomeUnits.VOLT)); if (updated) { - th.updateChannel(groupName, CHANNEL_LAST_UPDATE, - getTimestamp(getString(profile.settings.timezone), getLong(emeter.timestamp))); + th.updateChannel(groupName, CHANNEL_LAST_UPDATE, getTimestamp()); } m++; }