Class AbstractPowerSource
- java.lang.Object
-
- oshi.hardware.common.AbstractPowerSource
-
- All Implemented Interfaces:
PowerSource
- Direct Known Subclasses:
AixPowerSource
,FreeBsdPowerSource
,LinuxPowerSource
,MacPowerSource
,OpenBsdPowerSource
,SolarisPowerSource
,WindowsPowerSource
@ThreadSafe public abstract class AbstractPowerSource extends java.lang.Object implements PowerSource
A Power Source
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.hardware.PowerSource
PowerSource.CapacityUnits
-
-
Field Summary
Fields Modifier and Type Field Description private double
amperage
private PowerSource.CapacityUnits
capacityUnits
private boolean
charging
private java.lang.String
chemistry
private int
currentCapacity
private int
cycleCount
private int
designCapacity
private java.lang.String
deviceName
private boolean
discharging
private java.time.LocalDate
manufactureDate
private java.lang.String
manufacturer
private int
maxCapacity
private java.lang.String
name
private boolean
powerOnLine
private double
powerUsageRate
private double
remainingCapacityPercent
private java.lang.String
serialNumber
private double
temperature
private double
timeRemainingEstimated
private double
timeRemainingInstant
private double
voltage
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPowerSource(java.lang.String name, java.lang.String deviceName, double remainingCapacityPercent, double timeRemainingEstimated, double timeRemainingInstant, double powerUsageRate, double voltage, double amperage, boolean powerOnLine, boolean charging, boolean discharging, PowerSource.CapacityUnits capacityUnits, int currentCapacity, int maxCapacity, int designCapacity, int cycleCount, java.lang.String chemistry, java.time.LocalDate manufactureDate, java.lang.String manufacturer, java.lang.String serialNumber, double temperature)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
formatTimeRemaining(double timeInSeconds)
Estimated time remaining on power source, formatted as HH:mmdouble
getAmperage()
Amperage of the battery, in milliAmperes (mA).PowerSource.CapacityUnits
getCapacityUnits()
Reports =the units ofPowerSource.getCurrentCapacity()
,PowerSource.getMaxCapacity()
, andPowerSource.getDesignCapacity()
java.lang.String
getChemistry()
The battery chemistry (e.g., Lithium Ion).int
getCurrentCapacity()
The current (remaining) capacity of the battery.int
getCycleCount()
The cycle count of the battery, if known.int
getDesignCapacity()
The design (original) capacity of the battery.java.lang.String
getDeviceName()
Name of the power source at the device level.java.time.LocalDate
getManufactureDate()
The battery's date of manufacture.java.lang.String
getManufacturer()
The name of the battery's manufacturer.int
getMaxCapacity()
The maximum capacity of the battery.java.lang.String
getName()
Name of the power source at the Operating System level.private static java.util.List<PowerSource>
getPowerSources()
double
getPowerUsageRate()
Power Usage Rate of the battery, in milliWatts (mW).double
getRemainingCapacityPercent()
Estimated remaining capacity as a fraction of max capacity.java.lang.String
getSerialNumber()
The battery's serial number.double
getTemperature()
The battery's temperature, in degrees Celsius.double
getTimeRemainingEstimated()
Estimated time remaining on the power source, in seconds, as reported by the operating system.double
getTimeRemainingInstant()
Estimated time remaining on the power source, in seconds, as reported by the battery.double
getVoltage()
Voltage of the battery, in Volts.boolean
isCharging()
Reports whether the battery is charging.boolean
isDischarging()
Reports whether the battery is discharging.boolean
isPowerOnLine()
Reports whether the device is plugged in to an external power source.java.lang.String
toString()
boolean
updateAttributes()
Updates statistics on this battery.
-
-
-
Field Detail
-
name
private java.lang.String name
-
deviceName
private java.lang.String deviceName
-
remainingCapacityPercent
private double remainingCapacityPercent
-
timeRemainingEstimated
private double timeRemainingEstimated
-
timeRemainingInstant
private double timeRemainingInstant
-
powerUsageRate
private double powerUsageRate
-
voltage
private double voltage
-
amperage
private double amperage
-
powerOnLine
private boolean powerOnLine
-
charging
private boolean charging
-
discharging
private boolean discharging
-
capacityUnits
private PowerSource.CapacityUnits capacityUnits
-
currentCapacity
private int currentCapacity
-
maxCapacity
private int maxCapacity
-
designCapacity
private int designCapacity
-
cycleCount
private int cycleCount
-
chemistry
private java.lang.String chemistry
-
manufactureDate
private java.time.LocalDate manufactureDate
-
manufacturer
private java.lang.String manufacturer
-
serialNumber
private java.lang.String serialNumber
-
temperature
private double temperature
-
-
Constructor Detail
-
AbstractPowerSource
protected AbstractPowerSource(java.lang.String name, java.lang.String deviceName, double remainingCapacityPercent, double timeRemainingEstimated, double timeRemainingInstant, double powerUsageRate, double voltage, double amperage, boolean powerOnLine, boolean charging, boolean discharging, PowerSource.CapacityUnits capacityUnits, int currentCapacity, int maxCapacity, int designCapacity, int cycleCount, java.lang.String chemistry, java.time.LocalDate manufactureDate, java.lang.String manufacturer, java.lang.String serialNumber, double temperature)
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:PowerSource
Name of the power source at the Operating System level.- Specified by:
getName
in interfacePowerSource
- Returns:
- The power source name, as reported by the operating system.
-
getDeviceName
public java.lang.String getDeviceName()
Description copied from interface:PowerSource
Name of the power source at the device level.- Specified by:
getDeviceName
in interfacePowerSource
- Returns:
- The power source name, as reported by the device itself.
-
getRemainingCapacityPercent
public double getRemainingCapacityPercent()
Description copied from interface:PowerSource
Estimated remaining capacity as a fraction of max capacity.This is an estimated/smoothed value which should correspond to the Operating System's "percent power" display, and may not directly correspond to the ratio of
PowerSource.getCurrentCapacity()
toPowerSource.getMaxCapacity()
.- Specified by:
getRemainingCapacityPercent
in interfacePowerSource
- Returns:
- A value between 0.0 (fully drained) and 1.0 (fully charged)
-
getTimeRemainingEstimated
public double getTimeRemainingEstimated()
Description copied from interface:PowerSource
Estimated time remaining on the power source, in seconds, as reported by the operating system.This is an estimated/smoothed value which should correspond to the Operating System's "battery time remaining" display, and will react slowly to changes in power consumption.
- Specified by:
getTimeRemainingEstimated
in interfacePowerSource
- Returns:
- If positive, seconds remaining. If negative, -1.0 (calculating) or -2.0 (unlimited)
-
getTimeRemainingInstant
public double getTimeRemainingInstant()
Description copied from interface:PowerSource
Estimated time remaining on the power source, in seconds, as reported by the battery. If the battery is charging, this value may represent time remaining to fully charge the battery.Note that this value is not very accurate on some battery systems. The value may vary widely depending on present power usage, which could be affected by disk activity and other factors. This value will often be a higher value than
PowerSource.getTimeRemainingEstimated()
.- Specified by:
getTimeRemainingInstant
in interfacePowerSource
- Returns:
- Seconds remaining to fully discharge or fully charge the battery.
-
getPowerUsageRate
public double getPowerUsageRate()
Description copied from interface:PowerSource
Power Usage Rate of the battery, in milliWatts (mW).- Specified by:
getPowerUsageRate
in interfacePowerSource
- Returns:
- If positive, the charge rate. If negative, the discharge rate.
-
getVoltage
public double getVoltage()
Description copied from interface:PowerSource
Voltage of the battery, in Volts.- Specified by:
getVoltage
in interfacePowerSource
- Returns:
- the battery voltage, or -1 if unknown.
-
getAmperage
public double getAmperage()
Description copied from interface:PowerSource
Amperage of the battery, in milliAmperes (mA).- Specified by:
getAmperage
in interfacePowerSource
- Returns:
- the battery amperage. If positive, charging the battery. If negative, discharging the battery.
-
isPowerOnLine
public boolean isPowerOnLine()
Description copied from interface:PowerSource
Reports whether the device is plugged in to an external power source.- Specified by:
isPowerOnLine
in interfacePowerSource
- Returns:
true
if plugged in,false
otherwise.
-
isCharging
public boolean isCharging()
Description copied from interface:PowerSource
Reports whether the battery is charging.- Specified by:
isCharging
in interfacePowerSource
- Returns:
true
if the battery is charging,false
otherwise.
-
isDischarging
public boolean isDischarging()
Description copied from interface:PowerSource
Reports whether the battery is discharging.- Specified by:
isDischarging
in interfacePowerSource
- Returns:
true
if the battery is discharging,false
otherwise.
-
getCapacityUnits
public PowerSource.CapacityUnits getCapacityUnits()
Description copied from interface:PowerSource
Reports =the units ofPowerSource.getCurrentCapacity()
,PowerSource.getMaxCapacity()
, andPowerSource.getDesignCapacity()
- Specified by:
getCapacityUnits
in interfacePowerSource
- Returns:
- The units of battery capacity.
-
getCurrentCapacity
public int getCurrentCapacity()
Description copied from interface:PowerSource
The current (remaining) capacity of the battery.- Specified by:
getCurrentCapacity
in interfacePowerSource
- Returns:
- The current capacity. Units are defined by
PowerSource.getCapacityUnits()
.
-
getMaxCapacity
public int getMaxCapacity()
Description copied from interface:PowerSource
The maximum capacity of the battery. When compared to design capacity, permits a measure of battery state of health. It is possible for max capacity to exceed design capacity.- Specified by:
getMaxCapacity
in interfacePowerSource
- Returns:
- The maximum capacity. Units are defined by
PowerSource.getCapacityUnits()
.
-
getDesignCapacity
public int getDesignCapacity()
Description copied from interface:PowerSource
The design (original) capacity of the battery. When compared to maximum capacity, permits a measure of battery state of health. It is possible for max capacity to exceed design capacity.- Specified by:
getDesignCapacity
in interfacePowerSource
- Returns:
- The design capacity. Units are defined by
PowerSource.getCapacityUnits()
.
-
getCycleCount
public int getCycleCount()
Description copied from interface:PowerSource
The cycle count of the battery, if known.- Specified by:
getCycleCount
in interfacePowerSource
- Returns:
- The cycle count of the battery, or -1 if unknown.
-
getChemistry
public java.lang.String getChemistry()
Description copied from interface:PowerSource
The battery chemistry (e.g., Lithium Ion).- Specified by:
getChemistry
in interfacePowerSource
- Returns:
- the battery chemistry.
-
getManufactureDate
public java.time.LocalDate getManufactureDate()
Description copied from interface:PowerSource
The battery's date of manufacture.Some battery manufacturers encode the manufacture date in the serial number. Parsing this value is operating system and battery manufacturer dependent, and is left to the user.
- Specified by:
getManufactureDate
in interfacePowerSource
- Returns:
- the manufacture date, if available. May be
null
.
-
getManufacturer
public java.lang.String getManufacturer()
Description copied from interface:PowerSource
The name of the battery's manufacturer.- Specified by:
getManufacturer
in interfacePowerSource
- Returns:
- the manufacturer name.
-
getSerialNumber
public java.lang.String getSerialNumber()
Description copied from interface:PowerSource
The battery's serial number.Some battery manufacturers encode the manufacture date in the serial number. Parsing this value is operating system and battery manufacturer dependent, and is left to the user.
- Specified by:
getSerialNumber
in interfacePowerSource
- Returns:
- the serial number.
-
getTemperature
public double getTemperature()
Description copied from interface:PowerSource
The battery's temperature, in degrees Celsius.- Specified by:
getTemperature
in interfacePowerSource
- Returns:
- the battery's temperature, or 0 if uknown.
-
updateAttributes
public boolean updateAttributes()
Description copied from interface:PowerSource
Updates statistics on this battery.- Specified by:
updateAttributes
in interfacePowerSource
- Returns:
true
if the update was successful. Iffalse
the battery statistics are unchanged.
-
getPowerSources
private static java.util.List<PowerSource> getPowerSources()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
formatTimeRemaining
private static java.lang.String formatTimeRemaining(double timeInSeconds)
Estimated time remaining on power source, formatted as HH:mm- Parameters:
timeInSeconds
- The time remaining, in seconds- Returns:
- formatted String of time remaining
-
-