]> git.basschouten.com Git - openhab-addons.git/blob
6e81aba225d5749ddb338bbd1c6812b6f4f9d201
[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.hdpowerview.internal.dto;
14
15 import java.time.DayOfWeek;
16 import java.util.EnumSet;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * State of a single Scheduled Event, as returned by an HD PowerView Hub
23  *
24  * @author Jacob Laursen - Initial contribution
25  */
26 @NonNullByDefault
27 public class ScheduledEvent {
28     public static final EnumSet<DayOfWeek> WEEKDAYS = EnumSet.of(DayOfWeek.MONDAY, DayOfWeek.TUESDAY,
29             DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY);
30
31     public static final EnumSet<DayOfWeek> WEEKENDS = EnumSet.of(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY);
32
33     public static final int SCHEDULED_EVENT_TYPE_TIME = 0;
34     public static final int SCHEDULED_EVENT_TYPE_SUNRISE = 1;
35     public static final int SCHEDULED_EVENT_TYPE_SUNSET = 2;
36
37     public int id;
38     public boolean enabled;
39     public int sceneId;
40     public int sceneCollectionId;
41     public boolean daySunday;
42     public boolean dayMonday;
43     public boolean dayTuesday;
44     public boolean dayWednesday;
45     public boolean dayThursday;
46     public boolean dayFriday;
47     public boolean daySaturday;
48     public int eventType;
49     public int hour;
50     public int minute;
51
52     @Override
53     public boolean equals(@Nullable Object o) {
54         if (o == this) {
55             return true;
56         }
57         if (!(o instanceof ScheduledEvent)) {
58             return false;
59         }
60         ScheduledEvent other = (ScheduledEvent) o;
61
62         return this.id == other.id && this.enabled == other.enabled && this.sceneId == other.sceneId
63                 && this.sceneCollectionId == other.sceneCollectionId && this.daySunday == other.daySunday
64                 && this.dayMonday == other.dayMonday && this.dayTuesday == other.dayTuesday
65                 && this.dayWednesday == other.dayWednesday && this.dayThursday == other.dayThursday
66                 && this.dayFriday == other.dayFriday && this.daySaturday == other.daySaturday
67                 && this.eventType == other.eventType && this.hour == other.hour && this.minute == other.minute;
68     }
69
70     @Override
71     public final int hashCode() {
72         final int prime = 31;
73         int result = 1;
74         result = prime * result + id;
75         result = prime * result + (enabled ? 1 : 0);
76         result = prime * result + sceneId;
77         result = prime * result + sceneCollectionId;
78         result = prime * result + (daySunday ? 1 : 0);
79         result = prime * result + (dayMonday ? 1 : 0);
80         result = prime * result + (dayTuesday ? 1 : 0);
81         result = prime * result + (dayWednesday ? 1 : 0);
82         result = prime * result + (dayThursday ? 1 : 0);
83         result = prime * result + (dayFriday ? 1 : 0);
84         result = prime * result + (daySaturday ? 1 : 0);
85         result = prime * result + eventType;
86         result = prime * result + hour;
87         result = prime * result + minute;
88
89         return result;
90     }
91
92     public EnumSet<DayOfWeek> getDays() {
93         EnumSet<DayOfWeek> days = EnumSet.noneOf(DayOfWeek.class);
94         if (daySunday) {
95             days.add(DayOfWeek.SUNDAY);
96         }
97         if (dayMonday) {
98             days.add(DayOfWeek.MONDAY);
99         }
100         if (dayTuesday) {
101             days.add(DayOfWeek.TUESDAY);
102         }
103         if (dayWednesday) {
104             days.add(DayOfWeek.WEDNESDAY);
105         }
106         if (dayThursday) {
107             days.add(DayOfWeek.THURSDAY);
108         }
109         if (dayFriday) {
110             days.add(DayOfWeek.FRIDAY);
111         }
112         if (daySaturday) {
113             days.add(DayOfWeek.SATURDAY);
114         }
115         return days;
116     }
117 }