]> git.basschouten.com Git - openhab-addons.git/blob
a6eb68c9fd52af481f00a5c762ed42dcb269530e
[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.homematic.internal.communicator.parser;
14
15 import java.io.IOException;
16
17 import org.openhab.binding.homematic.internal.model.HmChannel;
18 import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
19 import org.openhab.binding.homematic.internal.model.HmDevice;
20 import org.openhab.binding.homematic.internal.model.HmParamsetType;
21
22 /**
23  * Parses an event received from a Homematic gateway.
24  *
25  * @author Gerhard Riegler - Initial contribution
26  */
27 public class EventParser extends CommonRpcParser<Object[], HmDatapointInfo> {
28     private Object value;
29
30     @Override
31     public HmDatapointInfo parse(Object[] message) throws IOException {
32         String address;
33         Integer channel = 0;
34         String addressWithChannel = toString(message[1]);
35         if ("".equals(addressWithChannel)) {
36             address = HmDevice.ADDRESS_GATEWAY_EXTRAS;
37             channel = HmChannel.CHANNEL_NUMBER_VARIABLE;
38         } else {
39             String addrChannel = addressWithChannel == null ? "" : addressWithChannel.trim();
40             String[] configParts = addrChannel.split(":");
41             address = getSanitizedAddress(configParts[0]);
42             if (configParts.length > 1) {
43                 channel = configParts[1] == null ? null : Integer.valueOf(configParts[1]);
44             }
45         }
46
47         String name = toString(message[2]);
48         value = message[3];
49
50         return new HmDatapointInfo(address, HmParamsetType.VALUES, channel, name);
51     }
52
53     /**
54      * Returns the value of the event.
55      */
56     public Object getValue() {
57         return value;
58     }
59 }