What's New / Connectivity & Hardware

What's new in EnergyKit

+15 New~3 DeprecatediOS

EnergyKit is Apple's framework for reading home electrical load and electric vehicle data. Its types cover charging reasons, HVAC and EV load events, electrical measurements, and load device descriptions.

The 27 SDK adds 15 APIs and deprecates 3. New types are the ElectricVehicleChargingReason enum, the PerformanceMetrics and ElectricVehicleStatusEvent structs, and the ElectricalLoadDevice struct, plus new initializers and a deviceName property on ElectricHVACLoadEvent and ElectricVehicleLoadEvent. The three deprecations are all initializers: ElectricHVACLoadEvent.init, ElectricVehicleLoadEvent.init, and ElectricVehicleLoadEvent.ElectricalMeasurement.init, each replaced by a new init in this release.

New

15
struct

ElectricalLoadDevice

NewiOS
public struct ElectricalLoadDevice : Codable, Sendable, Hashable

Represents an electrical load device for event submission.

Provides a unified way to identify devices across ElectricVehicleLoadEvent, ElectricHVACLoadEvent, and ElectricVehicleStatusEvent.

Declaration
public struct ElectricalLoadDevice : Codable, Sendable, Hashable {

    /// The type of electrical load device
    public enum DeviceType : String, Codable, Equatable, Hashable, Sendable {

        case hvac

        case electricVehicle

        /// Creates a new instance with the specified raw value.
        ///
        /// If there is no value of the type that corresponds with the specified raw
        /// value, this initializer returns `nil`. For example:
        ///
        ///     enum PaperSize: String {
        ///         case A4, A5, Letter, Legal
        ///     }
        ///
        ///     print(PaperSize(rawValue: "Legal"))
        ///     // Prints "Optional(PaperSize.Legal)"
        ///
        ///     print(PaperSize(rawValue: "Tabloid"))
        ///     // Prints "nil"
        ///
        /// - Parameter rawValue: The raw value to use for the new instance.
        public init?(rawValue: String)

        /// The raw type that can be used to represent all values of the conforming
        /// type.
        ///
        /// Every distinct value of the conforming type has a corresponding unique
        /// value of the `RawValue` type, but there may be values of the `RawValue`
        /// type that don't have a corresponding value of the conforming type.
        @available(macOS 27.0, iOS 27.0, *)
        @available(tvOS, unavailable)
        @available(watchOS, unavailable)
        @available(visionOS, unavailable)
        public typealias RawValue = String

        /// The corresponding value of the raw type.
        ///
        /// A new instance initialized with `rawValue` will be equivalent to this
        /// instance. For example:
        ///
        ///     enum PaperSize: String {
        ///         case A4, A5, Letter, Legal
        ///     }
        ///
        ///     let selectedSize = PaperSize.Letter
        ///     print(selectedSize.rawValue)
        ///     // Prints "Letter"
        ///
        ///     print(selectedSize == PaperSize(rawValue: selectedSize.rawValue)!)
        ///     // Prints "true"
        public var rawValue: String { get }
    }

    /// The device identifier.
    public let id: String

    /// The device name.
    ///
    /// The max length is `250 UTF-16` characters.
    /// Names that violate these rules are automatically sanitized:
    /// - Isn't empty, and less than or equal to 250 characters.
    /// - Contains only alphanumeric, whitespace, punctuation, or symbol characters.
    public let name: String

    /// The type of electrical load device.
    public let type: ElectricalLoadDevice.DeviceType

    /// Creates an electrical load device.
    ///
    /// - Parameters:
    ///   - id: The device's unique stable identifier.
    ///     The max length is `64 UTF-8` bytes. UUID strings are permitted.
    ///     The following are enforced as preconditions:
    ///     - Isn't empty, and less than or equal to 64 UTF-8 bytes.
    ///     - Uses only alphanumeric, space, hyphen, and apostrophe characters.
    ///     - Starts and ends with an alphanumeric character.

Truncated.

extension

ElectricalLoadDevice.DeviceType

NewiOS
extension ElectricalLoadDevice.DeviceType : RawRepresentable
Declaration
extension ElectricalLoadDevice.DeviceType : RawRepresentable {
}
enum

ElectricVehicleChargingReason

NewiOS
public enum ElectricVehicleChargingReason

Reasons that explain electric vehicle charging state transitions in ElectricVehicleStatusEvent.

Declaration
public enum ElectricVehicleChargingReason {

    /// Reasons for active charging state in ``ElectricVehicleStatusEvent``.
    ///
    /// Indicates why the vehicle is actively charging.
    public enum ActiveReason : Codable, Equatable, Hashable, Sendable, CaseIterable {

        /// Cleaner energy is available on the grid.
        case cleanerEnergyAvailable

        /// Lower electricity rates are available.
        case lowerElectricityRatesAvailable

        /// The user manually started charging.
        case userInitiated

        /// Charging started at a scheduled time.
        case scheduledStart

        /// The user manually resumed charging.
        case userResumed

        /// Charging resumed at a scheduled time.
        case scheduledResume

        /// A demand response event ended.
        case demandResponseEnded

        /// Battery thermal management completed.
        case batteryThermalManagementCompleted

        /// Battery health management completed.
        case batteryHealthManagementCompleted

        /// A charger fault was cleared.
        case chargerFaultCleared

        /// Sufficient power was restored for charging.
        case sufficientPowerRestored

        /// Load balancing completed.
        case loadBalancingCompleted

        /// The reason is unknown.
        case unknown

        /// Returns a Boolean value indicating whether two values are equal.
        ///
        /// Equality is the inverse of inequality. For any values `a` and `b`,
        /// `a == b` implies that `a != b` is `false`.
        ///
        /// - Parameters:
        ///   - lhs: A value to compare.
        ///   - rhs: Another value to compare.
        public static func == (a: ElectricVehicleChargingReason.ActiveReason, b: ElectricVehicleChargingReason.ActiveReason) -> Bool

        /// A type that can represent a collection of all values of this type.
        @available(macOS 27.0, iOS 27.0, *)
        @available(tvOS, unavailable)
        @available(watchOS, unavailable)
        @available(visionOS, unavailable)
        public typealias AllCases = [ElectricVehicleChargingReason.ActiveReason]

        /// A collection of all values of this type.
        nonisolated public static var allCases: [ElectricVehicleChargingReason.ActiveReason] { get }

        /// Encodes this value into the given encoder.
        ///
        /// If the value fails to encode anything, `encoder` will encode an empty
        /// keyed container in its place.
        ///
        /// This function throws an error if any values are invalid for the given
        /// encoder's format.
        ///
        /// - Parameter encoder: The encoder to write data to.
        public func encode(to encoder: any Encoder) throws

        /// Hashes the essential components of this value by feeding them into the
        /// given hasher.
        ///

Truncated.

struct

ElectricVehicleStatusEvent

NewiOS
public struct ElectricVehicleStatusEvent : ElectricalLoadEventProtocol, Hashable

An event representing the status of an electric vehicle while connected to a charger.

Status events are discrete snapshots that capture the vehicle's state independent of charging sessions. They complement ElectricVehicleLoadEvent by providing visibility into why the vehicle isn't charging when plugged in, helping answer product questions like "when will charging begin?"

Unlike ElectricVehicleLoadEvent which tracks session-based energy flow with continuity, status events are point-in-time observations without session context.

Declaration
public struct ElectricVehicleStatusEvent : ElectricalLoadEventProtocol, Hashable {

    /// The status of an electric vehicle relative to its charger connection.
    ///
    /// Status is a discrete snapshot without session continuity, complementing
    /// ``ElectricVehicleLoadEvent`` which tracks session-based energy flow.
    public enum Status : Codable, Equatable, Hashable, Sendable {

        /// Charger has been physically connected to the vehicle
        ///
        /// This status indicates initial connection before any charging logic determines
        /// whether to begin charging or remain idle.
        case chargerPluggedIn

        /// Vehicle is actively charging
        ///
        /// The associated reason indicates why charging started (Begin) or resumed (Resume).
        /// Use Begin reasons when charging starts from an idle state, and Resume reasons
        /// when charging continues after being paused.
        case chargingActive(ElectricVehicleChargingReason.ActiveReason)

        /// Charger is connected but the vehicle is idle (not charging)
        ///
        /// The associated reason explains why charging is not active.
        /// Use Pause reasons when charging was paused during a session, and End reasons
        /// when a charging session completed or stopped.
        case chargingIdle(ElectricVehicleChargingReason.IdleReason)

        /// Charger has been physically disconnected from the vehicle
        case chargerUnplugged

        /// Returns a Boolean value indicating whether two values are equal.
        ///
        /// Equality is the inverse of inequality. For any values `a` and `b`,
        /// `a == b` implies that `a != b` is `false`.
        ///
        /// - Parameters:
        ///   - lhs: A value to compare.
        ///   - rhs: Another value to compare.
        public static func == (a: ElectricVehicleStatusEvent.Status, b: ElectricVehicleStatusEvent.Status) -> Bool

        /// Encodes this value into the given encoder.
        ///
        /// If the value fails to encode anything, `encoder` will encode an empty
        /// keyed container in its place.
        ///
        /// This function throws an error if any values are invalid for the given
        /// encoder's format.
        ///
        /// - Parameter encoder: The encoder to write data to.
        public func encode(to encoder: any Encoder) throws

        /// Hashes the essential components of this value by feeding them into the
        /// given hasher.
        ///
        /// Implement this method to conform to the `Hashable` protocol. The
        /// components used for hashing must be the same as the components compared
        /// in your type's `==` operator implementation. Call `hasher.combine(_:)`
        /// with each of these components.
        ///
        /// - Important: In your implementation of `hash(into:)`,
        ///   don't call `finalize()` on the `hasher` instance provided,
        ///   or replace it with a different instance.
        ///   Doing so may become a compile-time error in the future.
        ///
        /// - Parameter hasher: The hasher to use when combining the components
        ///   of this instance.
        public func hash(into hasher: inout Hasher)

        /// The hash value.
        ///
        /// Hash values are not guaranteed to be equal across different executions of
        /// your program. Do not save hash values to use during a future execution.
        ///
        /// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
        ///   conform to `Hashable`, implement the `hash(into:)` requirement instead.
        ///   The compiler provides an implementation for `hashValue` for you.
        public var hashValue: Int { get }

        /// Creates a new instance by decoding from the given decoder.

Truncated.

typealias

ElectricalLoadDevice.DeviceType.RawValue

NewiOS
public typealias RawValue = String

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

var

ElectricHVACLoadEvent.deviceName

NewiOS
public var deviceName: String { get }

A human-readable name for the device.

The max length is 250 UTF-16 characters. Names that violate these rules are automatically sanitized:

  • Isn't empty, and less than or equal to 250 characters.
  • Contains only alphanumeric, whitespace, punctuation, or symbol characters.
init

ElectricHVACLoadEvent.init

NewiOS
public init(timestamp: Date, measurement: ElectricHVACLoadEvent.ElectricalMeasurement, session: ElectricHVACLoadEvent.Session, device: ElectricalLoadDevice)

Creates an electric HVAC load event.

Parameters

timestamp
The timestamp for when the event occurred.
measurement
The electricity consumption of a device.
session
The session information
device
The electrical load device that generated this event.
typealias

ElectricVehicleChargingReason.ActiveReason.AllCases

NewiOS
public typealias AllCases = [ElectricVehicleChargingReason.ActiveReason]

A type that can represent a collection of all values of this type.

typealias

ElectricVehicleChargingReason.IdleReason.AllCases

NewiOS
public typealias AllCases = [ElectricVehicleChargingReason.IdleReason]

A type that can represent a collection of all values of this type.

var

ElectricVehicleLoadEvent.deviceName

NewiOS
public var deviceName: String { get }

A human-readable name for the device.

The max length is 250 UTF-16 characters. Names that violate these rules are automatically sanitized:

  • Isn't empty, and less than or equal to 250 characters.
  • Contains only alphanumeric, whitespace, punctuation, or symbol characters.
init

ElectricVehicleLoadEvent.init

NewiOS
public init(timestamp: Date, measurement: ElectricVehicleLoadEvent.ElectricalMeasurement, session: ElectricVehicleLoadEvent.Session, device: ElectricalLoadDevice)

Creates an electric vehicle load event.

Parameters

timestamp
The timestamp for when the event occurred.
measurement
The electricity consumption or generation of a device.
session
The session information
device
The electrical load device that generated this event.
init

ElectricVehicleLoadEvent.ElectricalMeasurement.init

NewiOS
public init(stateOfCharge: Int, direction: ElectricityFlowDirection, power: Measurement<UnitPower>, energy: Measurement<UnitEnergy>, performanceMetrics: ElectricVehicleLoadEvent.ElectricalMeasurement.PerformanceMetrics?)

Creates an electrical measurement with optional performance metrics.

var

ElectricVehicleLoadEvent.ElectricalMeasurement.performanceMetrics

NewiOS
public var performanceMetrics: ElectricVehicleLoadEvent.ElectricalMeasurement.PerformanceMetrics? { get }

Performance metrics for this measurement, or nil if unavailable.

struct

ElectricVehicleLoadEvent.ElectricalMeasurement.PerformanceMetrics

NewiOS
public struct PerformanceMetrics : Codable, Sendable, Hashable

Performance metrics for the current electrical measurement.

Declaration
public struct PerformanceMetrics : Codable, Sendable, Hashable {

    /// Estimated range based on current state of charge
    public let estimatedRange: Measurement<UnitLength>?

    /// Battery pack temperature, or `nil` if unavailable.
    public let batteryTemperature: Measurement<UnitTemperature>?

    /// Creates performance metrics for the current measurement.
    /// - Parameters:
    ///   - estimatedRange: Current estimated range, or `nil` if unavailable
    ///   - batteryTemperature: Current battery temperature, or `nil` if unavailable
    public init(estimatedRange: Measurement<UnitLength>? = nil, batteryTemperature: Measurement<UnitTemperature>? = nil)

    /// Returns a Boolean value indicating whether two values are equal.
    ///
    /// Equality is the inverse of inequality. For any values `a` and `b`,
    /// `a == b` implies that `a != b` is `false`.
    ///
    /// - Parameters:
    ///   - lhs: A value to compare.
    ///   - rhs: Another value to compare.
    public static func == (a: ElectricVehicleLoadEvent.ElectricalMeasurement.PerformanceMetrics, b: ElectricVehicleLoadEvent.ElectricalMeasurement.PerformanceMetrics) -> Bool

    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, `encoder` will encode an empty
    /// keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given
    /// encoder's format.
    ///
    /// - Parameter encoder: The encoder to write data to.
    public func encode(to encoder: any Encoder) throws

    /// Hashes the essential components of this value by feeding them into the
    /// given hasher.
    ///
    /// Implement this method to conform to the `Hashable` protocol. The
    /// components used for hashing must be the same as the components compared
    /// in your type's `==` operator implementation. Call `hasher.combine(_:)`
    /// with each of these components.
    ///
    /// - Important: In your implementation of `hash(into:)`,
    ///   don't call `finalize()` on the `hasher` instance provided,
    ///   or replace it with a different instance.
    ///   Doing so may become a compile-time error in the future.
    ///
    /// - Parameter hasher: The hasher to use when combining the components
    ///   of this instance.
    public func hash(into hasher: inout Hasher)

    /// The hash value.
    ///
    /// Hash values are not guaranteed to be equal across different executions of
    /// your program. Do not save hash values to use during a future execution.
    ///
    /// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
    ///   conform to `Hashable`, implement the `hash(into:)` requirement instead.
    ///   The compiler provides an implementation for `hashValue` for you.
    public var hashValue: Int { get }

    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    ///
    /// - Parameter decoder: The decoder to read data from.
    public init(from decoder: any Decoder) throws
}
typealias

ElectricVehicleStatusEvent.ID

NewiOS
public typealias ID = UUID

A type representing the stable identity of the entity associated with an instance.

Deprecated

3
init

ElectricHVACLoadEvent.init

DeprecatediOS
public init(timestamp: Date, measurement: ElectricHVACLoadEvent.ElectricalMeasurement, session: ElectricHVACLoadEvent.Session, deviceID: String)

Creates an ElectricHVACLoadEvent

Parameters

timestamp
The timestamp for when the event occurred.
measurement
The electricity consumption of a device.
session
The session information
deviceID
The device's unique stable identifier.

ReturnsThrows: EnergyKit.invalidDeviceID

init

ElectricVehicleLoadEvent.init

DeprecatediOS
public init(timestamp: Date, measurement: ElectricVehicleLoadEvent.ElectricalMeasurement, session: ElectricVehicleLoadEvent.Session, deviceID: String)

Creates an ElectricVehicleLoadEvent

Parameters

timestamp
The timestamp for when the event occurred.
measurement
The electricity consumption or generation of a device.
session
The session information
deviceID
The device's unique stable identifier.

ReturnsThrows: EnergyKit.invalidDeviceID

init

ElectricVehicleLoadEvent.ElectricalMeasurement.init

DeprecatediOS
public init(stateOfCharge: Int, direction: ElectricityFlowDirection, power: Measurement<UnitPower>, energy: Measurement<UnitEnergy>)

Initializes an electrical measurement for the electrical load event.

Parameters

stateOfCharge
The remaining capacity available in a battery
direction
Specifies whether electricity is being imported from the grid or exported to the grid.
power
Power in milli-watts
energy
The accumulated electrical energy consumed or generated by the device in milli-watt hours. The accumulator is reset on end.

No APIs match your filter.

← More in Connectivity & Hardware