Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[miele] Migrate time channels from DateTime to Number:Time #13841

Merged
merged 1 commit into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions bundles/org.openhab.binding.miele/README.md
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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) |
Expand Down
Expand Up @@ -16,10 +16,7 @@
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;
Expand All @@ -32,6 +29,7 @@
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;
Expand Down Expand Up @@ -75,35 +73,27 @@ public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationPr
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) {
Expand Down
Expand Up @@ -15,7 +15,6 @@
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;
Expand All @@ -38,6 +37,8 @@
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;
Expand Down Expand Up @@ -335,9 +336,7 @@ private void updateDurationState(ChannelUID channelUid, String value) {
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) {
Expand Down
Expand Up @@ -16,10 +16,7 @@
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;
Expand All @@ -32,6 +29,7 @@
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;
Expand Down Expand Up @@ -70,35 +68,27 @@ public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationPr
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) {
Expand Down
Expand Up @@ -16,10 +16,7 @@
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;
Expand All @@ -30,7 +27,9 @@
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;
Expand Down Expand Up @@ -75,35 +74,27 @@ public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationPr
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) {
Expand Down
Expand Up @@ -16,10 +16,7 @@
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;
Expand All @@ -32,6 +29,7 @@
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;
Expand Down Expand Up @@ -76,35 +74,27 @@ public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationPr
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) {
Expand Down