]> git.basschouten.com Git - openhab-addons.git/blob
1fa12d36ecfac993df74df868c34bb4f78383ab6
[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.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.paradoxalarm.internal.communication.IRequest;
18 import org.openhab.binding.paradoxalarm.internal.communication.messages.zone.ZoneCommand;
19 import org.openhab.binding.paradoxalarm.internal.handlers.Commandable;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * The {@link Zone} Paradox zone.
25  * ID is always numeric (1-192 for Evo192)
26  * States are taken from cached RAM memory map and parsed.
27  *
28  * @author Konstantin Polihronov - Initial contribution
29  */
30 @NonNullByDefault
31 public class Zone extends Entity implements Commandable {
32
33     private final Logger logger = LoggerFactory.getLogger(Zone.class);
34
35     private @Nullable ZoneState zoneState;
36
37     public Zone(ParadoxPanel panel, int id, @Nullable String label) {
38         super(panel, id, label);
39     }
40
41     public @Nullable ZoneState getZoneState() {
42         return zoneState;
43     }
44
45     public void setZoneState(ZoneState zoneState) {
46         this.zoneState = zoneState;
47         logger.debug("Zone {} state updated to: {}", getLabel(), zoneState);
48     }
49
50     @Override
51     public void handleCommand(@Nullable String command) {
52         ZoneCommand zoneCommand = ZoneCommand.parse(command);
53         if (zoneCommand == null) {
54             logger.debug("Command {} is parsed to null. Skipping it", command);
55             return;
56         }
57
58         logger.debug("Submitting command={} for partition=[{}]", zoneCommand, this);
59         IRequest request = zoneCommand.getRequest(getId());
60         getPanel().getCommunicator().submitRequest(request);
61     }
62 }