mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Lutron
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
665a4e752f
commit
6e90350c1f
@ -13,6 +13,7 @@
|
|||||||
package org.openhab.binding.lutron.internal.grxprg;
|
package org.openhab.binding.lutron.internal.grxprg;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
@ -165,8 +166,8 @@ public class PrgBridgeHandler extends BaseBridgeHandler {
|
|||||||
} else if (id.equals(PrgConstants.CHANNEL_ZONERAISESTOP)) {
|
} else if (id.equals(PrgConstants.CHANNEL_ZONERAISESTOP)) {
|
||||||
protocolHandler.setZoneRaiseStop();
|
protocolHandler.setZoneRaiseStop();
|
||||||
} else if (id.equals(PrgConstants.CHANNEL_TIMECLOCK)) {
|
} else if (id.equals(PrgConstants.CHANNEL_TIMECLOCK)) {
|
||||||
if (command instanceof DateTimeType dateTime) {
|
if (command instanceof DateTimeType dateTimeCommand) {
|
||||||
final ZonedDateTime zdt = dateTime.getZonedDateTime();
|
final ZonedDateTime zdt = dateTimeCommand.getZonedDateTime(ZoneId.systemDefault());
|
||||||
protocolHandler.setTime(GregorianCalendar.from(zdt));
|
protocolHandler.setTime(GregorianCalendar.from(zdt));
|
||||||
} else {
|
} else {
|
||||||
logger.error("Received a TIMECLOCK channel command with a non DateTimeType: {}", command);
|
logger.error("Received a TIMECLOCK channel command with a non DateTimeType: {}", command);
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
package org.openhab.binding.lutron.internal.grxprg;
|
package org.openhab.binding.lutron.internal.grxprg;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -885,8 +883,7 @@ class PrgProtocolHandler {
|
|||||||
final int yr = Integer.parseInt(m.group(5));
|
final int yr = Integer.parseInt(m.group(5));
|
||||||
c.set(Calendar.YEAR, yr + (yr < 50 ? 1900 : 2000));
|
c.set(Calendar.YEAR, yr + (yr < 50 ? 1900 : 2000));
|
||||||
|
|
||||||
phCallback.stateChanged(PrgConstants.CHANNEL_TIMECLOCK,
|
phCallback.stateChanged(PrgConstants.CHANNEL_TIMECLOCK, new DateTimeType(c.toInstant()));
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(c.toInstant(), ZoneId.systemDefault())));
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.error("Invalid time response (can't parse number): '{}'", resp);
|
logger.error("Invalid time response (can't parse number): '{}'", resp);
|
||||||
}
|
}
|
||||||
@ -936,14 +933,12 @@ class PrgProtocolHandler {
|
|||||||
final Calendar sunrise = Calendar.getInstance();
|
final Calendar sunrise = Calendar.getInstance();
|
||||||
sunrise.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(1)));
|
sunrise.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(1)));
|
||||||
sunrise.set(Calendar.MINUTE, Integer.parseInt(m.group(2)));
|
sunrise.set(Calendar.MINUTE, Integer.parseInt(m.group(2)));
|
||||||
phCallback.stateChanged(PrgConstants.CHANNEL_SUNRISE,
|
phCallback.stateChanged(PrgConstants.CHANNEL_SUNRISE, new DateTimeType(sunrise.toInstant()));
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(sunrise.toInstant(), ZoneId.systemDefault())));
|
|
||||||
|
|
||||||
final Calendar sunset = Calendar.getInstance();
|
final Calendar sunset = Calendar.getInstance();
|
||||||
sunset.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(3)));
|
sunset.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(3)));
|
||||||
sunset.set(Calendar.MINUTE, Integer.parseInt(m.group(4)));
|
sunset.set(Calendar.MINUTE, Integer.parseInt(m.group(4)));
|
||||||
phCallback.stateChanged(PrgConstants.CHANNEL_SUNSET,
|
phCallback.stateChanged(PrgConstants.CHANNEL_SUNSET, new DateTimeType(sunset.toInstant()));
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(sunset.toInstant(), ZoneId.systemDefault())));
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.error("Invalid sunrise/sunset response (can't parse number): '{}'", resp);
|
logger.error("Invalid sunrise/sunset response (can't parse number): '{}'", resp);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,6 @@ package org.openhab.binding.lutron.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.lutron.internal.LutronBindingConstants.*;
|
import static org.openhab.binding.lutron.internal.LutronBindingConstants.*;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@ -176,15 +174,13 @@ public class TimeclockHandler extends LutronHandler {
|
|||||||
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_SUNRISE.toString().equals(parameters[0])) {
|
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_SUNRISE.toString().equals(parameters[0])) {
|
||||||
Calendar calendar = parseLutronTime(parameters[1]);
|
Calendar calendar = parseLutronTime(parameters[1]);
|
||||||
if (calendar != null) {
|
if (calendar != null) {
|
||||||
updateState(CHANNEL_SUNRISE,
|
updateState(CHANNEL_SUNRISE, new DateTimeType(calendar.toInstant()));
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_SUNSET.toString().equals(parameters[0])) {
|
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_SUNSET.toString().equals(parameters[0])) {
|
||||||
Calendar calendar = parseLutronTime(parameters[1]);
|
Calendar calendar = parseLutronTime(parameters[1]);
|
||||||
if (calendar != null) {
|
if (calendar != null) {
|
||||||
updateState(CHANNEL_SUNSET,
|
updateState(CHANNEL_SUNSET, new DateTimeType(calendar.toInstant()));
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_EXECEVENT.toString().equals(parameters[0])) {
|
} else if (parameters.length >= 2 && TimeclockCommand.ACTION_EXECEVENT.toString().equals(parameters[0])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user