Classes

The following classes are available globally.

  • Cache

    This class functions as a shared container of queries which can be live-updated from subscriptions. For example, you might combine HARequestType.getStates with HAEventType.stateChanged to get all states and be alerted for changes.

    All methods on this class are thread-safe.

    Important

    You, or another object, must keep a strong reference to this cache or a HACancellable returned to you; the cache does not retain itself directly. This includes map values.

    Note

    Use shouldResetWithoutSubscribers to control whether the subscription is disconnected when not in use.

    Note

    Use map(_:) to make quasi-streamed changes to the cache contents.

    See more

    Declaration

    Swift

    public class HACache<ValueType>
  • Container for caches

    You can create your own cache accessible in this container like so:

    Create a key to represent your cache:

    struct YourValueTypeKey: HACacheKey {
        func create(connection: HAConnection) -> HACache<YourValueType> {
            return HACache(connection: connection, populate: , subscribe: )
        }
    }
    

    Add a convenience getter to the container itself:

    extension HACachesContainer {
        var yourValueType: HACache<YourValueType> { self[YourValueTypeKey.self] }
    }
    

    Then, access it from a connection like connection.caches.yourValueType.

    See more

    Declaration

    Swift

    public class HACachesContainer
  • URLSession delegate for HAKit REST API calls that supports custom certificate handling

    This delegate handles both client certificate authentication (mTLS) and custom server certificate validation through the HACertificateProvider protocol.

    Example usage:

    struct MyCertificateProvider: HACertificateProvider {
        func provideClientCertificate(for challenge: ...) {
            // Provide client certificate from keychain
        }
    
        func evaluateServerTrust(_ serverTrust: ...) {
            // Validate self-signed or custom CA certificates
        }
    }
    
    let provider = MyCertificateProvider()
    let delegate = HAURLSessionDelegate(certificateProvider: provider)
    let session = URLSession(configuration: .ephemeral, delegate: delegate, delegateQueue: nil)
    let connection = HAKit.connection(configuration: config, urlSession: session)
    
    See more

    Declaration

    Swift

    public class HAURLSessionDelegate : NSObject, URLSessionDelegate
  • Wrapper around a value with a lock

    Provided publicly as a convenience in case the library uses it anywhere.

    See more

    Declaration

    Swift

    public class HAProtected<ValueType>