]> git.basschouten.com Git - openhab-addons.git/commitdiff
Migrate time channels from DateTime to Number:Time (#13841)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sat, 10 Dec 2022 22:05:59 +0000 (23:05 +0100)
committerGitHub <noreply@github.com>
Sat, 10 Dec 2022 22:05:59 +0000 (23:05 +0100)
Fixes #13840

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.miele/README.md
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/DishwasherChannelSelector.java
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/MieleApplianceHandler.java
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/OvenChannelSelector.java
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/TumbleDryerChannelSelector.java
bundles/org.openhab.binding.miele/src/main/java/org/openhab/binding/miele/internal/handler/WashingMachineChannelSelector.java
bundles/org.openhab.binding.miele/src/main/resources/OH-INF/thing/channeltypes.xml

index d87b25ccabdbb404b4a79c6003289af48654c8f7..767fbaa7d5a054a340e11d939c5d6d7201d14ac5 100644 (file)
@@ -126,9 +126,9 @@ Channels available for each appliance type are listed below.
 | rawPhase            | Number               | Read       | Current phase of the program running on the appliance as raw number |
 | start               | DateTime             | Read       | Programmed start time of the program                                |
 | end                 | DateTime             | Read       | End time of the program (programmed or running)                     |
-| duration            | DateTime             | Read       | Duration of the program running on the appliance                    |
-| elapsed             | DateTime             | Read       | Time elapsed in the program running on the appliance                |
-| finish              | DateTime             | Read       | Time to finish the program running on the appliance                 |
+| duration            | Number:Time          | Read       | Duration of the program running on the appliance                    |
+| elapsed             | Number:Time          | Read       | Time elapsed in the program running on the appliance                |
+| finish              | Number:Time          | Read       | Time to finish the program running on the appliance                 |
 | door                | Contact              | Read       | Current state of the door of the appliance                          |
 | switch              | Switch               | Write      | Switch the appliance on or off                                      |
 | powerConsumption    | Number:Power         | Read       | Power consumption by the currently running program on the appliance |
@@ -239,9 +239,9 @@ Channels available for each appliance type are listed below.
 | rawPhase            | Number               | Read       | Current phase of the program running on the appliance as raw number |
 | start               | DateTime             | Read       | Programmed start time of the program                                |
 | end                 | DateTime             | Read       | End time of the program (programmed or running)                     |
-| duration            | DateTime             | Read       | Duration of the program running on the appliance                    |
-| elapsed             | DateTime             | Read       | Time elapsed in the program running on the appliance                |
-| finish              | DateTime             | Read       | Time to finish the program running on the appliance                 |
+| duration            | Number:Time          | Read       | Duration of the program running on the appliance                    |
+| elapsed             | Number:Time          | Read       | Time elapsed in the program running on the appliance                |
+| finish              | Number:Time          | Read       | Time to finish the program running on the appliance                 |
 | target              | Number:Temperature   | Read       | Target temperature to be reached by the oven                        |
 | measured            | Number:Temperature   | Read       | Actual measured temperature in the oven                             |
 | temp1               | Number:Temperature   | Read       | Program temperature in the oven 1                                   |
@@ -282,9 +282,9 @@ See oven.
 | rawPhase            | Number               | Read       | Current phase of the program running on the appliance as raw number |
 | start               | DateTime             | Read       | Programmed start time of the program                                |
 | end                 | DateTime             | Read       | End time of the program (programmed or running)                     |
-| duration            | DateTime             | Read       | Duration of the program running on the appliance                    |
-| elapsed             | DateTime             | Read       | Time elapsed in the program running on the appliance                |
-| finish              | DateTime             | Read       | Time to finish the program running on the appliance                 |
+| duration            | Number:Time          | Read       | Duration of the program running on the appliance                    |
+| elapsed             | Number:Time          | Read       | Time elapsed in the program running on the appliance                |
+| finish              | Number:Time          | Read       | Time to finish the program running on the appliance                 |
 | door                | Contact              | Read       | Current state of the door of the appliance                          |
 | switch              | Switch               | Write      | Switch the appliance on or off                                      |
 | step                | Number               | Read       | Current step in the program running on the appliance                |
@@ -347,9 +347,9 @@ See oven.
 | rawPhase            | Number               | Read       | Current phase of the program running on the appliance as raw number |
 | start               | DateTime             | Read       | Programmed start time of the program                                |
 | end                 | DateTime             | Read       | End time of the program (programmed or running)                     |
-| duration            | DateTime             | Read       | Duration of the program running on the appliance                    |
-| elapsed             | DateTime             | Read       | Time elapsed in the program running on the appliance                |
-| finish              | DateTime             | Read       | Time to finish the program running on the appliance                 |
+| duration            | Number:Time          | Read       | Duration of the program running on the appliance                    |
+| elapsed             | Number:Time          | Read       | Time elapsed in the program running on the appliance                |
+| finish              | Number:Time          | Read       | Time to finish the program running on the appliance                 |
 | door                | Contact              | Read       | Current state of the door of the appliance                          |
 | switch              | Switch               | Write      | Switch the appliance on or off                                      |
 | target              | Number:Temperature   | Read       | Temperature of the selected program (10 °C = cold)                  |
index 78e132ecbb8ebd07aa9276400f09819f3fdc674f..20c19a5782604b2a0de79a29357e7dbba173650c 100644 (file)
@@ -16,10 +16,7 @@ import static java.util.Map.entry;
 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
 
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -32,6 +29,7 @@ import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.types.State;
 import org.openhab.core.types.Type;
 import org.openhab.core.types.UnDefType;
@@ -75,35 +73,27 @@ public enum DishwasherChannelSelector implements ApplianceChannelSelector {
     PROGRAM_PHASE(RAW_PHASE_PROPERTY_NAME, PHASE_CHANNEL_ID, DecimalType.class, false, false),
     START_TIME("", START_CHANNEL_ID, DateTimeType.class, false, false),
     END_TIME("", END_CHANNEL_ID, DateTimeType.class, false, false),
-    DURATION("duration", "duration", DateTimeType.class, false, false) {
+    DURATION("duration", "duration", QuantityType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    ELAPSED_TIME("elapsedTime", "elapsed", DateTimeType.class, false, false) {
+    ELAPSED_TIME("elapsedTime", "elapsed", QuantityType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    FINISH_TIME("", FINISH_CHANNEL_ID, DateTimeType.class, false, false),
+    FINISH_TIME("", FINISH_CHANNEL_ID, QuantityType.class, false, false),
     DOOR("signalDoor", "door", OpenClosedType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
index daaba7146744ebc51e0ab878973553459dc6c6a7..9979231b746d3684468c04c18ab264f46a4b6be6 100644 (file)
@@ -15,7 +15,6 @@ package org.openhab.binding.miele.internal.handler;
 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
 
 import java.time.Instant;
-import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.HashMap;
@@ -38,6 +37,8 @@ import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.i18n.TranslationProvider;
 import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.QuantityType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
@@ -335,9 +336,7 @@ public abstract class MieleApplianceHandler<E extends Enum<E> & ApplianceChannel
         try {
             long minutesFromNow = Long.valueOf(value);
             if (minutesFromNow > 0) {
-                ZonedDateTime remaining = ZonedDateTime.ofInstant(Instant.ofEpochSecond(minutesFromNow * 60),
-                        ZoneId.of("UTC"));
-                updateState(channelUid, new DateTimeType(remaining.withZoneSameLocal(timeZoneProvider.getTimeZone())));
+                updateState(channelUid, new QuantityType<>(minutesFromNow, Units.MINUTE));
                 return;
             }
         } catch (NumberFormatException e) {
index 998df2e9a8f30b8ae3e6ec222f8913ec275f84bb..ca4506e6306715ea6b44d669c80a0b18557495ed 100644 (file)
@@ -16,10 +16,7 @@ import static java.util.Map.entry;
 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
 
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -32,6 +29,7 @@ import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.types.State;
 import org.openhab.core.types.Type;
 import org.openhab.core.types.UnDefType;
@@ -70,35 +68,27 @@ public enum OvenChannelSelector implements ApplianceChannelSelector {
     PROGRAM_PHASE(RAW_PHASE_PROPERTY_NAME, PHASE_CHANNEL_ID, DecimalType.class, false),
     START_TIME("", START_CHANNEL_ID, DateTimeType.class, false),
     END_TIME("", END_CHANNEL_ID, DateTimeType.class, false),
-    DURATION("duration", "duration", DateTimeType.class, false) {
+    DURATION("duration", "duration", QuantityType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    ELAPSED_TIME("elapsedTime", "elapsed", DateTimeType.class, false) {
+    ELAPSED_TIME("elapsedTime", "elapsed", QuantityType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    FINISH_TIME("", FINISH_CHANNEL_ID, DateTimeType.class, false),
+    FINISH_TIME("", FINISH_CHANNEL_ID, QuantityType.class, false),
     TARGET_TEMP("targetTemperature", "target", QuantityType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
index e762fd181eb181fce8c7211b925994ca091637c2..7e924c4df5adaf0dd44c558d455bc372b2185bc9 100644 (file)
@@ -16,10 +16,7 @@ import static java.util.Map.entry;
 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
 
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -30,7 +27,9 @@ import org.openhab.core.library.types.DateTimeType;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.OpenClosedType;
+import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.types.State;
 import org.openhab.core.types.Type;
 import org.openhab.core.types.UnDefType;
@@ -75,35 +74,27 @@ public enum TumbleDryerChannelSelector implements ApplianceChannelSelector {
     PROGRAM_PHASE(RAW_PHASE_PROPERTY_NAME, PHASE_CHANNEL_ID, DecimalType.class, false),
     START_TIME("", START_CHANNEL_ID, DateTimeType.class, false),
     END_TIME("", END_CHANNEL_ID, DateTimeType.class, false),
-    DURATION("duration", "duration", DateTimeType.class, false) {
+    DURATION("duration", "duration", QuantityType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    ELAPSED_TIME("elapsedTime", "elapsed", DateTimeType.class, false) {
+    ELAPSED_TIME("elapsedTime", "elapsed", QuantityType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    FINISH_TIME("", FINISH_CHANNEL_ID, DateTimeType.class, false),
+    FINISH_TIME("", FINISH_CHANNEL_ID, QuantityType.class, false),
     DRYING_STEP("dryingStep", "step", DecimalType.class, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
index 44eecd47a8dcc10400b74a1c8a2a11eeb87c1084..38c679eb96df59f392d6f14cda02899776c95681 100644 (file)
@@ -16,10 +16,7 @@ import static java.util.Map.entry;
 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
 
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.Map;
-import java.util.TimeZone;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -32,6 +29,7 @@ import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.library.types.OpenClosedType;
 import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
+import org.openhab.core.library.unit.Units;
 import org.openhab.core.types.State;
 import org.openhab.core.types.Type;
 import org.openhab.core.types.UnDefType;
@@ -76,35 +74,27 @@ public enum WashingMachineChannelSelector implements ApplianceChannelSelector {
     PROGRAM_PHASE(RAW_PHASE_PROPERTY_NAME, PHASE_CHANNEL_ID, DecimalType.class, false, false),
     START_TIME("", START_CHANNEL_ID, DateTimeType.class, false, false),
     END_TIME("", END_CHANNEL_ID, DateTimeType.class, false, false),
-    DURATION("duration", "duration", DateTimeType.class, false, false) {
+    DURATION("duration", "duration", QuantityType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s.trim()) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    ELAPSED_TIME("elapsedTime", "elapsed", DateTimeType.class, false, false) {
+    ELAPSED_TIME("elapsedTime", "elapsed", QuantityType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
-            Date date = new Date();
-            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-            dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
             try {
-                date.setTime(Long.valueOf(s) * 60000);
-            } catch (Exception e) {
-                date.setTime(0);
+                return new QuantityType<>(Long.valueOf(s), Units.MINUTE);
+            } catch (NumberFormatException e) {
+                return UnDefType.UNDEF;
             }
-            return getState(dateFormatter.format(date));
         }
     },
-    FINISH_TIME("", FINISH_CHANNEL_ID, DateTimeType.class, false, false),
+    FINISH_TIME("", FINISH_CHANNEL_ID, QuantityType.class, false, false),
     TARGET_TEMP("targetTemperature", "target", QuantityType.class, false, false) {
         @Override
         public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
index 5f7c683ae58cdbfc4e6e5ef6dc903793f94498be..4d13057abdff2d4c4a27d170e2e854b0441cbb4f 100644 (file)
        </channel-type>
 
        <channel-type id="duration">
-               <item-type>DateTime</item-type>
+               <item-type>Number:Time</item-type>
                <label>Duration</label>
                <description>Duration of the program running on the appliance</description>
                <category>Time</category>
-               <state readOnly="true" pattern="%1$tH:%1$tM"></state>
+               <state readOnly="true" pattern="%1$tR"></state>
        </channel-type>
 
        <channel-type id="elapsed">
-               <item-type>DateTime</item-type>
+               <item-type>Number:Time</item-type>
                <label>Elapsed Time</label>
                <description>Time elapsed in the program running on the appliance</description>
                <category>Time</category>
-               <state readOnly="true" pattern="%1$tH:%1$tM"></state>
+               <state readOnly="true" pattern="%1$tR"></state>
        </channel-type>
 
        <channel-type id="finish">
-               <item-type>DateTime</item-type>
+               <item-type>Number:Time</item-type>
                <label>Finish Time</label>
                <description>Time to finish the program running on the appliance</description>
                <category>Time</category>
-               <state readOnly="true" pattern="%1$tH:%1$tM"></state>
+               <state readOnly="true" pattern="%1$tR"></state>
        </channel-type>
 
        <channel-type id="door">