Class AbstractDevice

java.lang.Object
org.episteme.core.device.AbstractDevice
All Implemented Interfaces:
Serializable, AutoCloseable, Device, Commented, ComprehensiveIdentification, Identified<Identification>, Named
Direct Known Subclasses:
AbstractActuator, AbstractSensor, AbstractSimulatedDevice, MassSpectra, USBDevice

public abstract class AbstractDevice extends Object implements Device
Base implementation for the Device interface. Delegates identification and naming to an internal Identification object.
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Field Details

    • identification

      protected final Identification identification
    • manufacturer

      protected String manufacturer
    • model

      protected String model
    • locationDescription

      protected String locationDescription
    • firmware

      protected String firmware
    • precisionDescription

      protected String precisionDescription
    • sensitivity

      protected Quantity<?> sensitivity
    • accuracy

      protected Quantity<?> accuracy
    • resolution

      protected Quantity<?> resolution
    • minRange

      protected Quantity<?> minRange
    • maxRange

      protected Quantity<?> maxRange
    • status

      protected Device.Status status
    • lastCalibration

      protected Instant lastCalibration
    • calibrationHistory

      protected final List<Calibration> calibrationHistory
    • history

      protected final List<AbstractDevice.Record> history
    • displayUnit

      protected Unit<?> displayUnit
    • currentValue

      protected Quantity<?> currentValue
  • Constructor Details

    • AbstractDevice

      protected AbstractDevice(Identification identification)
  • Method Details

    • getId

      public Identification getId()
      Description copied from interface: Device
      Returns the unique identifier for this device.
      Specified by:
      getId in interface Device
      Specified by:
      getId in interface Identified<Identification>
      Returns:
      the device ID
    • getTraits

      public Map<String,Object> getTraits()
      Description copied from interface: ComprehensiveIdentification
      Returns the traits map for this entity.
      Specified by:
      getTraits in interface Commented
      Specified by:
      getTraits in interface ComprehensiveIdentification
      Returns:
      the traits map
    • getTrait

      public Object getTrait(String key)
      Description copied from interface: ComprehensiveIdentification
      Returns a trait value by name.
      Specified by:
      getTrait in interface Commented
      Specified by:
      getTrait in interface ComprehensiveIdentification
      Parameters:
      key - the trait name
      Returns:
      the trait value, or null if not found
    • getTraitOptional

      public Optional<Object> getTraitOptional(String key)
      Returns a trait value wrapped in an Optional.
      Parameters:
      key - the trait key
      Returns:
      an Optional containing the trait value, or empty if not found
    • getManufacturer

      public String getManufacturer()
      Description copied from interface: Device
      Returns the manufacturer name.
      Specified by:
      getManufacturer in interface Device
      Returns:
      the manufacturer
    • setManufacturer

      protected void setManufacturer(String manufacturer)
    • getModel

      public String getModel()
      Description copied from interface: Device
      Returns the model name.
      Specified by:
      getModel in interface Device
      Returns:
      the model
    • setModel

      protected void setModel(String model)
    • getLocationDescription

      public String getLocationDescription()
      Description copied from interface: Device
      Returns the location description of the device.
      Specified by:
      getLocationDescription in interface Device
      Returns:
      the location description
    • setLocationDescription

      protected void setLocationDescription(String locationDescription)
    • getFirmware

      public String getFirmware()
      Description copied from interface: Device
      Returns the firmware version of this device.
      Specified by:
      getFirmware in interface Device
      Returns:
      the firmware version, or "N/A" if not applicable
    • setFirmware

      protected void setFirmware(String firmware)
    • getPrecisionDescription

      public String getPrecisionDescription()
      Description copied from interface: Device
      Returns the precision description of the device.
      Specified by:
      getPrecisionDescription in interface Device
      Returns:
      the precision description
    • setPrecisionDescription

      protected void setPrecisionDescription(String precisionDescription)
    • getSensitivity

      public Optional<Quantity<?>> getSensitivity()
      Description copied from interface: Device
      Returns the sensitivity of the device.
      Specified by:
      getSensitivity in interface Device
      Returns:
      the sensitivity
    • setSensitivity

      protected void setSensitivity(Quantity<?> sensitivity)
    • getAccuracy

      public Optional<Quantity<?>> getAccuracy()
      Description copied from interface: Device
      Returns the accuracy of the device.
      Specified by:
      getAccuracy in interface Device
      Returns:
      the accuracy
    • setAccuracy

      protected void setAccuracy(Quantity<?> accuracy)
    • getResolution

      public Optional<Quantity<?>> getResolution()
      Description copied from interface: Device
      Returns the resolution of the device.
      Specified by:
      getResolution in interface Device
      Returns:
      the resolution
    • setResolution

      protected void setResolution(Quantity<?> resolution)
    • getMinRange

      public Optional<Quantity<?>> getMinRange()
      Description copied from interface: Device
      Returns the minimum measurement range.
      Specified by:
      getMinRange in interface Device
    • setMinRange

      protected void setMinRange(Quantity<?> minRange)
    • getMaxRange

      public Optional<Quantity<?>> getMaxRange()
      Description copied from interface: Device
      Returns the maximum measurement range.
      Specified by:
      getMaxRange in interface Device
    • setMaxRange

      protected void setMaxRange(Quantity<?> maxRange)
    • getStatus

      public String getStatus()
      Description copied from interface: Device
      Returns the current status of the device as a string.
      Specified by:
      getStatus in interface Device
      Returns:
      the status string
    • getDeviceStatus

      public Device.Status getDeviceStatus()
      Description copied from interface: Device
      Returns the actual status enum if available.
      Specified by:
      getDeviceStatus in interface Device
    • setStatus

      public void setStatus(Device.Status status)
    • getLastCalibration

      public Instant getLastCalibration()
      Description copied from interface: Device
      Returns the timestamp of the last calibration.
      Specified by:
      getLastCalibration in interface Device
      Returns:
      the last calibration instant
    • setLastCalibration

      protected void setLastCalibration(Instant lastCalibration)
    • getCalibrationHistory

      public List<Calibration> getCalibrationHistory()
      Description copied from interface: Device
      Returns the calibration history.
      Specified by:
      getCalibrationHistory in interface Device
    • getDisplayUnit

      public Optional<Unit<?>> getDisplayUnit()
      Description copied from interface: Device
      Returns the preferred unit for display.
      Specified by:
      getDisplayUnit in interface Device
    • setDisplayUnit

      public void setDisplayUnit(Unit<?> unit)
      Description copied from interface: Device
      Sets the preferred unit for display.
      Specified by:
      setDisplayUnit in interface Device
    • calibrate

      public void calibrate(Quantity<?> reference) throws Exception
      Description copied from interface: Device
      Calibrates the device using a reference value.
      Specified by:
      calibrate in interface Device
      Throws:
      Exception
    • performCalibration

      protected void performCalibration(Quantity<?> reference) throws Exception
      Performs actual calibration logic. Subclasses should override this.
      Throws:
      Exception
    • needsCalibration

      public boolean needsCalibration(int maxAgeHours)
      Description copied from interface: Device
      Checks if the device needs calibration based on its maximum age.
      Specified by:
      needsCalibration in interface Device
    • getValue

      public Optional<Quantity<?>> getValue()
      Description copied from interface: Device
      Returns the current primary value of the device (e.g. sensor reading).
      Specified by:
      getValue in interface Device
      Returns:
      the current value
    • measure

      public Optional<Quantity<?>> measure()
      Description copied from interface: Device
      Takes a measurement.
      Specified by:
      measure in interface Device
      Returns:
      the measured value
    • setCurrentValue

      protected void setCurrentValue(Quantity<?> value)
      Updates the current value and records it in history.
    • getHistory

      public List<AbstractDevice.Record> getHistory()
      Description copied from interface: Device
      Returns the history of values for this device.
      Specified by:
      getHistory in interface Device
      Returns:
      the value history
    • recordMeasurement

      protected void recordMeasurement(Quantity<?> value)
      Records a value in the device history with a timestamp.
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: Device
      Checks if the device is enabled.
      Specified by:
      isEnabled in interface Device
      Returns:
      true if enabled
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: Device
      Sets whether the device is enabled.
      Specified by:
      setEnabled in interface Device
      Parameters:
      enabled - true to enable
    • getMeasurableQuantities

      public List<Class<? extends Quantity<?>>> getMeasurableQuantities()
      Description copied from interface: Device
      Returns the types of quantities this instrument can measure.
      Specified by:
      getMeasurableQuantities in interface Device