Class MacPowerSource
java.lang.Object
oshi.hardware.common.AbstractPowerSource
oshi.hardware.common.platform.mac.MacPowerSource
- All Implemented Interfaces:
PowerSource
Abstract base for the macOS PowerSource. The
AppleSmartBattery registry read and the per-power-source field
computation are shared; the JNA and FFM subclasses supply an IOKitProvider and read the IOKit Power Sources
(IOPS) list into MacPowerSource.PowerSourceData carriers via buildPowerSources(IOKitProvider, double, List, MacPowerSource.PowerSourceFactory).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRaw values read from a single IOKit Power Source (IOPS) dictionary by the JNA/FFM subclasses.protected static interfaceCreates a concrete (JNA or FFM) Mac power source from the computed battery fields.Nested classes/interfaces inherited from interface PowerSource
PowerSource.CapacityUnitsModifier and TypeInterfaceDescriptionstatic enumUnits of Battery Capacity -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMacPowerSource(String psName, String psDeviceName, double psRemainingCapacityPercent, double psTimeRemainingEstimated, double psTimeRemainingInstant, double psPowerUsageRate, double psVoltage, double psAmperage, boolean psPowerOnLine, boolean psCharging, boolean psDischarging, PowerSource.CapacityUnits psCapacityUnits, int psCurrentCapacity, int psMaxCapacity, int psDesignCapacity, int psCycleCount, String psChemistry, LocalDate psManufactureDate, String psManufacturer, String psSerialNumber, double psTemperature) Creates a MacPowerSource. -
Method Summary
Modifier and TypeMethodDescriptionprotected static List<PowerSource> buildPowerSources(IOKitProvider ioKit, double timeRemainingEstimated, List<MacPowerSource.PowerSourceData> sources, MacPowerSource.PowerSourceFactory factory) Reads theAppleSmartBatteryregistry entry (viaioKit) and merges it with the per-source IOPS readings into a list of power sources.Methods inherited from class AbstractPowerSource
getAmperage, getCapacityUnits, getChemistry, getCurrentCapacity, getCycleCount, getDesignCapacity, getDeviceName, getManufactureDate, getManufacturer, getMaxCapacity, getName, getPowerUsageRate, getRemainingCapacityPercent, getSerialNumber, getTemperature, getTimeRemainingEstimated, getTimeRemainingInstant, getVoltage, isCharging, isDischarging, isPowerOnLine, queryPowerSources, toString, updateAttributesModifier and TypeMethodDescriptiondoubleAmperage of the battery, in milliAmperes (mA).Reports =the units ofPowerSource.getCurrentCapacity(),PowerSource.getMaxCapacity(), andPowerSource.getDesignCapacity()The battery chemistry (e.g., Lithium Ion).intThe current (remaining) capacity of the battery.intThe cycle count of the battery, if known.intThe design (original) capacity of the battery.Name of the power source at the device level.The battery's date of manufacture.The name of the battery's manufacturer.intThe maximum capacity of the battery.getName()Name of the power source at the Operating System level.doublePower Usage Rate of the battery, in milliWatts (mW).doubleEstimated remaining capacity as a fraction of max capacity.The battery's serial number.doubleThe battery's temperature, in degrees Celsius.doubleEstimated time remaining on the power source, in seconds, as reported by the operating system.doubleEstimated time remaining on the power source, in seconds, as reported by the battery.doubleVoltage of the battery, in Volts.booleanReports whether the battery is charging.booleanReports whether the battery is discharging.booleanReports whether the device is plugged in to an external power source.protected abstract List<PowerSource> Returns a fresh list of power sources for this platform, used byAbstractPowerSource.updateAttributes().toString()booleanUpdates statistics on this battery.
-
Constructor Details
-
MacPowerSource
protected MacPowerSource(String psName, String psDeviceName, double psRemainingCapacityPercent, double psTimeRemainingEstimated, double psTimeRemainingInstant, double psPowerUsageRate, double psVoltage, double psAmperage, boolean psPowerOnLine, boolean psCharging, boolean psDischarging, PowerSource.CapacityUnits psCapacityUnits, int psCurrentCapacity, int psMaxCapacity, int psDesignCapacity, int psCycleCount, String psChemistry, LocalDate psManufactureDate, String psManufacturer, String psSerialNumber, double psTemperature) Creates a MacPowerSource.- Parameters:
psName- power source namepsDeviceName- device namepsRemainingCapacityPercent- remaining capacity percentagepsTimeRemainingEstimated- estimated time remainingpsTimeRemainingInstant- instant time remainingpsPowerUsageRate- power usage ratepsVoltage- voltagepsAmperage- amperagepsPowerOnLine- whether on AC powerpsCharging- whether chargingpsDischarging- whether dischargingpsCapacityUnits- capacity unitspsCurrentCapacity- current capacitypsMaxCapacity- max capacitypsDesignCapacity- design capacitypsCycleCount- cycle countpsChemistry- chemistrypsManufactureDate- manufacture datepsManufacturer- manufacturerpsSerialNumber- serial numberpsTemperature- temperature
-
-
Method Details
-
buildPowerSources
protected static List<PowerSource> buildPowerSources(IOKitProvider ioKit, double timeRemainingEstimated, List<MacPowerSource.PowerSourceData> sources, MacPowerSource.PowerSourceFactory factory) Reads theAppleSmartBatteryregistry entry (viaioKit) and merges it with the per-source IOPS readings into a list of power sources.Mac PowerSource information comes from two sources: the IORegistry's
AppleSmartBatteryentry (battery-wide fields, read here through the sharedIOKitProvider) and the IOKit's IOPS functions (one entry per power source, read natively by the caller intosources).- Parameters:
ioKit- the IOKit provider backing the registry readtimeRemainingEstimated- the estimated time remaining (-1 unknown, -2 unlimited) from IOPSsources- the present power sources read from the IOPS listfactory- creates the platform-specific instance- Returns:
- a list of power sources, one per element of
sources
-