]> git.basschouten.com Git - openhab-addons.git/blob
91dae6baf3bd05275102caa849a68011694595e3
[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 {}:\t{}", getLabel(), getState().getMainState());
44         return this;
45     }
46
47     @Override
48     public void handleCommand(String command) {
49         PartitionCommand partitionCommand = PartitionCommand.parse(command);
50         if (partitionCommand == null) {
51             logger.debug("Command {} is parsed to null. Skipping it", command);
52             return;
53         }
54
55         logger.debug("Submitting command={} for partition=[{}]", partitionCommand, this);
56         IRequest request = partitionCommand.getRequest(getId());
57         getPanel().getCommunicator().submitRequest(request);
58     }
59 }