mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Groupe PSA
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
000f8d7c6b
commit
3361aa41dd
@ -22,7 +22,6 @@ import org.eclipse.jetty.client.HttpClient;
|
|||||||
import org.openhab.binding.groupepsa.internal.bridge.GroupePSABridgeHandler;
|
import org.openhab.binding.groupepsa.internal.bridge.GroupePSABridgeHandler;
|
||||||
import org.openhab.binding.groupepsa.internal.things.GroupePSAHandler;
|
import org.openhab.binding.groupepsa.internal.things.GroupePSAHandler;
|
||||||
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
||||||
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;
|
||||||
@ -48,15 +47,12 @@ public class GroupePSAHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
|
|
||||||
private final OAuthFactory oAuthFactory;
|
private final OAuthFactory oAuthFactory;
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private final TimeZoneProvider timeZoneProvider;
|
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public GroupePSAHandlerFactory(final @Reference OAuthFactory oAuthFactory, //
|
public GroupePSAHandlerFactory(final @Reference OAuthFactory oAuthFactory, //
|
||||||
final @Reference HttpClientFactory httpClientFactory, //
|
final @Reference HttpClientFactory httpClientFactory) {
|
||||||
final @Reference TimeZoneProvider timeZoneProvider) {
|
|
||||||
this.oAuthFactory = oAuthFactory;
|
this.oAuthFactory = oAuthFactory;
|
||||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||||
this.timeZoneProvider = timeZoneProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +65,7 @@ public class GroupePSAHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
|
||||||
|
|
||||||
if (THING_TYPE_VEHICLE.equals(thingTypeUID)) {
|
if (THING_TYPE_VEHICLE.equals(thingTypeUID)) {
|
||||||
return new GroupePSAHandler(thing, timeZoneProvider);
|
return new GroupePSAHandler(thing);
|
||||||
} else if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
|
} else if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
|
||||||
return new GroupePSABridgeHandler((Bridge) thing, oAuthFactory, httpClient);
|
return new GroupePSABridgeHandler((Bridge) thing, oAuthFactory, httpClient);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ import org.openhab.binding.groupepsa.internal.rest.api.dto.Safety;
|
|||||||
import org.openhab.binding.groupepsa.internal.rest.api.dto.Service;
|
import org.openhab.binding.groupepsa.internal.rest.api.dto.Service;
|
||||||
import org.openhab.binding.groupepsa.internal.rest.api.dto.VehicleStatus;
|
import org.openhab.binding.groupepsa.internal.rest.api.dto.VehicleStatus;
|
||||||
import org.openhab.binding.groupepsa.internal.rest.exceptions.GroupePSACommunicationException;
|
import org.openhab.binding.groupepsa.internal.rest.exceptions.GroupePSACommunicationException;
|
||||||
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.OpenClosedType;
|
import org.openhab.core.library.types.OpenClosedType;
|
||||||
@ -93,8 +92,6 @@ public class GroupePSAHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(GroupePSAHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(GroupePSAHandler.class);
|
||||||
|
|
||||||
private final TimeZoneProvider timeZoneProvider;
|
|
||||||
|
|
||||||
private @Nullable String id = null;
|
private @Nullable String id = null;
|
||||||
private long lastQueryTimeNs = 0L;
|
private long lastQueryTimeNs = 0L;
|
||||||
|
|
||||||
@ -102,9 +99,8 @@ public class GroupePSAHandler extends BaseThingHandler {
|
|||||||
private long maxQueryFrequencyNanos = TimeUnit.MINUTES.toNanos(1);
|
private long maxQueryFrequencyNanos = TimeUnit.MINUTES.toNanos(1);
|
||||||
private long onlineIntervalM;
|
private long onlineIntervalM;
|
||||||
|
|
||||||
public GroupePSAHandler(Thing thing, TimeZoneProvider timeZoneProvider) {
|
public GroupePSAHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
this.timeZoneProvider = timeZoneProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -424,7 +420,7 @@ public class GroupePSAHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
protected void updateState(String channelID, @Nullable ZonedDateTime date) {
|
protected void updateState(String channelID, @Nullable ZonedDateTime date) {
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
updateState(channelID, new DateTimeType(date).toZone(timeZoneProvider.getTimeZone()));
|
updateState(channelID, new DateTimeType(date));
|
||||||
} else {
|
} else {
|
||||||
updateState(channelID, UnDefType.UNDEF);
|
updateState(channelID, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import static org.mockito.Mockito.*;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@ -35,7 +34,6 @@ import org.openhab.binding.groupepsa.internal.rest.api.GroupePSAConnectApi;
|
|||||||
import org.openhab.binding.groupepsa.internal.rest.exceptions.GroupePSACommunicationException;
|
import org.openhab.binding.groupepsa.internal.rest.exceptions.GroupePSACommunicationException;
|
||||||
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
||||||
import org.openhab.core.config.core.Configuration;
|
import org.openhab.core.config.core.Configuration;
|
||||||
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.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
import org.openhab.core.thing.Bridge;
|
import org.openhab.core.thing.Bridge;
|
||||||
@ -67,7 +65,6 @@ public class GroupePSAHandlerTest {
|
|||||||
|
|
||||||
private @NonNullByDefault({}) @Mock OAuthFactory oAuthFactory;
|
private @NonNullByDefault({}) @Mock OAuthFactory oAuthFactory;
|
||||||
private @NonNullByDefault({}) @Mock HttpClient httpClient;
|
private @NonNullByDefault({}) @Mock HttpClient httpClient;
|
||||||
private @NonNullByDefault({}) @Mock TimeZoneProvider timeZoneProvider;
|
|
||||||
|
|
||||||
static String getResourceFileAsString(String fileName) throws GroupePSACommunicationException {
|
static String getResourceFileAsString(String fileName) throws GroupePSACommunicationException {
|
||||||
try (InputStream is = GroupePSAConnectApi.class.getResourceAsStream(fileName)) {
|
try (InputStream is = GroupePSAConnectApi.class.getResourceAsStream(fileName)) {
|
||||||
@ -90,7 +87,7 @@ public class GroupePSAHandlerTest {
|
|||||||
|
|
||||||
// Create real objects
|
// Create real objects
|
||||||
bridgeHandler = spy(new GroupePSABridgeHandler(bridge, oAuthFactory, httpClient));
|
bridgeHandler = spy(new GroupePSABridgeHandler(bridge, oAuthFactory, httpClient));
|
||||||
thingHandler = spy(new GroupePSAHandler(thing, timeZoneProvider));
|
thingHandler = spy(new GroupePSAHandler(thing));
|
||||||
api = spy(new GroupePSAConnectApi(httpClient, bridgeHandler, "clientId", "realm"));
|
api = spy(new GroupePSAConnectApi(httpClient, bridgeHandler, "clientId", "realm"));
|
||||||
|
|
||||||
// Setup API mock
|
// Setup API mock
|
||||||
@ -124,7 +121,6 @@ public class GroupePSAHandlerTest {
|
|||||||
thingHandler.setCallback(thingCallback);
|
thingHandler.setCallback(thingCallback);
|
||||||
doReturn(bridge).when(thingHandler).getBridge();
|
doReturn(bridge).when(thingHandler).getBridge();
|
||||||
doNothing().when(thingHandler).buildDoorChannels(any());
|
doNothing().when(thingHandler).buildDoorChannels(any());
|
||||||
doReturn(ZoneId.systemDefault()).when(timeZoneProvider).getTimeZone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
|
Loading…
Reference in New Issue
Block a user