mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for ZoneMinder
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
aae1224658
commit
6007d6bc51
@ -19,7 +19,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.openhab.binding.zoneminder.internal.handler.ZmBridgeHandler;
|
import org.openhab.binding.zoneminder.internal.handler.ZmBridgeHandler;
|
||||||
import org.openhab.binding.zoneminder.internal.handler.ZmMonitorHandler;
|
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.io.net.http.HttpClientFactory;
|
||||||
import org.openhab.core.thing.Bridge;
|
import org.openhab.core.thing.Bridge;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
@ -40,16 +39,13 @@ import org.osgi.service.component.annotations.Reference;
|
|||||||
@Component(configurationPid = "binding.zoneminder", service = ThingHandlerFactory.class)
|
@Component(configurationPid = "binding.zoneminder", service = ThingHandlerFactory.class)
|
||||||
public class ZmHandlerFactory extends BaseThingHandlerFactory {
|
public class ZmHandlerFactory extends BaseThingHandlerFactory {
|
||||||
|
|
||||||
private final TimeZoneProvider timeZoneProvider;
|
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final ZmStateDescriptionOptionsProvider stateDescriptionProvider;
|
private final ZmStateDescriptionOptionsProvider stateDescriptionProvider;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public ZmHandlerFactory(@Reference TimeZoneProvider timeZoneProvider,
|
public ZmHandlerFactory(@Reference HttpClientFactory httpClientFactory,
|
||||||
@Reference HttpClientFactory httpClientFactory,
|
|
||||||
@Reference ZmStateDescriptionOptionsProvider stateDescriptionProvider) {
|
@Reference ZmStateDescriptionOptionsProvider stateDescriptionProvider) {
|
||||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||||
this.timeZoneProvider = timeZoneProvider;
|
|
||||||
this.stateDescriptionProvider = stateDescriptionProvider;
|
this.stateDescriptionProvider = stateDescriptionProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +60,7 @@ public class ZmHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
if (SUPPORTED_SERVER_THING_TYPES_UIDS.contains(thingTypeUID)) {
|
if (SUPPORTED_SERVER_THING_TYPES_UIDS.contains(thingTypeUID)) {
|
||||||
return new ZmBridgeHandler((Bridge) thing, httpClient, stateDescriptionProvider);
|
return new ZmBridgeHandler((Bridge) thing, httpClient, stateDescriptionProvider);
|
||||||
} else if (SUPPORTED_MONITOR_THING_TYPES_UIDS.contains(thingTypeUID)) {
|
} else if (SUPPORTED_MONITOR_THING_TYPES_UIDS.contains(thingTypeUID)) {
|
||||||
return new ZmMonitorHandler(thing, timeZoneProvider);
|
return new ZmMonitorHandler(thing);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ package org.openhab.binding.zoneminder.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.zoneminder.internal.ZmBindingConstants.*;
|
import static org.openhab.binding.zoneminder.internal.ZmBindingConstants.*;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -26,7 +25,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.zoneminder.internal.action.ZmActions;
|
import org.openhab.binding.zoneminder.internal.action.ZmActions;
|
||||||
import org.openhab.binding.zoneminder.internal.config.ZmMonitorConfig;
|
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.DateTimeType;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
import org.openhab.core.library.types.DecimalType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
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 Logger logger = LoggerFactory.getLogger(ZmMonitorHandler.class);
|
||||||
|
|
||||||
private final TimeZoneProvider timeZoneProvider;
|
|
||||||
|
|
||||||
private @Nullable ZmBridgeHandler bridgeHandler;
|
private @Nullable ZmBridgeHandler bridgeHandler;
|
||||||
|
|
||||||
private @NonNullByDefault({}) String monitorId;
|
private @NonNullByDefault({}) String monitorId;
|
||||||
@ -70,9 +66,8 @@ public class ZmMonitorHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
private final Map<String, State> monitorStatusCache = new ConcurrentHashMap<>();
|
private final Map<String, State> monitorStatusCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public ZmMonitorHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
|
public ZmMonitorHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
this.timeZoneProvider = timeZoneProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -209,10 +204,8 @@ public class ZmMonitorHandler extends BaseThingHandler {
|
|||||||
updateChannelState(CHANNEL_EVENT_NAME, new StringType(event.getName()));
|
updateChannelState(CHANNEL_EVENT_NAME, new StringType(event.getName()));
|
||||||
updateChannelState(CHANNEL_EVENT_CAUSE, new StringType(event.getCause()));
|
updateChannelState(CHANNEL_EVENT_CAUSE, new StringType(event.getCause()));
|
||||||
updateChannelState(CHANNEL_EVENT_NOTES, new StringType(event.getNotes()));
|
updateChannelState(CHANNEL_EVENT_NOTES, new StringType(event.getNotes()));
|
||||||
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(
|
updateChannelState(CHANNEL_EVENT_START, new DateTimeType(event.getStart().toInstant()));
|
||||||
ZonedDateTime.ofInstant(event.getStart().toInstant(), timeZoneProvider.getTimeZone())));
|
updateChannelState(CHANNEL_EVENT_END, new DateTimeType(event.getEnd().toInstant()));
|
||||||
updateChannelState(CHANNEL_EVENT_END,
|
|
||||||
new DateTimeType(ZonedDateTime.ofInstant(event.getEnd().toInstant(), timeZoneProvider.getTimeZone())));
|
|
||||||
updateChannelState(CHANNEL_EVENT_FRAMES, new DecimalType(event.getFrames()));
|
updateChannelState(CHANNEL_EVENT_FRAMES, new DecimalType(event.getFrames()));
|
||||||
updateChannelState(CHANNEL_EVENT_ALARM_FRAMES, new DecimalType(event.getAlarmFrames()));
|
updateChannelState(CHANNEL_EVENT_ALARM_FRAMES, new DecimalType(event.getAlarmFrames()));
|
||||||
updateChannelState(CHANNEL_EVENT_LENGTH, new QuantityType<>(event.getLength(), Units.SECOND));
|
updateChannelState(CHANNEL_EVENT_LENGTH, new QuantityType<>(event.getLength(), Units.SECOND));
|
||||||
|
Loading…
Reference in New Issue
Block a user