mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[awattar] comply to naming convertion, simplify calc, fix typo
Signed-off-by: Thomas Leber <thomas@tl-photography.at>
This commit is contained in:
parent
11f60da2d6
commit
a5a7e7c3c9
@ -224,7 +224,7 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
|
|||||||
* @return the range
|
* @return the range
|
||||||
*/
|
*/
|
||||||
protected TimeRange getRange(int start, int duration, ZoneId zoneId) {
|
protected TimeRange getRange(int start, int duration, ZoneId zoneId) {
|
||||||
ZonedDateTime startTime = getStarTime(start, zoneId);
|
ZonedDateTime startTime = getStartTime(start, zoneId);
|
||||||
ZonedDateTime endTime = startTime.plusHours(duration);
|
ZonedDateTime endTime = startTime.plusHours(duration);
|
||||||
ZonedDateTime now = getNow(zoneId);
|
ZonedDateTime now = getNow(zoneId);
|
||||||
if (now.getHour() < start) {
|
if (now.getHour() < start) {
|
||||||
@ -232,7 +232,7 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
|
|||||||
startTime = startTime.minusDays(1);
|
startTime = startTime.minusDays(1);
|
||||||
endTime = endTime.minusDays(1);
|
endTime = endTime.minusDays(1);
|
||||||
}
|
}
|
||||||
if (endTime.toInstant().toEpochMilli() < now.toInstant().toEpochMilli()) {
|
if (endTime.isBefore(now)) {
|
||||||
// span is in the past, add one day
|
// span is in the past, add one day
|
||||||
startTime = startTime.plusDays(1);
|
startTime = startTime.plusDays(1);
|
||||||
endTime = endTime.plusDays(1);
|
endTime = endTime.plusDays(1);
|
||||||
@ -247,7 +247,7 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
|
|||||||
* @param zoneId the time zone
|
* @param zoneId the time zone
|
||||||
* @return the start time
|
* @return the start time
|
||||||
*/
|
*/
|
||||||
protected ZonedDateTime getStarTime(int start, ZoneId zoneId) {
|
protected ZonedDateTime getStartTime(int start, ZoneId zoneId) {
|
||||||
return getCalendarForHour(start, zoneId);
|
return getCalendarForHour(start, zoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class AwattarBridgeHandlerRefreshTest extends JavaTest {
|
|||||||
* @throws AwattarApiException
|
* @throws AwattarApiException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testRefreshIfNeeded_ThingOffline() throws SecurityException, AwattarApiException {
|
void testRefreshIfNeededThingOffline() throws SecurityException, AwattarApiException {
|
||||||
when(bridgeMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
when(bridgeMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
||||||
|
|
||||||
bridgeHandler.refreshIfNeeded();
|
bridgeHandler.refreshIfNeeded();
|
||||||
@ -113,7 +113,7 @@ class AwattarBridgeHandlerRefreshTest extends JavaTest {
|
|||||||
* @throws AwattarApiException
|
* @throws AwattarApiException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testRefreshIfNeeded_DataEmpty() throws SecurityException, AwattarApiException {
|
void testRefreshIfNeededDataEmpty() throws SecurityException, AwattarApiException {
|
||||||
when(bridgeMock.getStatus()).thenReturn(ThingStatus.ONLINE);
|
when(bridgeMock.getStatus()).thenReturn(ThingStatus.ONLINE);
|
||||||
|
|
||||||
bridgeHandler.refreshIfNeeded();
|
bridgeHandler.refreshIfNeeded();
|
||||||
@ -124,7 +124,7 @@ class AwattarBridgeHandlerRefreshTest extends JavaTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNeedRefresh_ThingOffline() throws SecurityException {
|
void testNeedRefreshThingOffline() throws SecurityException {
|
||||||
when(bridgeMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
when(bridgeMock.getStatus()).thenReturn(ThingStatus.OFFLINE);
|
||||||
|
|
||||||
// get private method via reflection
|
// get private method via reflection
|
||||||
@ -136,7 +136,7 @@ class AwattarBridgeHandlerRefreshTest extends JavaTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNeedRefresh_DataEmpty() throws SecurityException, IllegalArgumentException, IllegalAccessException {
|
void testNeedRefreshDataEmpty() throws SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||||
when(bridgeMock.getStatus()).thenReturn(ThingStatus.ONLINE);
|
when(bridgeMock.getStatus()).thenReturn(ThingStatus.ONLINE);
|
||||||
|
|
||||||
List<Field> fields = ReflectionSupport.findFields(AwattarBridgeHandler.class,
|
List<Field> fields = ReflectionSupport.findFields(AwattarBridgeHandler.class,
|
||||||
|
@ -202,7 +202,7 @@ public class AwattarBridgeHandlerTest extends JavaTest {
|
|||||||
when(bestpriceMock.getConfiguration()).thenReturn(new Configuration(config));
|
when(bestpriceMock.getConfiguration()).thenReturn(new Configuration(config));
|
||||||
|
|
||||||
AwattarBestPriceHandler handler = new AwattarBestPriceHandler(bestpriceMock, timeZoneProviderMock) {
|
AwattarBestPriceHandler handler = new AwattarBestPriceHandler(bestpriceMock, timeZoneProviderMock) {
|
||||||
protected ZonedDateTime getStarTime(int start, ZoneId zoneId) {
|
protected ZonedDateTime getStartTime(int start, ZoneId zoneId) {
|
||||||
return ZonedDateTime.of(2024, 6, 15, 12, 0, 0, 0, zoneId);
|
return ZonedDateTime.of(2024, 6, 15, 12, 0, 0, 0, zoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ public class AwattarBridgeHandlerTest extends JavaTest {
|
|||||||
verify(bestPriceCallbackMock).stateUpdated(channelUID, expectedState);
|
verify(bestPriceCallbackMock).stateUpdated(channelUID, expectedState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream<Arguments> testBestpriceHandler_channels() {
|
public static Stream<Arguments> testBestpriceHandlerChannels() {
|
||||||
return Stream.of( //
|
return Stream.of( //
|
||||||
Arguments.of(12, 0, 24, 1, true, CHANNEL_HOURS, new StringType("14")),
|
Arguments.of(12, 0, 24, 1, true, CHANNEL_HOURS, new StringType("14")),
|
||||||
Arguments.of(12, 0, 24, 1, true, CHANNEL_ACTIVE, OnOffType.from(false)),
|
Arguments.of(12, 0, 24, 1, true, CHANNEL_ACTIVE, OnOffType.from(false)),
|
||||||
@ -250,7 +250,7 @@ public class AwattarBridgeHandlerTest extends JavaTest {
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource
|
@MethodSource
|
||||||
void testBestpriceHandler_channels(int currentHour, int currentMinute, int rangeDuration, int length,
|
void testBestpriceHandlerChannels(int currentHour, int currentMinute, int rangeDuration, int length,
|
||||||
boolean consecutive, String channelId, State expectedState) {
|
boolean consecutive, String channelId, State expectedState) {
|
||||||
ThingUID bestPriceUid = new ThingUID(AwattarBindingConstants.THING_TYPE_BESTPRICE, "foo");
|
ThingUID bestPriceUid = new ThingUID(AwattarBindingConstants.THING_TYPE_BESTPRICE, "foo");
|
||||||
Map<String, Object> config = Map.of("rangeDuration", rangeDuration, "length", length, "consecutive",
|
Map<String, Object> config = Map.of("rangeDuration", rangeDuration, "length", length, "consecutive",
|
||||||
@ -258,7 +258,7 @@ public class AwattarBridgeHandlerTest extends JavaTest {
|
|||||||
when(bestpriceMock.getConfiguration()).thenReturn(new Configuration(config));
|
when(bestpriceMock.getConfiguration()).thenReturn(new Configuration(config));
|
||||||
|
|
||||||
AwattarBestPriceHandler handler = new AwattarBestPriceHandler(bestpriceMock, timeZoneProviderMock) {
|
AwattarBestPriceHandler handler = new AwattarBestPriceHandler(bestpriceMock, timeZoneProviderMock) {
|
||||||
protected ZonedDateTime getStarTime(int start, ZoneId zoneId) {
|
protected ZonedDateTime getStartTime(int start, ZoneId zoneId) {
|
||||||
return ZonedDateTime.of(2024, 6, 15, 0, 0, 0, 0, zoneId);
|
return ZonedDateTime.of(2024, 6, 15, 0, 0, 0, 0, zoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user