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.homeconnect.internal.client.model;
15 import static org.openhab.binding.homeconnect.internal.client.model.EventType.EVENT;
16 import static org.openhab.binding.homeconnect.internal.client.model.EventType.NOTIFY;
17 import static org.openhab.binding.homeconnect.internal.client.model.EventType.STATUS;
19 import java.time.ZonedDateTime;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
27 * @author Jonas BrĂ¼stel - Initial contribution
33 private final String haId;
35 private final EventType type;
37 private @Nullable final String key;
38 // user-friendly name of the feature key
39 private @Nullable final String name;
40 // URI of the resource that changed
41 private @Nullable final String uri;
42 // creation time of event
43 private @Nullable final ZonedDateTime creation;
45 private @Nullable final EventLevel level;
47 private @Nullable final EventHandling handling;
48 // new value, e.g. in case of a status update (string, number or boolean)
49 private @Nullable final String value;
51 private @Nullable final String unit;
53 public Event(final String haId, final EventType type) {
59 this.creation = ZonedDateTime.now();
66 public Event(final String haId, final EventType type, @Nullable final String key, @Nullable final String name,
67 @Nullable final String uri, @Nullable final ZonedDateTime creation, @Nullable final EventLevel level,
68 @Nullable final EventHandling handling, @Nullable final String value, @Nullable final String unit) {
74 this.creation = creation;
76 this.handling = handling;
81 public String getHaId() {
85 public EventType getType() {
89 public @Nullable String getKey() {
93 public @Nullable String getName() {
97 public @Nullable String getUri() {
101 public @Nullable ZonedDateTime getCreation() {
105 public @Nullable EventLevel getLevel() {
109 public @Nullable EventHandling getHandling() {
113 public @Nullable String getValue() {
117 public boolean getValueAsBoolean() {
118 return Boolean.parseBoolean(value);
121 public int getValueAsInt() {
122 String stringValue = value;
123 return stringValue != null ? Float.valueOf(stringValue).intValue() : 0;
126 public @Nullable String getUnit() {
131 public String toString() {
132 if (STATUS.equals(type) || EVENT.equals(type) || NOTIFY.equals(type)) {
133 return "Event{" + "haId='" + haId + '\'' + ", type=" + type + ", key='" + key + '\'' + ", name='" + name
134 + '\'' + ", uri='" + uri + '\'' + ", creation=" + creation + ", level=" + level + ", handling="
135 + handling + ", value='" + value + '\'' + ", unit='" + unit + '\'' + '}';
137 return "Event{" + "haId='" + haId + '\'' + ", type=" + type + '}';