2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nobohub.internal.model;
15 import java.time.LocalDateTime;
16 import java.time.Month;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.Test;
23 * Unit tests for WeekProfile model object.
25 * @author Jørgen Austvik - Initial contribution
28 public class WeekProfileTest {
30 private static final LocalDateTime MONDAY = LocalDateTime.of(2020, Month.MAY, 11, 0, 0);
31 private static final LocalDateTime WEDNESDAY = LocalDateTime.of(2020, Month.MAY, 13, 0, 0);
32 private static final LocalDateTime SUNDAY = LocalDateTime.of(2020, Month.MAY, 17, 23, 59);
35 public void testParseH03() throws NoboDataException {
36 WeekProfile weekProfile = WeekProfile.fromH03(
37 "H03 1 Default 00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,00000,07001,00000,07001,23000");
38 Assertions.assertEquals(1, weekProfile.getId());
39 Assertions.assertEquals("Default", weekProfile.getName());
43 public void testFindFirstStatus() throws NoboDataException {
44 WeekProfile weekProfile = WeekProfile.fromH03(
45 "H03 1 Default 00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,00000,07001,00000,07001,23000");
46 WeekProfileStatus status = weekProfile.getStatusAt(MONDAY);
47 Assertions.assertEquals(WeekProfileStatus.ECO, status);
51 public void testFindLastStatus() throws NoboDataException {
52 WeekProfile weekProfile = WeekProfile.fromH03(
53 "H03 1 Default 00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,00000,07001,00000,07001,23000");
54 WeekProfileStatus status = weekProfile.getStatusAt(SUNDAY);
55 Assertions.assertEquals(WeekProfileStatus.ECO, status);
59 public void testFindEmptyDayStatus() throws NoboDataException {
60 WeekProfile weekProfile = WeekProfile.fromH03("H03 1 Default 00000,00000,00001,00000,00000,00000,00000");
61 WeekProfileStatus status = weekProfile.getStatusAt(WEDNESDAY);
62 Assertions.assertEquals(WeekProfileStatus.COMFORT, status);
66 public void testFindOffDayStatus() throws NoboDataException {
67 WeekProfile weekProfile = WeekProfile.fromH03("H03 2 Off 00004,00003,00004,00004,00004,00004,00003");
68 WeekProfileStatus statusWen = weekProfile.getStatusAt(WEDNESDAY);
69 Assertions.assertEquals(WeekProfileStatus.OFF, statusWen);
70 WeekProfileStatus statusSat = weekProfile.getStatusAt(SUNDAY);
71 Assertions.assertEquals(WeekProfileStatus.OFF, statusSat);
75 public void testFindStartingNowStatus() throws NoboDataException {
76 WeekProfile weekProfile = WeekProfile.fromH03(
77 "H03 1 Default 00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,00000,07001,00000,07001,23000");
78 WeekProfileStatus status = weekProfile.getStatusAt(MONDAY.plusHours(6));
79 Assertions.assertEquals(WeekProfileStatus.COMFORT, status);
81 status = weekProfile.getStatusAt(MONDAY.plusHours(6).plusMinutes(1));
82 Assertions.assertEquals(WeekProfileStatus.COMFORT, status);
84 status = weekProfile.getStatusAt(MONDAY.plusHours(6).minusMinutes(1));
85 Assertions.assertEquals(WeekProfileStatus.ECO, status);
89 public void testFindNormalStatus() throws NoboDataException {
90 WeekProfile weekProfile = WeekProfile.fromH03(
91 "H03 1 Default 00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,23000,00000,06001,08000,15001,00000,07001,00000,07001,23000");
92 WeekProfileStatus status = weekProfile.getStatusAt(WEDNESDAY.plusHours(7).plusMinutes(13));
93 Assertions.assertEquals(WeekProfileStatus.COMFORT, status);