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.souliss.internal.handler;
15 import java.text.SimpleDateFormat;
16 import java.util.Date;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.library.types.DateTimeType;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.binding.BaseThingHandler;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * This class implements the base Souliss Action Message. All Action Messages derives from
29 * @author Tonino Fazio - Initial contribution
30 * @author Luca Calcaterra - Refactor for OH3
31 * @author Tonino Fazio - @since 1.7.0
35 public abstract class SoulissGenericActionMessage extends BaseThingHandler {
39 private String sTopicNumber = "";
40 private String sTopicVariant = "";
42 private String timestamp = "";
43 private final Logger logger = LoggerFactory.getLogger(SoulissGenericActionMessage.class);
45 protected SoulissGenericActionMessage(Thing pThing) {
47 thingGenActMsg = pThing;
50 var cfg = thingGenActMsg.getConfiguration();
51 var props = cfg.getProperties();
52 var pTopicNumber = props.get("number");
53 var pTopicVariant = props.get("number");
54 if (pTopicNumber != null) {
55 sTopicNumber = pTopicNumber.toString();
57 if (pTopicVariant != null) {
58 sTopicVariant = pTopicVariant.toString();
60 } catch (Exception e) {
61 logger.debug("Item Definition Error. Use ex:'souliss:t11:thing_id'");
66 * @return the Topic Number
68 public String getTopicNumber() {
73 * @param the Topic Variant
75 public String getTopicVariant() {
79 public DateTimeType getLastUpdateTime() {
80 return DateTimeType.valueOf(timestamp);
83 public void setUpdateTimeNow() {
84 timestamp = getTimestamp();
88 * Create a time stamp as "yyyy-MM-dd'T'HH:mm:ssz"
90 * @return String timestamp
92 private static String getTimestamp() {
93 // Pattern : yyyy-MM-dd'T'HH:mm:ssz
94 var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
96 return sdf.format(n.getTime());
100 public void thingUpdated(Thing thing) {
101 this.thingGenActMsg = thing;