]> git.basschouten.com Git - openhab-addons.git/blob
e7ae6ac1ae440e1bc14d35d4c8aafe41f5461917
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.hdpowerview.internal.api.responses;
14
15 import java.time.DayOfWeek;
16 import java.util.EnumSet;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23  * State of all Scheduled Events in an HD PowerView hub
24  *
25  * @author Jacob Laursen - Initial contribution
26  */
27 @NonNullByDefault
28 public class ScheduledEvents {
29
30     public static final EnumSet<DayOfWeek> WEEKDAYS = EnumSet.of(DayOfWeek.MONDAY, DayOfWeek.TUESDAY,
31             DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY);
32
33     public static final EnumSet<DayOfWeek> WEEKENDS = EnumSet.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
34
35     public static final int SCHEDULED_EVENT_TYPE_TIME = 0;
36     public static final int SCHEDULED_EVENT_TYPE_SUNRISE = 1;
37     public static final int SCHEDULED_EVENT_TYPE_SUNSET = 2;
38
39     public @Nullable List<ScheduledEvent> scheduledEventData;
40     public @Nullable List<Integer> scheduledEventIds;
41
42     /*
43      * the following SuppressWarnings annotation is because the Eclipse compiler
44      * does NOT expect a NonNullByDefault annotation on the inner class, since it is
45      * implicitly inherited from the outer class, whereas the Maven compiler always
46      * requires an explicit NonNullByDefault annotation on all classes
47      */
48     @SuppressWarnings("null")
49     @NonNullByDefault
50     public static class ScheduledEvent {
51         public int id;
52         public boolean enabled;
53         public int sceneId;
54         public int sceneCollectionId;
55         public boolean daySunday;
56         public boolean dayMonday;
57         public boolean dayTuesday;
58         public boolean dayWednesday;
59         public boolean dayThursday;
60         public boolean dayFriday;
61         public boolean daySaturday;
62         public int eventType;
63         public int hour;
64         public int minute;
65
66         @Override
67         public boolean equals(@Nullable Object o) {
68             if (o == this) {
69                 return true;
70             }
71             if (!(o instanceof ScheduledEvent)) {
72                 return false;
73             }
74             ScheduledEvent other = (ScheduledEvent) o;
75
76             return this.id == other.id && this.enabled == other.enabled && this.sceneId == other.sceneId
77                     && this.sceneCollectionId == other.sceneCollectionId && this.daySunday == other.daySunday
78                     && this.dayMonday == other.dayMonday && this.dayTuesday == other.dayTuesday
79                     && this.dayWednesday == other.dayWednesday && this.dayThursday == other.dayThursday
80                     && this.dayFriday == other.dayFriday && this.daySaturday == other.daySaturday
81                     && this.eventType == other.eventType && this.hour == other.hour && this.minute == other.minute;
82         }
83
84         @Override
85         public final int hashCode() {
86             final int prime = 31;
87             int result = 1;
88             result = prime * result + id;
89             result = prime * result + (enabled ? 1 : 0);
90             result = prime * result + sceneId;
91             result = prime * result + sceneCollectionId;
92             result = prime * result + (daySunday ? 1 : 0);
93             result = prime * result + (dayMonday ? 1 : 0);
94             result = prime * result + (dayTuesday ? 1 : 0);
95             result = prime * result + (dayWednesday ? 1 : 0);
96             result = prime * result + (dayThursday ? 1 : 0);
97             result = prime * result + (dayFriday ? 1 : 0);
98             result = prime * result + (daySaturday ? 1 : 0);
99             result = prime * result + eventType;
100             result = prime * result + hour;
101             result = prime * result + minute;
102
103             return result;
104         }
105
106         public EnumSet<DayOfWeek> getDays() {
107             EnumSet<DayOfWeek> days = EnumSet.noneOf(DayOfWeek.class);
108             if (daySunday) {
109                 days.add(DayOfWeek.SUNDAY);
110             }
111             if (dayMonday) {
112                 days.add(DayOfWeek.MONDAY);
113             }
114             if (dayTuesday) {
115                 days.add(DayOfWeek.TUESDAY);
116             }
117             if (dayWednesday) {
118                 days.add(DayOfWeek.WEDNESDAY);
119             }
120             if (dayThursday) {
121                 days.add(DayOfWeek.THURSDAY);
122             }
123             if (dayFriday) {
124                 days.add(DayOfWeek.FRIDAY);
125             }
126             if (daySaturday) {
127                 days.add(DayOfWeek.SATURDAY);
128             }
129             return days;
130         }
131     }
132 }