Skip to content

Commit

Permalink
Apply PR openhab#7879
Browse files Browse the repository at this point in the history
Signed-off-by: clinique <[email protected]>
  • Loading branch information
clinique committed Jun 9, 2020
1 parent 46fb7d3 commit 1a968ca
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.time.ZoneId;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class FreeboxHandlerFactory extends BaseThingHandlerFactory {

private final AudioHTTPServer audioHTTPServer;
private final NetworkAddressService networkAddressService;
private final TimeZoneProvider timeZoneProvider;
private final ZoneId zoneId;
private @Nullable String callbackUrl;
private final Map<ThingUID, ServiceRegistration<AudioSink>> audioSinkRegistrations = new ConcurrentHashMap<>();

Expand All @@ -72,7 +73,7 @@ public FreeboxHandlerFactory(final @Reference AudioHTTPServer audioHTTPServer,
super.activate(componentContext);
this.audioHTTPServer = audioHTTPServer;
this.networkAddressService = networkAddressService;
this.timeZoneProvider = timeZoneProvider;
this.zoneId = timeZoneProvider.getTimeZone();
setCallbackUrl(componentContext.getProperties().get(CALLBACK_URL));
}

Expand All @@ -95,18 +96,18 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
} else if (thingTypeUID.equals(FREEBOX_BRIDGE_TYPE_DELTA)) {
return new DeltaHandler((Bridge) thing);
} else if (thingTypeUID.equals(FREEBOX_THING_TYPE_PLAYER)) {
PlayerHandler handler = new PlayerHandler(thing, timeZoneProvider, audioHTTPServer, callbackUrl);
PlayerHandler handler = new PlayerHandler(thing, zoneId, audioHTTPServer, callbackUrl);
@SuppressWarnings("unchecked")
ServiceRegistration<AudioSink> reg = (ServiceRegistration<AudioSink>) bundleContext
.registerService(AudioSink.class.getName(), handler, new Hashtable<>());
audioSinkRegistrations.put(thing.getUID(), reg);
return handler;
} else if (thingTypeUID.equals(FREEBOX_THING_TYPE_HOST)) {
return new HostHandler(thing, timeZoneProvider);
return new HostHandler(thing, zoneId);
} else if (thingTypeUID.equals(FREEBOX_THING_TYPE_PHONE)) {
return new PhoneHandler(thing, timeZoneProvider);
return new PhoneHandler(thing, zoneId);
} else if (thingTypeUID.equals(FREEBOX_THING_TYPE_VM)) {
return new VirtualMachineHandler(thing, timeZoneProvider);
return new VirtualMachineHandler(thing, zoneId);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.freebox.internal.handler;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -23,7 +24,6 @@

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.DateTimeType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.QuantityType;
Expand Down Expand Up @@ -52,13 +52,13 @@
@NonNullByDefault
public abstract class APIConsumerHandler extends BaseThingHandler {
final Logger logger = LoggerFactory.getLogger(APIConsumerHandler.class);
private final TimeZoneProvider timeZoneProvider;
private final ZoneId zoneId;
private @NonNullByDefault({}) ScheduledFuture<?> globalJob;
protected @NonNullByDefault({}) ServerHandler bridgeHandler;

public APIConsumerHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
public APIConsumerHandler(Thing thing, ZoneId zoneId) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
this.zoneId = zoneId;
}

protected Map<String, String> discoverAttributes() throws FreeboxException {
Expand Down Expand Up @@ -168,7 +168,7 @@ protected void logCommandException(FreeboxException e, ChannelUID channelUID, Co

protected ZonedDateTime convertTimestamp(long timestamp) {
Instant i = Instant.ofEpochSecond(timestamp);
return ZonedDateTime.ofInstant(i, timeZoneProvider.getTimeZone());
return ZonedDateTime.ofInstant(i, zoneId);
}

protected void updateChannelDateTimeState(String group, String channel, long timestamp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.time.ZoneId;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.openhab.binding.freebox.internal.action.HostActions;
Expand All @@ -43,8 +43,8 @@ public class HostHandler extends APIConsumerHandler {
private @NonNullByDefault({}) HostConfiguration config;
protected String ipAddress = "";

public HostHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
super(thing, timeZoneProvider);
public HostHandler(Thing thing, ZoneId zoneId) {
super(thing, zoneId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.time.ZoneId;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.freebox.internal.api.APIRequests;
import org.openhab.binding.freebox.internal.api.FreeboxException;
import org.openhab.binding.freebox.internal.api.model.CallEntry;
import org.openhab.binding.freebox.internal.api.model.PhoneStatus;
import org.openhab.binding.freebox.internal.api.model.CallEntry.CallType;
import org.openhab.binding.freebox.internal.api.model.PhoneStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -46,8 +46,8 @@ public class PhoneHandler extends APIConsumerHandler {
private final Logger logger = LoggerFactory.getLogger(PhoneHandler.class);
private Long lastCallTimestamp;

public PhoneHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
super(thing, timeZoneProvider);
public PhoneHandler(Thing thing, ZoneId zoneId) {
super(thing, zoneId);
lastCallTimestamp = thing.getProperties().containsKey(LAST_CALL_TIMESTAMP)
? Long.parseLong(thing.getProperties().get(LAST_CALL_TIMESTAMP)) - 1
: 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.io.IOException;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -39,7 +40,6 @@
import org.eclipse.smarthome.core.audio.URLAudioStream;
import org.eclipse.smarthome.core.audio.UnsupportedAudioFormatException;
import org.eclipse.smarthome.core.audio.UnsupportedAudioStreamException;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.PercentType;
Expand Down Expand Up @@ -105,9 +105,8 @@ public class PlayerHandler extends HostHandler implements AudioSink {
private String baseAddress = "";
private @NonNullByDefault({}) PlayerConfiguration configuration;

public PlayerHandler(Thing thing, TimeZoneProvider timeZoneProvider, AudioHTTPServer audioHTTPServer,
@Nullable String callbackUrl) {
super(thing, timeZoneProvider);
public PlayerHandler(Thing thing, ZoneId zoneId, AudioHTTPServer audioHTTPServer, @Nullable String callbackUrl) {
super(thing, zoneId);
this.audioHTTPServer = audioHTTPServer;
this.callbackUrl = callbackUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.time.ZoneId;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
Expand All @@ -39,8 +40,8 @@ public class VirtualMachineHandler extends HostHandler {
private final Logger logger = LoggerFactory.getLogger(VirtualMachineHandler.class);
private @NonNullByDefault({}) String vmId;

public VirtualMachineHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
super(thing, timeZoneProvider);
public VirtualMachineHandler(Thing thing, ZoneId zoneId) {
super(thing, zoneId);
}

@Override
Expand Down

0 comments on commit 1a968ca

Please sign in to comment.