import org.openhab.binding.paradoxalarm.internal.communication.messages.IPPacket;
import org.openhab.binding.paradoxalarm.internal.communication.messages.IpMessagesConstants;
import org.openhab.binding.paradoxalarm.internal.communication.messages.ParadoxIPPacket;
-import org.openhab.binding.paradoxalarm.internal.model.ParadoxPanel;
import org.openhab.binding.paradoxalarm.internal.util.ParadoxUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
if (communicator != null) {
communicator.close();
}
- ParadoxPanel.getInstance().dispose();
}
};
protected void startScan() {
IParadoxCommunicator communicator = ip150BridgeHandler.getCommunicator();
if (communicator != null && communicator.isOnline()) {
- ParadoxPanel panel = ParadoxPanel.getInstance();
+ ParadoxPanel panel = ip150BridgeHandler.getPanel();
discoverPanel(panel.getPanelInformation());
discoverPartitions(panel.getPartitions());
discoverZones(panel.getZones());
private void initializeDelayed() {
logger.debug("Start initializeDelayed() in {}", getThing().getUID());
- ParadoxPanel panel = ParadoxPanel.getInstance();
+ ParadoxIP150BridgeHandler bridge = (ParadoxIP150BridgeHandler) getBridge().getHandler();
+ ParadoxPanel panel = bridge.getPanel();
// Asynchronous update not yet done
if (panel.getPanelInformation() == null) {
// Retry until reach MAX_WAIT_TIME
private final Logger logger = LoggerFactory.getLogger(ParadoxIP150BridgeHandler.class);
private IParadoxCommunicator communicator;
+ private ParadoxPanel panel = new ParadoxPanel();
private ParadoxIP150BridgeConfiguration config;
private @Nullable ScheduledFuture<?> refreshCacheUpdateSchedule;
.withMaxPartitions(config.getMaxPartitions()).withMaxZones(config.getMaxZones())
.withScheduler(scheduler).withEncryption(config.isEncrypt()).build();
- ParadoxPanel panel = ParadoxPanel.getInstance();
panel.setCommunicator(communicator);
Collection<IDataUpdateListener> listeners = Arrays.asList(panel, this);
public void dispose() {
cancelSchedule(refreshCacheUpdateSchedule);
CommunicationState.logout(communicator);
+ panel.dispose();
super.dispose();
}
return communicator;
}
+ public ParadoxPanel getPanel() {
+ return panel;
+ }
+
@Override
public void onSocketTimeOutOccurred(IOException exception) {
logger.warn("TIMEOUT! {} received message for socket timeout. ", this, exception);
@Override
protected void updateEntity() {
- ParadoxPanel panel = ParadoxPanel.getInstance();
+ ParadoxIP150BridgeHandler bridge = (ParadoxIP150BridgeHandler) getBridge().getHandler();
+ ParadoxPanel panel = bridge.getPanel();
StringType panelState = panel.isOnline() ? STATE_ONLINE : STATE_OFFLINE;
updateState(PANEL_STATE_CHANNEL_UID, panelState);
ParadoxInformation panelInformation = panel.getPanelInformation();
protected Partition getPartition() {
int index = calculateEntityIndex();
- List<Partition> partitions = ParadoxPanel.getInstance().getPartitions();
+ ParadoxIP150BridgeHandler bridge = (ParadoxIP150BridgeHandler) getBridge().getHandler();
+ ParadoxPanel panel = bridge.getPanel();
+ List<Partition> partitions = panel.getPartitions();
if (partitions == null) {
logger.debug(
"Partitions collection of Paradox Panel object is null. Probably not yet initialized. Skipping update.");
@Override
protected void updateEntity() {
int index = calculateEntityIndex();
- List<Zone> zones = ParadoxPanel.getInstance().getZones();
+ ParadoxIP150BridgeHandler bridge = (ParadoxIP150BridgeHandler) getBridge().getHandler();
+ ParadoxPanel panel = bridge.getPanel();
+ List<Zone> zones = panel.getZones();
if (zones == null) {
logger.debug(
"Zones collection of Paradox Panel object is null. Probably not yet initialized. Skipping update.");
public abstract class Entity {
private final Logger logger = LoggerFactory.getLogger(Entity.class);
+ private ParadoxPanel panel;
private int id;
private String label;
- public Entity(int id, String label) {
+ public Entity(ParadoxPanel panel, int id, String label) {
+ this.panel = panel;
this.id = id;
this.label = label.trim();
logger.debug("Creating entity with label: {} and ID: {}", label, id);
this.label = label;
}
+ public ParadoxPanel getPanel() {
+ return panel;
+ }
+
@Override
public String toString() {
return "Entity [id=" + id + ", label=" + label + "]";
import java.util.Map;
import java.util.TimeZone;
-import org.eclipse.jdt.annotation.NonNull;
import org.openhab.binding.paradoxalarm.internal.communication.IDataUpdateListener;
import org.openhab.binding.paradoxalarm.internal.communication.IParadoxCommunicator;
import org.openhab.binding.paradoxalarm.internal.exceptions.ParadoxRuntimeException;
private final Logger logger = LoggerFactory.getLogger(ParadoxPanel.class);
- @NonNull
- private static ParadoxPanel paradoxPanel = new ParadoxPanel();
-
private ParadoxInformation panelInformation;
private List<Partition> partitions;
private List<Zone> zones;
private double dcLevel;
private ZonedDateTime panelTime;
- private ParadoxPanel() {
+ public ParadoxPanel() {
this.parser = new EvoParser();
}
}
}
- public static ParadoxPanel getInstance() {
- return paradoxPanel;
- }
-
public boolean isPanelSupported() {
PanelType panelType = panelInformation.getPanelType();
return panelType == PanelType.EVO48 || panelType == PanelType.EVO192 || panelType == PanelType.EVOHD;
zones = new ArrayList<>();
Map<Integer, String> zoneLabels = communicator.getZoneLabels();
for (int i = 0; i < zoneLabels.size(); i++) {
- Zone zone = new Zone(i + 1, zoneLabels.get(i));
+ Zone zone = new Zone(this, i + 1, zoneLabels.get(i));
zones.add(zone);
}
return zones;
partitions = new ArrayList<>();
Map<Integer, String> partitionLabels = communicator.getPartitionLabels();
for (int i = 0; i < partitionLabels.size(); i++) {
- Partition partition = new Partition(i + 1, partitionLabels.get(i));
+ Partition partition = new Partition(this, i + 1, partitionLabels.get(i));
partitions.add(partition);
logger.debug("Partition {}:\t{}", i + 1, partition.getState().getMainState());
}
*/
package org.openhab.binding.paradoxalarm.internal.model;
-import org.openhab.binding.paradoxalarm.internal.communication.IParadoxCommunicator;
import org.openhab.binding.paradoxalarm.internal.communication.PartitionCommandRequest;
import org.openhab.binding.paradoxalarm.internal.communication.RequestType;
import org.openhab.binding.paradoxalarm.internal.communication.messages.CommandPayload;
private PartitionState state = new PartitionState();
- public Partition(int id, String label) {
- super(id, label);
+ public Partition(ParadoxPanel panel, int id, String label) {
+ super(panel, id, label);
}
public PartitionState getState() {
ParadoxIPPacket packet = new ParadoxIPPacket(payload.getBytes())
.setMessageType(HeaderMessageType.SERIAL_PASSTHRU_REQUEST);
PartitionCommandRequest request = new PartitionCommandRequest(RequestType.PARTITION_COMMAND, packet, null);
- IParadoxCommunicator communicator = ParadoxPanel.getInstance().getCommunicator();
- communicator.submitRequest(request);
+ getPanel().getCommunicator().submitRequest(request);
}
}
private ZoneState zoneState;
- public Zone(int id, String label) {
- super(id, label);
+ public Zone(ParadoxPanel panel, int id, String label) {
+ super(panel, id, label);
}
public ZoneState getZoneState() {
private static ScheduledExecutorService scheduler;
private static IParadoxCommunicator communicator;
+ private static ParadoxPanel panel;
public static void main(String[] args) {
readArguments(args);
.withTcpPort(port).withMaxPartitions(4).withMaxZones(20).withScheduler(scheduler)
.withEncryption(true).build();
- ParadoxPanel panel = ParadoxPanel.getInstance();
+ panel = new ParadoxPanel();
panel.setCommunicator(communicator);
communicator.setListeners(Arrays.asList(panel));
communicator.startLoginSequence();
scheduler.scheduleWithFixedDelay(() -> {
- refreshMemoryMap(communicator, false);
+ refreshMemoryMap(panel, false);
}, 7, 5, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("Exception: ", e);
}
}
- private static void refreshMemoryMap(IParadoxCommunicator communicator, boolean withEpromValues) {
+ private static void refreshMemoryMap(ParadoxPanel panel, boolean withEpromValues) {
logger.debug("Refreshing memory map");
+ IParadoxCommunicator communicator = panel.getCommunicator();
communicator.refreshMemoryMap();
- ParadoxPanel panel = ParadoxPanel.getInstance();
panel.getPartitions().stream().forEach(partition -> logger.debug("Partition={}", partition));
panel.getZones().stream().filter(zone -> zone.getId() == 19).forEach(zone -> logger.debug("Zone={}", zone));
logger.debug("PanelTime={}, ACLevel={}, DCLevel={}, BatteryLevel={}", panel.getPanelTime(), panel.getVdcLevel(),