C8yEditableDevice

public class C8yEditableDevice : ObservableObject, Equatable

Use this class directly from a SwiftUI Form View to allow the wrapped device to be edited.

Changes to fields are published to the attribute onChange and can be acted on in your View with the following code. Duplicates are removed and changes are debounced into 1 event every 3 seconds, this means you could automatically persist changes to Cumulocity via the method C8yAssetCollection.saveObject(_) without having it called on each key press made by the user.

VStack {
    ...
}.onReceive(self.editableDevice.onChange) { editableDevice in

    do {
        try self.assetCollection.saveObject(editableDevice.toDevice()) { success, error in

        }
    } catch {
        print("error \(error.localizedDescription)")
    }
}
  • Declaration

    Swift

    public static func == (lhs: C8yEditableDevice, rhs: C8yEditableDevice) -> Bool
  • true if changes have been made to any of the attributes, you will need to set it back to false explicitly once changed e.g. after saving changes via the onChange publisher

    Declaration

    Swift

    public var haveChanges: Bool
  • external id to be modified.

    Declaration

    Swift

    @Published
    public var externalId: String { get set }
  • associated external id type of external id

    Declaration

    Swift

    @Published
    public var externalIdType: String { get set }
  • Read only copy of Cumulocity internal id for device, empty String if editing a new device that has not yet been submitted to Cumulocity

    Declaration

    Swift

    @Published
    public private(set) var c8yId: String { get set }
  • Name of the device to be edited

    Declaration

    Swift

    @Published
    public var name: String { get set }
  • The device type

    Declaration

    Swift

    @Published
    public var type: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var revision: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var firmware: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var supplier: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var model: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var notes: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var requiredResponseInterval: Int { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var networkType: C8yNetworkType { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var networkProvider: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var networkInstance: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var networkAppKey: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var networkAppEUI: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var category: C8yDevice.DeviceCategory { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var webLink: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var addressLine: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var city: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var postCode: String { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var country: String { get set }
  • Returns whether the device has been via the associated network. This field reflects last status from Cumulocity unless the network settings change

    Declaration

    Swift

    public var isDeployed: Bool { get }
  • Returns true if this device has not been saved to Cumulocity

    Declaration

    Swift

    public var isNew: Bool { get }
  • Use this publisher to listen for changes to the external id, removes duplicates and debounces to minimise events to maximum 1 every 3 seconds

    Declaration

    Swift

    public var externalIdChanged: AnyPublisher<String, Never> { get }
  • Use this publisher to listen for changes to any of device attribute, removes duplicates and debounces to minimise events to maximum 1 every 3 seconds.

    Declaration

    Swift

    public var onChange: AnyPublisher<C8yEditableDevice, Never> { get }
  • Default constructor to manage a new blank editable device

    Declaration

    Swift

    public init()
  • Constructor to allow an existing device to be edited.

    Declaration

    Swift

    public convenience init(deviceWrapper: C8yMutableDevice)
  • Constructor to allow an existing device to be edited.

    Declaration

    Swift

    public convenience init(_ device: C8yDevice)
  • Constructor for new device with the given attributes

    Declaration

    Swift

    public init(_ id: String, name: String, supplierName: String?, modelName: String, category: C8yDevice.DeviceCategory, operations: [String], revision: String?, firmware: String?, requiredResponseInterval: Int)
  • Clears all of the editable fields without triggering change event publishers

    Declaration

    Swift

    public func clear()
  • Returns true if the minimum number of fields for a device in Cumulocity have been assigned

    Declaration

    Swift

    public func isValid(_ willDeploy: Bool) -> Bool

    Parameters

    willDeploy

    if set to true network parameters must be fully specified; if false networking fields are ignored

    Return Value

    true if minimum fields are set,

  • Returns a C8yDevice instance with all of the edited fields included

    Declaration

    Swift

    public func toDevice() -> C8yDevice
  • Returns a C8yDevice instance with all of the edited fields included and the provided GPS position

    Declaration

    Swift

    public func toDevice(_ loc: CLLocation?) -> C8yDevice
  • Returns a C8yDevice instance with all of the edited fields included and the provided GPS position

    Declaration

    Swift

    public func toDevice(_ position: C8yManagedObject.Position?) -> C8yDevice
  • Undocumented

    Declaration

    Swift

    public func mergeDevices(_ c8yDevice: C8yDevice, group: C8yGroup? = nil)