]> git.basschouten.com Git - openhab-addons.git/blob
42966d2bc919a4fe2b3fa917411caeba2e368a00
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.PartitionCommandRequest;
16 import org.openhab.binding.paradoxalarm.internal.communication.RequestType;
17 import org.openhab.binding.paradoxalarm.internal.communication.messages.CommandPayload;
18 import org.openhab.binding.paradoxalarm.internal.communication.messages.HeaderMessageType;
19 import org.openhab.binding.paradoxalarm.internal.communication.messages.ParadoxIPPacket;
20 import org.openhab.binding.paradoxalarm.internal.communication.messages.PartitionCommand;
21 import org.openhab.binding.paradoxalarm.internal.handlers.Commandable;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * The {@link Partition} Paradox partition.
27  * ID is always numeric (1-8 for Evo192)
28  *
29  * @author Konstantin Polihronov - Initial contribution
30  */
31 public class Partition extends Entity implements Commandable {
32
33     private final Logger logger = LoggerFactory.getLogger(Partition.class);
34
35     private PartitionState state = new PartitionState();
36
37     public Partition(ParadoxPanel panel, int id, String label) {
38         super(panel, id, label);
39     }
40
41     public PartitionState getState() {
42         return state;
43     }
44
45     public Partition setState(PartitionState state) {
46         this.state = state;
47         logger.debug("Partition {}:\t{}", getLabel(), getState().getMainState());
48         return this;
49     }
50
51     @Override
52     public void handleCommand(String command) {
53         PartitionCommand partitionCommand = PartitionCommand.parse(command);
54         if (partitionCommand == PartitionCommand.UNKNOWN) {
55             logger.debug("Command UNKNOWN will be ignored.");
56             return;
57         }
58
59         logger.debug("Submitting command={} for partition=[{}]", partitionCommand, this);
60         CommandPayload payload = new CommandPayload(getId(), partitionCommand);
61         ParadoxIPPacket packet = new ParadoxIPPacket(payload.getBytes())
62                 .setMessageType(HeaderMessageType.SERIAL_PASSTHRU_REQUEST);
63         PartitionCommandRequest request = new PartitionCommandRequest(RequestType.PARTITION_COMMAND, packet, null);
64         getPanel().getCommunicator().submitRequest(request);
65     }
66 }