Simplify DateTimeType handling for ZoneMinder

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-11-27 23:11:45 +01:00 committed by Ciprian Pascu
parent 10bf67525e
commit 3609ecdce6
2 changed files with 5 additions and 16 deletions

View File

@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.binding.zoneminder.internal.handler.ZmBridgeHandler;
import org.openhab.binding.zoneminder.internal.handler.ZmMonitorHandler;
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;
@ -40,16 +39,13 @@ import org.osgi.service.component.annotations.Reference;
@Component(configurationPid = "binding.zoneminder", service = ThingHandlerFactory.class)
public class ZmHandlerFactory extends BaseThingHandlerFactory {
private final TimeZoneProvider timeZoneProvider;
private final HttpClient httpClient;
private final ZmStateDescriptionOptionsProvider stateDescriptionProvider;
@Activate
public ZmHandlerFactory(@Reference TimeZoneProvider timeZoneProvider,
@Reference HttpClientFactory httpClientFactory,
public ZmHandlerFactory(@Reference HttpClientFactory httpClientFactory,
@Reference ZmStateDescriptionOptionsProvider stateDescriptionProvider) {
this.httpClient = httpClientFactory.getCommonHttpClient();
this.timeZoneProvider = timeZoneProvider;
this.stateDescriptionProvider = stateDescriptionProvider;
}
@ -64,7 +60,7 @@ public class ZmHandlerFactory extends BaseThingHandlerFactory {
if (SUPPORTED_SERVER_THING_TYPES_UIDS.contains(thingTypeUID)) {
return new ZmBridgeHandler((Bridge) thing, httpClient, stateDescriptionProvider);
} else if (SUPPORTED_MONITOR_THING_TYPES_UIDS.contains(thingTypeUID)) {
return new ZmMonitorHandler(thing, timeZoneProvider);
return new ZmMonitorHandler(thing);
}
return null;
}

View File

@ -14,7 +14,6 @@ package org.openhab.binding.zoneminder.internal.handler;
import static org.openhab.binding.zoneminder.internal.ZmBindingConstants.*;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@ -26,7 +25,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.zoneminder.internal.action.ZmActions;
import org.openhab.binding.zoneminder.internal.config.ZmMonitorConfig;
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.OnOffType;
@ -57,8 +55,6 @@ public class ZmMonitorHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(ZmMonitorHandler.class);
private final TimeZoneProvider timeZoneProvider;
private @Nullable ZmBridgeHandler bridgeHandler;
private @NonNullByDefault({}) String monitorId;
@ -70,9 +66,8 @@ public class ZmMonitorHandler extends BaseThingHandler {
private final Map<String, State> monitorStatusCache = new ConcurrentHashMap<>();
public ZmMonitorHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
public ZmMonitorHandler(Thing thing) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
}
@Override
@ -209,10 +204,8 @@ public class ZmMonitorHandler extends BaseThingHandler {
updateChannelState(CHANNEL_EVENT_NAME, new StringType(event.getName()));
updateChannelState(CHANNEL_EVENT_CAUSE, new StringType(event.getCause()));
updateChannelState(CHANNEL_EVENT_NOTES, new StringType(event.getNotes()));
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(
ZonedDateTime.ofInstant(event.getStart().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_END,
new DateTimeType(ZonedDateTime.ofInstant(event.getEnd().toInstant(), timeZoneProvider.getTimeZone())));
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(event.getStart().toInstant()));
updateChannelState(CHANNEL_EVENT_END, new DateTimeType(event.getEnd().toInstant()));
updateChannelState(CHANNEL_EVENT_FRAMES, new DecimalType(event.getFrames()));
updateChannelState(CHANNEL_EVENT_ALARM_FRAMES, new DecimalType(event.getAlarmFrames()));
updateChannelState(CHANNEL_EVENT_LENGTH, new QuantityType<>(event.getLength(), Units.SECOND));