]> git.basschouten.com Git - openhab-addons.git/blob
2b2571ec044f975c9d473be1a74c7fc4f1a4fa59
[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.lcn.internal.subhandler;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.lcn.internal.LcnModuleHandler;
22 import org.openhab.binding.lcn.internal.common.LcnChannelGroup;
23 import org.openhab.binding.lcn.internal.common.LcnDefs;
24 import org.openhab.binding.lcn.internal.common.LcnException;
25 import org.openhab.binding.lcn.internal.common.PckGenerator;
26 import org.openhab.binding.lcn.internal.connection.ModInfo;
27 import org.openhab.core.library.types.StopMoveType;
28 import org.openhab.core.library.types.UpDownType;
29
30 /**
31  * Handles Commands and State changes of roller shutters connected to dimmer outputs of an LCN module.
32  *
33  * @author Fabian Wolter - Initial contribution
34  */
35 @NonNullByDefault
36 public class LcnModuleRollershutterOutputSubHandler extends AbstractLcnModuleSubHandler {
37     public LcnModuleRollershutterOutputSubHandler(LcnModuleHandler handler, ModInfo info) {
38         super(handler, info);
39     }
40
41     @Override
42     public void handleRefresh(LcnChannelGroup channelGroup, int number) {
43         info.refreshOutput(number);
44     }
45
46     @Override
47     public void handleCommandUpDown(UpDownType command, LcnChannelGroup channelGroup, int number, boolean invertUpDown)
48             throws LcnException {
49         // When configured as shutter in LCN-PRO, an output gets switched off, when the other is
50         // switched on and vice versa.
51         if (command == UpDownType.UP ^ invertUpDown) {
52             // first output: 100%
53             handler.sendPck(PckGenerator.dimOutput(0, 100, LcnDefs.ROLLER_SHUTTER_RAMP_MS));
54         } else {
55             // second output: 100%
56             handler.sendPck(PckGenerator.dimOutput(1, 100, LcnDefs.ROLLER_SHUTTER_RAMP_MS));
57         }
58     }
59
60     @Override
61     public void handleCommandStopMove(StopMoveType command, LcnChannelGroup channelGroup, int number)
62             throws LcnException {
63         if (command == StopMoveType.STOP) {
64             // both outputs off
65             handler.sendPck(PckGenerator.dimOutput(0, 0, 0));
66             handler.sendPck(PckGenerator.dimOutput(1, 0, 0));
67         } else {
68             // roller shutters on outputs are stateless, assume always down when MOVE is sent
69             // second output: 100%
70             handler.sendPck(PckGenerator.dimOutput(1, 100, LcnDefs.ROLLER_SHUTTER_RAMP_MS));
71         }
72     }
73
74     @Override
75     public void handleStatusMessage(Matcher matcher) {
76         // status messages of roller shutters on dimmer outputs are handled in the dimmer output sub handler
77     }
78
79     @Override
80     public Collection<Pattern> getPckStatusMessagePatterns() {
81         return Collections.emptyList();
82     }
83 }