C8yGroup
public struct C8yGroup : C8yObject
Encapsulates a c8y C8yManagedObject
managed object and treats it as a group exposing attributes and methods typically attributed to managing a group.
Also includes a number of custom atributes to better categorise devices such as groupCategory
, info
etc.
-
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
in order to categorise the type of group e.g. physical building, room etc. or logical folder, division etc.Declaration
Swift
public var groupCategory: C8yGroupCategory { get set }
-
String representing the hierachy in which group 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 }
-
Custom attribute to locate the group if it represents a physical category such as Site, Building or Room.
Declaration
Swift
public var info: Info { get set }
-
Returns a list of all the subgroups associated with this group
Declaration
Swift
public var subGroups: [C8yGroup] { get }
-
Override default version to only return count of devices that have alarms and not the total number of alarms
Declaration
Swift
public var alarmsCount: Int { get }
-
Returns a list of all the subgroups and devices associated with this group
Declaration
Swift
public internal(set) var children: [AnyC8yObject] { get }
-
Represents the wrapped Managed Object that defines this group
Declaration
Swift
public var wrappedManagedObject: C8yManagedObject
-
Constructor to create a group for the given c8y managed object
Throws
throws Error if managed object does not reference a group assetDeclaration
Swift
public init(_ obj: C8yManagedObject) throws
-
Constructor to define a new group with the given attributes
Declaration
Swift
public init(_ c8yId: String?, name: String, isTopLevelGroup: Bool, category: C8yGroupCategory, notes: String?)
Parameters
c8yId
required if you want to create a group for an existing c8y group, nil if you want to create a new group
name
The name attributed to the group
isTopLevelGroup
if true the group will be visible in groups menu navigation on the left hand side of the Cumulocity web app. Otherwise will only be available as a sub-folder once you have assigned it to a parent group
notes
optional notes to be associated with the group
-
Declaration
Swift
public static func == (lhs: C8yGroup, rhs: C8yGroup) -> Bool
-
Convenience method to determine if the given group matches all of the same attributes as this group
Declaration
Swift
public func isDifferent(_ group: C8yGroup) -> Bool
-
Convenience method to determine if the given device matches on of the devices associated with this group
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 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
-
Undocumented
Declaration
Swift
public func isPlannedForDate(_ date: Date) -> Bool
-
Returns true if the given external id matches one for this group
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 a sub-asset with the given internal id is found in this group or one its children
Declaration
Swift
public func contains(_ c8yId: String) -> Bool
Parameters
c8yId
internal id of the asset to check for
Return Value
true if found somewhere in groups children
-
returns the sub-group matching the given external id in this group or one of its children
Declaration
Swift
public func group(forExternalId id: String, ofType type: String) -> C8yGroup?
Parameters
ref
either name or internal id of asset for which we want to find its parent
Return Value
parent group of sub-asset or nil if the asset does not exist
-
returns the device within this group or one of its children for the given id
Declaration
Swift
public func device(withC8yId c8yId: String?) -> C8yDevice?
Parameters
c8yId
internal id of the device or group to be searched for
Return Value
Found device or nil if not found
-
returns the device within this group or one of its children for the given external id
Declaration
Swift
public func device(forExternalId id: String, ofType type: String) -> C8yDevice?
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
-
Adds the given asset to the group
Declaration
Swift
public mutating func addToGroup<T>(_ object: T) where T : C8yObject
Parameters
object
asset to be added to the group
-
Adds the given asset to the sub-group within this group one of its children
Declaration
Swift
public mutating func addToGroup<T>(c8yIdOfSubGroup c8yId: String, object: T) -> Bool where T : C8yObject
Parameters
c8yIdOfSubGroup
internal id of the sub group
object
asset to be added to the group
Return Value
true if the sub group was found and the asset added, false if the sub group cannot be found
-
Removes the specified asset from the group or sub group of one of its children
Declaration
Swift
public mutating func removeFromGroup(_ c8yId: String) -> Bool
Parameters
c8yId
id of the asset to be removed
Return Value
true if the asset was found and removed
-
Replaces the current asset in the group or sub group of one of its children
Declaration
Swift
public mutating func replaceInGroup<T>(_ object: T) -> Bool where T : C8yObject
Parameters
object
The object to be replaced
Return Value
true if the asset was found and replaced, false if not
-
Thrown from init if wrapped Managed Object is not a group asset
See moreDeclaration
Swift
public enum GroupDecodingError : Error
-
Represents a custom structure to allow more functional information to be associated with a group, such as contacts if it represents a physical entitiy or a planning date if it is to be used to group assets based on scheduling etc. etc.
The element is broken out into strings at the top level of the managed object to ensure that they can be viewed/edited using the standard c8y Property Editor widget
See moreDeclaration
Swift
public struct Info