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