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.anthem.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.types.State;
19 * The {@link AnthemUpdate} class represents the result of parsing the response from
20 * an Anthem processor.
22 * @author Mark Hilbush - Initial contribution
25 public class AnthemUpdate {
26 private Object updateObject;
28 public AnthemUpdate(StateUpdate stateUpdate) {
29 this.updateObject = stateUpdate;
32 public AnthemUpdate(PropertyUpdate propertyUpdate) {
33 this.updateObject = propertyUpdate;
36 public static AnthemUpdate createStateUpdate(String groupId, String channelId, State state) {
37 return new AnthemUpdate(new StateUpdate(groupId, channelId, state));
40 public static AnthemUpdate createPropertyUpdate(String name, String value) {
41 return new AnthemUpdate(new PropertyUpdate(name, value));
44 public boolean isStateUpdate() {
45 return updateObject instanceof StateUpdate;
48 public boolean isPropertyUpdate() {
49 return updateObject instanceof PropertyUpdate;
52 public StateUpdate getStateUpdate() {
53 if (updateObject instanceof StateUpdate stateUpdate) {
56 throw new IllegalStateException("Update object is not a state update");
59 public PropertyUpdate getPropertyUpdate() {
60 if (updateObject instanceof PropertyUpdate propertyUpdate) {
61 return propertyUpdate;
63 throw new IllegalStateException("Update object is not a property update");