]> git.basschouten.com Git - openhab-addons.git/blob
e65a3820991c9c946001578ba6a9ba0cdf098c58
[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.paradoxalarm.internal.model;
14
15 import org.openhab.binding.paradoxalarm.internal.communication.IRequest;
16 import org.openhab.binding.paradoxalarm.internal.communication.messages.partition.PartitionCommand;
17 import org.openhab.binding.paradoxalarm.internal.handlers.Commandable;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * The {@link Partition} Paradox partition.
23  * ID is always numeric (1-8 for Evo192)
24  *
25  * @author Konstantin Polihronov - Initial contribution
26  */
27 public class Partition extends Entity implements Commandable {
28
29     private final Logger logger = LoggerFactory.getLogger(Partition.class);
30
31     private PartitionState state = new PartitionState();
32
33     public Partition(ParadoxPanel panel, int id, String label) {
34         super(panel, id, label);
35     }
36
37     public PartitionState getState() {
38         return state;
39     }
40
41     public Partition setState(PartitionState state) {
42         this.state = state;
43         logger.debug("Partition {} main state:\t{}", getLabel(), getState().getMainState());
44         if (logger.isTraceEnabled()) {
45             logger.trace("Partition {} detailed state:\t{}", getLabel(), getState().getDetailedState());
46             logger.trace("Partition {} full state dump:\t{}", getLabel(), getState());
47         }
48         return this;
49     }
50
51     @Override
52     public void handleCommand(String command) {
53         PartitionCommand partitionCommand = PartitionCommand.parse(command);
54         if (partitionCommand == null) {
55             logger.debug("Command {} is parsed to null. Skipping it", command);
56             return;
57         }
58
59         logger.debug("Submitting command={} for partition=[{}]", partitionCommand, this);
60         IRequest request = partitionCommand.getRequest(getId());
61         getPanel().getCommunicator().submitRequest(request);
62     }
63 }