]> git.basschouten.com Git - openhab-addons.git/blob
cf878804bf1868ec4534efc402c28475a0c41732
[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.anthem.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.types.State;
17
18 /**
19  * The {@link AnthemUpdate} class represents the result of parsing the response from
20  * an Anthem processor.
21  *
22  * @author Mark Hilbush - Initial contribution
23  */
24 @NonNullByDefault
25 public class AnthemUpdate {
26     private Object updateObject;
27
28     public AnthemUpdate(StateUpdate stateUpdate) {
29         this.updateObject = stateUpdate;
30     }
31
32     public AnthemUpdate(PropertyUpdate propertyUpdate) {
33         this.updateObject = propertyUpdate;
34     }
35
36     public static AnthemUpdate createStateUpdate(String groupId, String channelId, State state) {
37         return new AnthemUpdate(new StateUpdate(groupId, channelId, state));
38     }
39
40     public static AnthemUpdate createPropertyUpdate(String name, String value) {
41         return new AnthemUpdate(new PropertyUpdate(name, value));
42     }
43
44     public boolean isStateUpdate() {
45         return updateObject instanceof StateUpdate;
46     }
47
48     public boolean isPropertyUpdate() {
49         return updateObject instanceof PropertyUpdate;
50     }
51
52     public StateUpdate getStateUpdate() {
53         if (updateObject instanceof StateUpdate stateUpdate) {
54             return stateUpdate;
55         }
56         throw new IllegalStateException("Update object is not a state update");
57     }
58
59     public PropertyUpdate getPropertyUpdate() {
60         if (updateObject instanceof PropertyUpdate propertyUpdate) {
61             return propertyUpdate;
62         }
63         throw new IllegalStateException("Update object is not a property update");
64     }
65 }