]> git.basschouten.com Git - openhab-addons.git/blob
fe3dee04533ebb61c7e8abfee925462619beb04b
[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.teleinfo.internal.reader.io.serialport.converter;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.teleinfo.internal.dto.common.Ptec;
18 import org.openhab.binding.teleinfo.internal.reader.io.serialport.ConversionException;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The {@link PtecConverter} class defines a converter to translate a Teleinfo String value into
24  * {@link Ptec} object.
25  *
26  * @author Nicolas SIBERIL - Initial contribution
27  */
28 @NonNullByDefault
29 public class PtecConverter implements Converter {
30
31     private final Logger logger = LoggerFactory.getLogger(PtecConverter.class);
32
33     @Override
34     public @Nullable Object convert(String value) throws ConversionException {
35         logger.debug("convert(String) [start]");
36         if (logger.isTraceEnabled()) {
37             logger.trace("value = {}", value);
38         }
39
40         Ptec convertedValue = null;
41         switch (value) {
42             case "TH..":
43                 convertedValue = Ptec.TH;
44                 break;
45             case "HC..":
46                 convertedValue = Ptec.HC;
47                 break;
48             case "HP..":
49                 convertedValue = Ptec.HP;
50                 break;
51             case "HN..":
52                 convertedValue = Ptec.HN;
53                 break;
54             case "PM..":
55                 convertedValue = Ptec.PM;
56                 break;
57             case "HCJB":
58                 convertedValue = Ptec.HCJB;
59                 break;
60             case "HCJW":
61                 convertedValue = Ptec.HCJW;
62                 break;
63             case "HCJR":
64                 convertedValue = Ptec.HCJR;
65                 break;
66             case "HPJB":
67                 convertedValue = Ptec.HPJB;
68                 break;
69             case "HPJW":
70                 convertedValue = Ptec.HPJW;
71                 break;
72             case "HPJR":
73                 convertedValue = Ptec.HPJR;
74                 break;
75             default:
76                 throw new ConversionException(value);
77         }
78
79         logger.debug("convert(String) [end]");
80         return convertedValue;
81     }
82 }