]> git.basschouten.com Git - openhab-addons.git/blob
26fd75750fe286cf09a5fc0115fdca5f5e0767b5
[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.velbus.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link VelbusFirstGenerationDeviceModuleAddress} represents the address Velbus
19  * module of the 1st generation.
20  *
21  * @author Cedric Boon - Initial contribution
22  */
23 @NonNullByDefault
24 public class VelbusFirstGenerationDeviceModuleAddress extends VelbusModuleAddress {
25
26     public VelbusFirstGenerationDeviceModuleAddress(byte address) {
27         super(address, 0);
28     }
29
30     @Override
31     public int getChannelNumber(VelbusChannelIdentifier velbusChannelIdentifier) {
32         byte channelByte = velbusChannelIdentifier.getChannelByte();
33         if (channelByte == (byte) 0x03) {
34             return 1;
35         } else if (channelByte == (byte) 0x0C) {
36             return 2;
37         }
38
39         throw new IllegalArgumentException("The byte '" + channelByte
40                 + "' does not represent a valid channel on the first generation device with address '"
41                 + velbusChannelIdentifier.getAddress() + "'.");
42     }
43
44     @Override
45     public VelbusChannelIdentifier getChannelIdentifier(int channelIndex) {
46         if (channelIndex == 0) {
47             return new VelbusChannelIdentifier(getAddress(), (byte) 0x03);
48         } else if (channelIndex == 1) {
49             return new VelbusChannelIdentifier(getAddress(), (byte) 0x0C);
50         } else {
51             throw new IllegalArgumentException("The channel index '" + channelIndex
52                     + "' is not valid for the first generation device on the address '" + getAddress() + "'.");
53         }
54     }
55 }