Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[freebox] Consider TimeZoneProvider to get the timezone #7879

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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