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

Simplify DateTimeType handling #17725

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
10686b0
Simplify DateTimeType handling for Automower
jlaur Nov 9, 2024
ad21f63
Simplify DateTimeType handling for aWATTar
jlaur Nov 11, 2024
4293ee8
Simplify DateTimeType handling for Broadlink
jlaur Nov 16, 2024
7a22449
Simplify DateTimeType handling for deCONZ
jlaur Nov 9, 2024
4a49239
Simplify DateTimeType handling for DWD Unwetter
jlaur Nov 14, 2024
9d993ca
Simplify DateTimeType handling for Ecovacs
jlaur Nov 10, 2024
b419715
Simplify DateTimeType handling for EVCC
jlaur Nov 19, 2024
65a2804
Simplify DateTimeType handling for Exec
jlaur Nov 25, 2024
271a490
Simplify DateTimeType handling for Fine Offset Weather Station
jlaur Nov 17, 2024
500254c
Simplify DateTimeType handling for Flume
jlaur Nov 9, 2024
c8387db
Simplify DateTimeType handling for FMI Weather
jlaur Nov 25, 2024
766c524
Simplify DateTimeType handling for FreeboxOS
jlaur Nov 25, 2024
ffca3d3
Simplify DateTimeType handling for Groupe PSA
jlaur Nov 9, 2024
836a279
Simplify DateTimeType handling for Helios easyControls
jlaur Nov 17, 2024
18d26a8
Simplify DateTimeType handling for Hydrawise
jlaur Nov 17, 2024
52ea57a
Simplify DateTimeType handling for IHC
jlaur Nov 9, 2024
995f91f
Simplify DateTimeType handling for Insteon
jlaur Nov 15, 2024
6578483
Simplify DateTimeType handling for JuiceNet
jlaur Nov 9, 2024
736c868
Simplify DateTimeType handling for KM200
jlaur Nov 17, 2024
7f6db7f
Simplify DateTimeType handling for LaMetric
jlaur Nov 17, 2024
98b9d65
Simplify DateTimeType handling for Lutron
jlaur Nov 17, 2024
5d50659
Simplify DateTimeType handling for Meater
jlaur Nov 25, 2024
2e9d974
Simplify DateTimeType handling for Mercedes Me
jlaur Nov 19, 2024
83c08c1
Simplify DateTimeType handling for Met Office DataHub
jlaur Nov 25, 2024
7d99eae
Simplify DateTimeType handling for Mi IO
jlaur Nov 9, 2024
8460955
Simplify DateTimeType handling for Millheat
jlaur Nov 15, 2024
7238685
Simplify DateTimeType handling for MQTT
jlaur Nov 19, 2024
3f7deba
Simplify DateTimeType handling for Ruuvi Gateway MQTT
jlaur Nov 24, 2024
229a86b
Simplify DateTimeType handling for Network
jlaur Nov 9, 2024
ce6240d
Simplify DateTimeType handling for Nest
jlaur Nov 16, 2024
9927cd9
Simplify DateTimeType handling for OJElectronics
jlaur Nov 17, 2024
4b18179
Simplify DateTimeType handling for OpenUV
jlaur Nov 18, 2024
db8457a
Simplify DateTimeType handling for PLCLogo
jlaur Nov 18, 2024
d09dc06
Simplify DateTimeType handling for Robonect
jlaur Nov 18, 2024
733ff9e
Simplify DateTimeType handling for SAICiSMART
jlaur Nov 9, 2024
016818b
Simplify DateTimeType handling for Satel Integra Alarm System
jlaur Nov 18, 2024
fa744ee
Simplify DateTimeType handling for Shelly
jlaur Nov 15, 2024
3eac74c
Simplify DateTimeType handling for Siemens HVAC
jlaur Nov 10, 2024
40b240d
Simplify DateTimeType handling for Solax
jlaur Nov 24, 2024
2864e74
Simplify DateTimeType handling for Philips Somneo
jlaur Nov 19, 2024
4789935
Simplify DateTimeType handling for TA C.M.I.
jlaur Nov 18, 2024
633284e
Simplify DateTimeType handling for Tado
jlaur Nov 9, 2024
5f6dc54
Simplify DateTimeType handling for Teleinfo
jlaur Nov 18, 2024
18df34a
Simplify DateTimeType handling for Vallox MV
jlaur Nov 9, 2024
23bd292
Simplify DateTimeType handling for VeSync
jlaur Nov 25, 2024
a8316e7
Simplify DateTimeType handling for Video Disk Recorder
jlaur Nov 10, 2024
16cbadc
Simplify DateTimeType handling for WeMo
jlaur Nov 9, 2024
8caaa1b
Simplify DateTimeType handling for Amazon DynamoDB
jlaur Nov 9, 2024
b66c442
Simplify DateTimeType handling for InfluxDB
jlaur Nov 9, 2024
a98e401
Simplify DateTimeType handling for Java Persistence API
jlaur Nov 18, 2024
b9fbcd9
Simplify DateTimeType handling for JDBC
jlaur Nov 14, 2024
fdf7df0
Simplify DateTimeType handling for MongoDB
jlaur Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.openhab.binding.automower.internal.things.AutomowerHandler;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -56,14 +55,12 @@ public class AutomowerHandlerFactory extends BaseThingHandlerFactory {
private final OAuthFactory oAuthFactory;
protected final @NonNullByDefault({}) HttpClient httpClient;
private @Nullable ServiceRegistration<?> automowerDiscoveryServiceRegistration;
private final TimeZoneProvider timeZoneProvider;

@Activate
public AutomowerHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory,
@Reference TimeZoneProvider timeZoneProvider) {
public AutomowerHandlerFactory(@Reference OAuthFactory oAuthFactory,
@Reference HttpClientFactory httpClientFactory) {
this.oAuthFactory = oAuthFactory;
this.httpClient = httpClientFactory.getCommonHttpClient();
this.timeZoneProvider = timeZoneProvider;
}

@Override
Expand All @@ -80,7 +77,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
}

if (AutomowerHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new AutomowerHandler(thing, timeZoneProvider);
return new AutomowerHandler(thing);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.openhab.binding.automower.internal.AutomowerBindingConstants.*;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
Expand All @@ -36,7 +35,6 @@
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.RestrictedReason;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.State;
import org.openhab.binding.automower.internal.rest.exceptions.AutomowerCommunicationException;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.PointType;
Expand Down Expand Up @@ -76,7 +74,6 @@
private static final long DEFAULT_POLLING_INTERVAL_S = TimeUnit.MINUTES.toSeconds(10);

private final Logger logger = LoggerFactory.getLogger(AutomowerHandler.class);
private final TimeZoneProvider timeZoneProvider;

private AtomicReference<String> automowerId = new AtomicReference<>(NO_ID);
private long lastQueryTimeMs = 0L;
Expand All @@ -97,9 +94,8 @@
}
};

public AutomowerHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
public AutomowerHandler(Thing thing) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
}

@Override
Expand Down Expand Up @@ -287,7 +283,7 @@
}

updateState(CHANNEL_STATUS_LAST_UPDATE,
new DateTimeType(toZonedDateTime(mower.getAttributes().getMetadata().getStatusTimestamp())));
new DateTimeType(Instant.ofEpochMilli(mower.getAttributes().getMetadata().getStatusTimestamp())));

Check failure on line 286 in bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java

View workflow job for this annotation

GitHub Actions / Build (Java 17, ubuntu-24.04)

The constructor org.openhab.core.library.types.DateTimeType(java.time.Instant) is undefined
updateState(CHANNEL_STATUS_BATTERY,
new QuantityType<>(mower.getAttributes().getBattery().getBatteryPercent(), Units.PERCENT));

Expand All @@ -297,15 +293,15 @@
if (errorCodeTimestamp == 0L) {
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, UnDefType.NULL);
} else {
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, new DateTimeType(toZonedDateTime(errorCodeTimestamp)));
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, new DateTimeType(Instant.ofEpochMilli(errorCodeTimestamp)));

Check failure on line 296 in bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java

View workflow job for this annotation

GitHub Actions / Build (Java 17, ubuntu-24.04)

The constructor org.openhab.core.library.types.DateTimeType(java.time.Instant) is undefined
}

long nextStartTimestamp = mower.getAttributes().getPlanner().getNextStartTimestamp();
// If next start timestamp is 0 it means the mower should start now, so using current timestamp
if (nextStartTimestamp == 0L) {
updateState(CHANNEL_PLANNER_NEXT_START, UnDefType.NULL);
} else {
updateState(CHANNEL_PLANNER_NEXT_START, new DateTimeType(toZonedDateTime(nextStartTimestamp)));
updateState(CHANNEL_PLANNER_NEXT_START, new DateTimeType(Instant.ofEpochMilli(nextStartTimestamp)));

Check failure on line 304 in bundles/org.openhab.binding.automower/src/main/java/org/openhab/binding/automower/internal/things/AutomowerHandler.java

View workflow job for this annotation

GitHub Actions / Build (Java 17, ubuntu-24.04)

The constructor org.openhab.core.library.types.DateTimeType(java.time.Instant) is undefined
}
updateState(CHANNEL_PLANNER_OVERRIDE_ACTION,
new StringType(mower.getAttributes().getPlanner().getOverride().getAction()));
Expand Down Expand Up @@ -339,18 +335,4 @@

updateProperties(properties);
}

/**
* Converts timestamp returned by the Automower API into local time-zone.
* Timestamp returned by the API doesn't have offset and it always in the current time zone - it can be treated as
* UTC.
* Method builds a ZonedDateTime with same hour value but in the current system timezone.
*
* @param timestamp - Automower API timestamp
* @return ZonedDateTime in system timezone
*/
private ZonedDateTime toZonedDateTime(long timestamp) {
Instant timestampInstant = Instant.ofEpochMilli(timestamp);
return ZonedDateTime.ofInstant(timestampInstant, timeZoneProvider.getTimeZone());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;

Expand All @@ -47,10 +46,6 @@ public static ZonedDateTime getCalendarForHour(int hour, ZoneId zone) {
return ZonedDateTime.now(zone).truncatedTo(ChronoUnit.DAYS).plusHours(hour);
}

public static DateTimeType getDateTimeType(long time, TimeZoneProvider tz) {
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), tz.getTimeZone()));
}

public static QuantityType<Time> getDuration(long millis) {
long minutes = millis / 60000;
return QuantityType.valueOf(minutes, Units.MINUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_REMAINING;
import static org.openhab.binding.awattar.internal.AwattarBindingConstants.CHANNEL_START;
import static org.openhab.binding.awattar.internal.AwattarUtil.getCalendarForHour;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDateTimeType;
import static org.openhab.binding.awattar.internal.AwattarUtil.getDuration;
import static org.openhab.binding.awattar.internal.AwattarUtil.getMillisToNextMinute;

Expand All @@ -43,6 +42,7 @@
import org.openhab.binding.awattar.internal.AwattarNonConsecutiveBestPriceResult;
import org.openhab.binding.awattar.internal.AwattarPrice;
import org.openhab.core.i18n.TimeZoneProvider;
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.types.StringType;
Expand Down Expand Up @@ -188,10 +188,10 @@ public void refreshChannel(ChannelUID channelUID) {
state = OnOffType.from(result.isActive());
break;
case CHANNEL_START:
state = getDateTimeType(result.getStart(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getStart()));
break;
case CHANNEL_END:
state = getDateTimeType(result.getEnd(), timeZoneProvider);
state = new DateTimeType(Instant.ofEpochMilli(result.getEnd()));
break;
case CHANNEL_COUNTDOWN:
diff = result.getStart() - Instant.now().toEpochMilli();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -212,7 +213,7 @@ private void handleRemoteLockCommand(ChannelUID channelUID, Command command) {

private void handleSetTimeCommand(ChannelUID channelUID, Command command) {
if (command instanceof DateTimeType dateTimeCommand) {
ZonedDateTime zonedDateTime = dateTimeCommand.getZonedDateTime();
ZonedDateTime zonedDateTime = dateTimeCommand.getInstant().atZone(ZoneId.systemDefault());
try {
new SetTimeCommand(tob(zonedDateTime.getHour()), tob(zonedDateTime.getMinute()),
tob(zonedDateTime.getSecond()), tob(zonedDateTime.getDayOfWeek().getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -119,10 +118,9 @@ public static <T> T getObjectFromJson(String filename, Class<T> clazz, Gson gson
@Test
public void dateTimeConversionTest() {
DateTimeType dateTime = Util.convertTimestampToDateTime("2020-08-22T11:09Z");
assertEquals(new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:00Z")), dateTime);
assertEquals(new DateTimeType(Instant.parse("2020-08-22T11:09:00Z")), dateTime);

dateTime = Util.convertTimestampToDateTime("2020-08-22T11:09:47");
assertEquals(new DateTimeType(ZonedDateTime.parse("2020-08-22T11:09:47Z")).toZone(ZoneId.systemDefault()),
dateTime);
assertEquals(new DateTimeType(Instant.parse("2020-08-22T11:09:47Z")), dateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -105,31 +104,22 @@ public void testGetCeiling() {

@Test
public void testGetExpires() {
// Conversion is needed as getExpires returns the Date with the System Default Zone
assertThat(((DateTimeType) warningsData.getExpires(0)).getZonedDateTime().withZoneSameInstant(ZoneId.of("UTC"))
.toString(), is("2018-12-22T18:00Z[UTC]"));
assertThat(((DateTimeType) warningsData.getExpires(1)).getZonedDateTime().withZoneSameInstant(ZoneId.of("UTC"))
.toString(), is("2018-12-23T01:00Z[UTC]"));
assertThat(((DateTimeType) warningsData.getExpires(0)).getInstant().toString(), is("2018-12-22T18:00:00Z"));
assertThat(((DateTimeType) warningsData.getExpires(1)).getInstant().toString(), is("2018-12-23T01:00:00Z"));
assertThat(warningsData.getExpires(2), is(UnDefType.UNDEF));
}

@Test
public void testGetOnset() {
// Conversion is needed as getOnset returns the Date with the System Default Zone
assertThat(((DateTimeType) warningsData.getOnset(0)).getZonedDateTime().withZoneSameInstant(ZoneId.of("UTC"))
.toString(), is("2018-12-21T10:00Z[UTC]"));
assertThat(((DateTimeType) warningsData.getOnset(1)).getZonedDateTime().withZoneSameInstant(ZoneId.of("UTC"))
.toString(), is("2018-12-22T18:00Z[UTC]"));
assertThat(((DateTimeType) warningsData.getOnset(0)).getInstant().toString(), is("2018-12-21T10:00:00Z"));
assertThat(((DateTimeType) warningsData.getOnset(1)).getInstant().toString(), is("2018-12-22T18:00:00Z"));
assertThat(warningsData.getOnset(2), is(UnDefType.UNDEF));
}

@Test
public void testGetEffective() {
// Conversion is needed as getEffective returns the Date with the System Default Zone
assertThat(((DateTimeType) warningsData.getEffective(0)).getZonedDateTime()
.withZoneSameInstant(ZoneId.of("UTC")).toString(), is("2018-12-22T03:02Z[UTC]"));
assertThat(((DateTimeType) warningsData.getEffective(1)).getZonedDateTime()
.withZoneSameInstant(ZoneId.of("UTC")).toString(), is("2018-12-22T10:15Z[UTC]"));
assertThat(((DateTimeType) warningsData.getEffective(0)).getInstant().toString(), is("2018-12-22T03:02:00Z"));
assertThat(((DateTimeType) warningsData.getEffective(1)).getInstant().toString(), is("2018-12-22T10:15:00Z"));
assertThat(warningsData.getEffective(2), is(UnDefType.UNDEF));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.openhab.binding.ecovacs.internal.EcovacsBindingConstants.*;

import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -584,8 +583,7 @@ private void pollData() {
if (!cleanLogRecords.isEmpty()) {
CleanLogRecord record = cleanLogRecords.get(0);

updateState(CHANNEL_ID_LAST_CLEAN_START,
new DateTimeType(record.timestamp.toInstant().atZone(ZoneId.systemDefault())));
updateState(CHANNEL_ID_LAST_CLEAN_START, new DateTimeType(record.timestamp.toInstant()));
updateState(CHANNEL_ID_LAST_CLEAN_DURATION, new QuantityType<>(record.cleaningDuration, Units.SECOND));
updateState(CHANNEL_ID_LAST_CLEAN_AREA, new QuantityType<>(record.cleanedArea, SIUnits.SQUARE_METRE));
if (device.hasCapability(DeviceCapability.EXTENDED_CLEAN_LOG_RECORD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

import static org.openhab.binding.evcc.internal.EvccBindingConstants.*;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -79,7 +81,7 @@ public class EvccHandler extends BaseThingHandler {
private Set<String> vehicleFeatureHeating = new HashSet<String>();
private Set<String> loadpointFeatureHeating = new HashSet<String>();

Map<String, Triple<Boolean, Float, ZonedDateTime>> vehiclePlans = new HashMap<>();
Map<String, Triple<Boolean, Float, Instant>> vehiclePlans = new HashMap<>();

public EvccHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
super(thing);
Expand Down Expand Up @@ -284,7 +286,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_VEHICLE_PLAN_ENABLED, CHANNEL_HEATING_PLAN_ENABLED -> {
Triple<Boolean, Float, ZonedDateTime> planValues = vehiclePlans.get(vehicleName);
Triple<Boolean, Float, Instant> planValues = vehiclePlans.get(vehicleName);
if (command == OnOffType.ON) {
evccAPI.setVehiclePlan(vehicleName, planValues.getMiddle().intValue(),
planValues.getRight());
Expand All @@ -299,7 +301,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_VEHICLE_PLAN_SOC -> {
Triple<Boolean, Float, ZonedDateTime> planValues = vehiclePlans.get(vehicleName);
Triple<Boolean, Float, Instant> planValues = vehiclePlans.get(vehicleName);
if (command instanceof QuantityType<?> qt) {
vehiclePlans.put(vehicleName, new Triple<>(planValues.getLeft(),
qt.toUnit(Units.PERCENT).floatValue(), planValues.getRight()));
Expand All @@ -318,7 +320,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_HEATING_PLAN_TEMPERATURE -> {
Triple<Boolean, Float, ZonedDateTime> planValues = vehiclePlans.get(vehicleName);
Triple<Boolean, Float, Instant> planValues = vehiclePlans.get(vehicleName);
if (command instanceof QuantityType<?> qt) {
vehiclePlans.put(vehicleName, new Triple<>(planValues.getLeft(),
qt.toUnit(SIUnits.CELSIUS).floatValue(), planValues.getRight()));
Expand All @@ -337,14 +339,14 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_VEHICLE_PLAN_TIME, CHANNEL_HEATING_PLAN_TIME -> {
Triple<Boolean, Float, ZonedDateTime> planValues = vehiclePlans.get(vehicleName);
Triple<Boolean, Float, Instant> planValues = vehiclePlans.get(vehicleName);
if (command instanceof DateTimeType dtt) {
vehiclePlans.put(vehicleName, new Triple<>(planValues.getLeft(), planValues.getMiddle(),
dtt.getZonedDateTime()));
vehiclePlans.put(vehicleName,
new Triple<>(planValues.getLeft(), planValues.getMiddle(), dtt.getInstant()));
if (planValues.getLeft()) {
try {
evccAPI.setVehiclePlan(vehicleName, planValues.getMiddle().intValue(),
dtt.getZonedDateTime());
dtt.getInstant());
} catch (DateTimeParseException e) {
logger.debug("Failed to set vehicle plan time: ", e);
}
Expand Down Expand Up @@ -967,15 +969,16 @@ private void updateChannelsVehicle(String vehicleName, @Nullable String loadpoin
plan = vehicle.getPlan();
}
if (plan == null && vehiclePlans.get(vehicleName) == null) {
vehiclePlans.put(vehicleName, new Triple<>(false, 100f, ZonedDateTime.now().plusHours(12)));
vehiclePlans.put(vehicleName, new Triple<>(false, 100f, Instant.now().plus(12, ChronoUnit.HOURS)));
} else if (plan != null) {
vehiclePlans.put(vehicleName, new Triple<>(true, plan.getSoC(), ZonedDateTime.parse(plan.getTime())));
vehiclePlans.put(vehicleName,
new Triple<>(true, plan.getSoC(), ZonedDateTime.parse(plan.getTime()).toInstant()));
}
updateVehiclePlanChannel(uid, vehicleName, channelGroup, isHeating);
}

private void updateVehiclePlanChannel(ThingUID uid, String vehicleName, String channelGroup, boolean isHeating) {
Triple<Boolean, Float, ZonedDateTime> planValues = vehiclePlans.get(vehicleName);
Triple<Boolean, Float, Instant> planValues = vehiclePlans.get(vehicleName);

if (isHeating) {
ChannelUID channel = new ChannelUID(uid, channelGroup, CHANNEL_HEATING_PLAN_ENABLED);
Expand Down
Loading
Loading