]> git.basschouten.com Git - openhab-addons.git/blob
11fe75221a31ba796cfa055afcd544461f234429
[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.LcnException;
24 import org.openhab.binding.lcn.internal.common.PckGenerator;
25 import org.openhab.binding.lcn.internal.common.Variable;
26 import org.openhab.binding.lcn.internal.connection.ModInfo;
27 import org.openhab.core.library.types.OnOffType;
28
29 /**
30  * Handles Commands and State changes of regulator locks of an LCN module.
31  *
32  * @author Fabian Wolter - Initial contribution
33  */
34 @NonNullByDefault
35 public class LcnModuleRvarLockSubHandler extends AbstractLcnModuleVariableSubHandler {
36     public LcnModuleRvarLockSubHandler(LcnModuleHandler handler, ModInfo info) {
37         super(handler, info);
38     }
39
40     @Override
41     public void handleRefresh(LcnChannelGroup channelGroup, int number) {
42         super.handleRefresh(LcnChannelGroup.RVARSETPOINT, number);
43     }
44
45     @Override
46     public void handleCommandOnOff(OnOffType command, LcnChannelGroup channelGroup, int number) throws LcnException {
47         boolean locked = command == OnOffType.ON;
48         handler.sendPck(PckGenerator.lockRegulator(number, locked));
49
50         // request new lock state, if the module doesn't send it on itself
51         Variable variable = getVariable(LcnChannelGroup.RVARSETPOINT, number);
52         if (info.getFirmwareVersion().map(v -> variable.shouldPollStatusAfterRegulatorLock(v, locked)).orElse(true)) {
53             info.refreshVariable(variable);
54         }
55     }
56
57     @Override
58     public void handleStatusMessage(Matcher matcher) {
59         // status messages are handled in the RVar setpoint sub handler
60     }
61
62     @Override
63     public Collection<Pattern> getPckStatusMessagePatterns() {
64         return Collections.emptyList();
65     }
66 }