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.caddx.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.caddx.internal.CaddxMessage;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Used to parse panel log event messages.
23 * @author Georgios Moutsos - Initial contribution
26 public class LogEventMessage {
27 private final Logger logger = LoggerFactory.getLogger(LogEventMessage.class);
29 public final String number;
30 public final String size;
31 public final String type;
32 public final String zud;
33 public final String partition;
34 public final String month;
35 public final String day;
36 public final String hour;
37 public final String minute;
39 LogEventMessage(CaddxMessage message) {
40 this.number = message.getPropertyById("panel_log_event_number");
41 this.size = message.getPropertyById("panel_log_event_size");
42 this.type = message.getPropertyById("panel_log_event_type");
43 this.zud = message.getPropertyById("panel_log_event_zud");
44 this.partition = message.getPropertyById("panel_log_event_partition");
45 this.month = message.getPropertyById("panel_log_event_month");
46 this.day = message.getPropertyById("panel_log_event_day");
47 this.hour = message.getPropertyById("panel_log_event_hour");
48 this.minute = message.getPropertyById("panel_log_event_minute");
52 public String toString() {
54 StringBuilder sb = new StringBuilder();
56 int eventType = Integer.parseInt(type);
57 logger.trace("eventType received: {}", eventType);
58 LogEventType logEventType = LogEventType.valueOfLogEventType(eventType);
61 sb.append(String.format("%02d", Integer.parseInt(day))).append('-')
62 .append(String.format("%02d", Integer.parseInt(month))).append(' ')
63 .append(String.format("%02d", Integer.parseInt(hour))).append(':')
64 .append(String.format("%02d", Integer.parseInt(minute))).append(' ');
66 if (logEventType == null) {
67 sb.append("Unknown log event type");
69 sb.append(logEventType.description);
70 if (logEventType.isPartitionValid) {
71 sb.append(" Partition ").append(Integer.parseInt(partition) + 1);
74 switch (logEventType.zud) {
78 sb.append(" Zone ").append(Integer.parseInt(zud) + 1);
81 sb.append(" User ").append(Integer.parseInt(zud) + 1);
84 sb.append(" Device ").append(zud);
90 } catch (NumberFormatException e) {
91 logger.debug("LogEventMessage error. {}", e.getMessage(), e);
92 return "logmessage cannot be constructed";