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