]> git.basschouten.com Git - openhab-addons.git/blob
8f7a3fe433bc4d54b346f0f0c11df876ef677fb3
[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.velux.internal.things;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.velux.internal.VeluxBindingConstants;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * <B>Velux</B> product characteristics: Product Reference.
22  * <P>
23  * Combined set of information which describes a current state of a single Velux product.
24  * </P>
25  * Methods in handle this type of information:
26  * <UL>
27  * <LI>{@link #getProductName()} to retrieve the name representing this actuator/product.</LI>
28  * <LI>{@link #getProductType()} to retrieve the type of the product.</LI>
29  * <LI>{@link #toString} to retrieve a human-readable description of the product state.</LI>
30  * </UL>
31  *
32  *
33  * @author Guenther Schreiner - initial contribution.
34  */
35 @NonNullByDefault
36 public class VeluxProductReference {
37     private final Logger logger = LoggerFactory.getLogger(VeluxProductReference.class);
38
39     // Class internal
40
41     private final VeluxProductName name;
42     private final VeluxProductType typeId;
43
44     // Constructor
45
46     /**
47      * Initializes the {@link VeluxProductReference} based on a given {@link VeluxProduct} and its associated type.
48      * <P>
49      *
50      * @param name as {@link VeluxProductName} referencing to a specific actuator/product.
51      * @param type as int as handled by {@link VeluxProductType#get(int)}.
52      */
53     public VeluxProductReference(VeluxProductName name, int type) {
54         this.name = name;
55         this.typeId = VeluxProductType.get(type);
56         if (this.typeId == VeluxProductType.UNDEFTYPE) {
57             logger.warn(
58                     "Please report this to maintainer of the {} binding: VeluxProductReference({}) has found an unregistered ProductTypeId.",
59                     VeluxBindingConstants.BINDING_ID, type);
60         }
61     }
62
63     // Class access methods
64
65     public VeluxProductName getProductName() {
66         return this.name;
67     }
68
69     public VeluxProductType getProductType() {
70         return this.typeId;
71     }
72
73     @Override
74     public String toString() {
75         return String.format("Prod.ref. \"%s\"/%s", this.name, this.typeId);
76     }
77 }