]> git.basschouten.com Git - openhab-addons.git/blob
c187a118dc4ed3a4184ce27880700d204de84694
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nobohub.internal.model;
14
15 import java.time.LocalDateTime;
16 import java.time.Month;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.Test;
21
22 /**
23  * Unit tests for WeekProfile model object.
24  *
25  * @author Jørgen Austvik - Initial contribution
26  */
27 @NonNullByDefault
28 public class WeekProfileTest {
29
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);
33
34     @Test
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());
40     }
41
42     @Test
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);
48     }
49
50     @Test
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);
56     }
57
58     @Test
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);
63     }
64
65     @Test
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);
72     }
73
74     @Test
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);
80
81         status = weekProfile.getStatusAt(MONDAY.plusHours(6).plusMinutes(1));
82         Assertions.assertEquals(WeekProfileStatus.COMFORT, status);
83
84         status = weekProfile.getStatusAt(MONDAY.plusHours(6).minusMinutes(1));
85         Assertions.assertEquals(WeekProfileStatus.ECO, status);
86     }
87
88     @Test
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);
94     }
95 }