C8yDevice
public struct C8yDevice : C8yObject
Encapsulates a c8y C8yManagedObject
managed object and treats it as a device exposing attributes and methods typically attributed to a device
such as serialNumber
, model
Also includes a number of custom atributes to better categorise devices such as deviceCategory
, attachments
and relayState
-
Used to categorise the device typex
See moreDeclaration
Swift
public enum DeviceCategory : String, CaseIterable, Hashable, Identifiable, Encodable
-
client side id, required by SwiftUI for display purposes
Declaration
Swift
public var id: String
-
Dictionary of all related external id’s. Not populated by default, unless you use the class
C8yAssetCollection
to manage your groups and devicesDeclaration
Swift
public var externalIds: [String : C8yExternalId]
-
Implemented in accordance to protocol
C8yObject
, always returns .deviceDeclaration
Swift
public var groupCategory: C8yGroupCategory { get }
-
Implemented in accordance to protocol
C8yObject
, always returns .na as it is a deviceDeclaration
Swift
public var orgCategory: C8yOrganisationCategory { get }
-
Returns the category to which the device belongs. Represented by a custom attribute ‘xC8yDeviceCategory’ in the wrapped managed object
Declaration
Swift
public var deviceCategory: DeviceCategory { get set }
-
Undocumented
Declaration
Swift
public var alarmsCount: Int { get }
-
Convenience attribute to determin if the device is operating correctly or not.
nominal - available and no alarms present operating - available with warning alarms failing - avaiable with major alarms error - unavailable or available with critical alarms offline - unavailable, no alarms present maintenance - either unavailable or unavailable and all alarms ignored
Declaration
Swift
public var operationalLevel: C8yOperationLevel { get }
-
Returns true if the associated device is a switch/relay type device
Declaration
Swift
public var isRelay: Bool { get }
-
Reflects current state of relay either open, closed or pending Refer to
C8yMutableDevice
if you want to change the relay stateDeclaration
Swift
public var relayState: C8yManagedObject.RelayStateType? { get }
-
Returns the Cumulocity derived status of the device. Cumulocity determines the availability of the device based on the last time it received any data from the device. Cumulocity flags the device as UNAVAILABLE If nothing has been received within the devices
requiredResponseInterval
time period. Unless If therequiredResponseInterval
is set to -1, in which case it returns the status of MAINTENANCE.Refer to
C8yMutableDevice
if you want to change therequriedResponseInterval
or POST a managed object to c8y using the constructorC8yManagedObject.init(_:requiredAvailability:)
and serviceC8yManagedObjectService.post(_:)
Declaration
Swift
public var status: C8yManagedObject.AvailabilityStatus { get }
-
Returns the device’s serial number if available
Declaration
Swift
public internal(set) var serialNumber: String? { get set }
-
String value describing the supplier of the device or ‘generic’ if not defined
Declaration
Swift
public internal(set) var supplier: String { get set }
-
String value describing the model of the device or an empty string if not defined
Declaration
Swift
public internal(set) var model: String { get set }
-
String value describing the revision of the device or nil if not available
Declaration
Swift
public internal(set) var revision: String? { get set }
-
String value describing the device’s firmware version or nil if not available
Declaration
Swift
public var firmware: String? { get }
-
String list of operation types that are supported by this device. e.g. c8y_Restart etc.
Declaration
Swift
public var supportedOperations: [String] { get }
-
Network settings describing what network the device uses to communicate.
Declaration
Swift
public var network: C8yAssignedNetwork { get set }
-
Used in relation to
network
to determine if the device has been provisioned within the required network. This attribute should be updated to reflect whether this has been done. The precise details for provisioning are network specific and may in part be manual.Refer to the class
C8yNetworks
for more informationDeclaration
Swift
public internal(set) var isDeployed: Bool { get set }
-
Arbritary text associated with the device or nil if note available.
Declaration
Swift
public var notes: String? { get set }
-
Date/time that the Managed Object represeting this device was last updated in Cumulocity
Declaration
Swift
public var lastUpdated: Date? { get }
-
Date/time that Cumulocity last received some kind of activity from the device. This is used to determine the devices
status
in conjunction withrequiredResponseInterval
Declaration
Swift
public var lastMessage: Date? { get }
-
Value in seconds used to determine device availability, i.e. the device is considered unavailable if no activity is received from the device within the time period given here. The device is considered to be in maintenance mode if this is set to -1. Incidentally all alarms triggers are ignored if this value indicates maintenance mode.
Refer to
C8yMutableDevice
if you want to change therequriedResponseInterval
or POST a managed object to c8y using the constructorC8yManagedObject.init(_:requiredAvailability:)
and serviceC8yManagedObjectService.post(_:)
Declaration
Swift
public var requiredResponseInterval: Int? { get }
-
Custom attribute to allow a web url to be associated with the device. Useful if you want to provide a link to external technical documentation etc. The attribute is stored in the c8y managed object as ‘xWebLink’
Declaration
Swift
public var webLink: String? { get set }
-
This attribute only applies to devices that connect to Cumulocity using push notifications rather than the more typical polling mechanism whereby Cumulocity through an agent queries the device.
If applicable returns true if the device is currently connected and sending data, false indicates the device has disconnected.
Declaration
Swift
public var connected: Bool { get }
-
Alarm summary for device.
Declaration
Swift
public internal(set) var alarms: C8yManagedObject.ActiveAlarmsStatus? { get set }
-
Defines the type of measurements that can be collected for this device and gives an indication to how they should be displayed
Declaration
Swift
public var dataPoints: C8yDataPoints? { get }
-
Represents the wrapped Managed Object that defines this device
Declaration
Swift
public var wrappedManagedObject: C8yManagedObject
-
String representing the hierachy in which device belongs, i.e. list the parent group in which device is nested. This is only provided if you used
C8yAssetCollection
to fetch the deviceDeclaration
Swift
public internal(set) var hierachy: String? { get }
-
List of attachment references associated with this device. The attachments themselves can be fetched via the
C8yBinariesService
using the references here.The attachments are stored in the managed object in c8y using the attribute ‘xAttachmentIds’
Declaration
Swift
public internal(set) var attachments: [String] { get }
-
List of child devices associated with this device, only applicable for router or gateway type devices.
Declaration
Swift
public internal(set) var children: [AnyC8yObject] { get }
-
Creates a new empty device with the given external id and type
Declaration
Swift
public init(externalId: String, type: String)
Parameters
externalId
string representing external id
type
description of external id type e.g. ‘c8y_Serial’
-
Creates a device based on the underlying managed object
Declaration
Swift
public init(_ m: C8yManagedObject) throws
Parameters
m
The managed object representing the device
-
Declaration
Swift
public static func == (lhs: C8yDevice, rhs: C8yDevice) -> Bool
-
Convenience method to determine if the given device matches all of the same attributes as this device
Declaration
Swift
public func isDifferent(_ device: C8yDevice) -> Bool
-
Returns a string representing the default external id and type if provided or if not the c8y internal id.
Format is key=‘value’ e.g. c8y_Serial=122434344 c8y_id=9393
Declaration
Swift
public func defaultIdAndType() -> String
-
Returns the default external id if provided or if not the c8y internal id.
Declaration
Swift
public func defaultId() -> String?
-
Returns true if the given external id matches this device
Declaration
Swift
public func match(forExternalId id: String, type: String?) -> Bool
Parameters
forExternalId
the value, must match the value for the associated type
type
describes external id, must match a type given in
externalIds
Return Value
true if a match is found, false otherwise
-
Returns true if an external id and type can be found in the formatted string, which then matches one of the devices.
String could be formatted as
c8y_Serial=3434343 or 3434343 (if no separator given)
Declaration
Swift
public func matchRawStringIdentifier(line: String, separator: String.Element?) -> Bool
Parameters
line
formatted text string containing the id and type
separator
Optional separator determing how the type and value are provided. If nil assume type is not provided and will attempt to match one of the lines to any external id
Return Value
true if a match was made
-
Returns a UIImage representing a QR code of the default id of this device
Declaration
Swift
public func generateQRCodeImage() throws -> UIImage
Return Value
UIImage representing a QR code
-
Returns a UIImage representing a QR code for the given external id type of this device. Resorts to the default id of the device If the external id is not found for the given type.
Declaration
Swift
public func generateQRCodeImage(forType type: String?) throws -> UIImage
Return Value
UIImage representing a QR code
-
Thrown from init if wrapped Managed Object is not a device asset
See moreDeclaration
Swift
public enum DeviceDecodingError : Error