001package jmri.jmrix.loconet.hexfile;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004import javax.annotation.Nonnull;
005import jmri.JmriException;
006import jmri.Sensor;
007import jmri.jmrix.loconet.LnSensor;
008import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011
012/**
013 * Manage the LocoNet-specific Sensor implementation via a LocoNet
014 * hexfile emulator.
015 * <p>
016 * System names are "LSnnn", where L is the user-configurable system prefix,
017 * nnn is the sensor number without padding.
018 *
019 * @author Kevin Dickerson Copyright (C) 2001
020 */
021@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "This is in effect the same as its super class")
022public class LnSensorManager extends jmri.jmrix.loconet.LnSensorManager {
023
024    public LnSensorManager(LocoNetSystemConnectionMemo memo, boolean interrogateAtStart) {
025        super(memo, interrogateAtStart);
026    }
027
028    // LocoNet-specific methods
029
030    /**
031     * {@inheritDoc}
032     */
033    @Override
034    @Nonnull
035    protected Sensor createNewSensor(@Nonnull String systemName, String userName) throws IllegalArgumentException {
036        Sensor s = new LnSensor(systemName, userName, tc, getSystemPrefix());
037        if (defaultSensorState != Sensor.UNKNOWN) {
038            try {
039                s.setKnownState(defaultSensorState);
040            } catch (JmriException e) {
041                log.warn("Error setting state: ", e);
042            }
043        }
044        return s;
045    }
046
047    private int defaultSensorState = Sensor.UNKNOWN;
048
049    public void setDefaultSensorState(String state) {
050        if (state.equals(Bundle.getMessage("SensorStateInactive"))) {
051            defaultSensorState = Sensor.INACTIVE;
052        } else if (state.equals(Bundle.getMessage("SensorStateActive"))) {
053            defaultSensorState = Sensor.ACTIVE;
054        } else {
055            defaultSensorState = Sensor.UNKNOWN;
056        }
057    }
058
059    private final static Logger log = LoggerFactory.getLogger(LnSensorManager.class);
060
061}