Skip to content

Commit

Permalink
[freebox] Consider TimeZoneProvider to get the timezone (openhab#7879)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
  • Loading branch information
lolodomo authored and DaanMeijer committed Sep 1, 2020
1 parent 15e95ba commit 3acb9f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.smarthome.core.audio.AudioHTTPServer;
import org.eclipse.smarthome.core.audio.AudioSink;
import org.eclipse.smarthome.core.i18n.TimeZoneProvider;
import org.eclipse.smarthome.core.net.HttpServiceUtil;
import org.eclipse.smarthome.core.net.NetworkAddressService;
import org.eclipse.smarthome.core.thing.Bridge;
Expand Down Expand Up @@ -70,15 +71,18 @@ public class FreeboxHandlerFactory extends BaseThingHandlerFactory {

private final AudioHTTPServer audioHTTPServer;
private final NetworkAddressService networkAddressService;
private final TimeZoneProvider timeZoneProvider;

// url (scheme+server+port) to use for playing notification sounds
private @Nullable String callbackUrl;

@Activate
public FreeboxHandlerFactory(final @Reference AudioHTTPServer audioHTTPServer,
final @Reference NetworkAddressService networkAddressService) {
final @Reference NetworkAddressService networkAddressService,
final @Reference TimeZoneProvider timeZoneProvider) {
this.audioHTTPServer = audioHTTPServer;
this.networkAddressService = networkAddressService;
this.timeZoneProvider = timeZoneProvider;
}

@Override
Expand Down Expand Up @@ -120,7 +124,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
registerDiscoveryService(handler);
return handler;
} else if (FreeboxBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
FreeboxThingHandler handler = new FreeboxThingHandler(thing);
FreeboxThingHandler handler = new FreeboxThingHandler(thing, timeZoneProvider.getTimeZone());
if (FreeboxBindingConstants.FREEBOX_THING_TYPE_AIRPLAY.equals(thingTypeUID)) {
registerAudioSink(handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import static org.openhab.binding.freebox.internal.FreeboxBindingConstants.*;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -62,6 +62,7 @@ public class FreeboxThingHandler extends BaseThingHandler {

private final Logger logger = LoggerFactory.getLogger(FreeboxThingHandler.class);

private final ZoneId zoneId;
private ScheduledFuture<?> phoneJob;
private ScheduledFuture<?> callsJob;
private FreeboxHandler bridgeHandler;
Expand All @@ -70,8 +71,9 @@ public class FreeboxThingHandler extends BaseThingHandler {
private String airPlayName;
private String airPlayPassword;

public FreeboxThingHandler(Thing thing) {
public FreeboxThingHandler(Thing thing, ZoneId zoneId) {
super(thing);
this.zoneId = zoneId;
}

@Override
Expand Down Expand Up @@ -260,7 +262,7 @@ private void updateCall(FreeboxCallEntry call, String channelGroup) {
updateGroupChannelStringState(channelGroup, CALLNUMBER, call.getNumber());
updateGroupChannelDecimalState(channelGroup, CALLDURATION, call.getDuration());
ZonedDateTime zoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(call.getTimeStamp().getTimeInMillis()),
TimeZone.getDefault().toZoneId());
zoneId);
updateGroupChannelDateTimeState(channelGroup, CALLTIMESTAMP, zoned);
updateGroupChannelStringState(channelGroup, CALLNAME, call.getName());
if (channelGroup.equals(ANY)) {
Expand Down

0 comments on commit 3acb9f3

Please sign in to comment.