Skip to content

Commit

Permalink
fourth attempt at bounded property notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Aug 3, 2023
1 parent d2be1cc commit 37f1977
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ public struct OcaBoundedDeviceProperty<
if object.notificationTasks[propertyID] == nil {
object.notificationTasks[propertyID] = Task<(), Error> {
for try await value in self.async {
try? await storage.notifySubscribers(object: object, value.value)
try? await storage.notifySubscribers(object: object, value)
}
}
}
}

func notifySubscribers(object: OcaRoot, _ newValue: Value) async throws {
let event = OcaEvent(emitterONo: object.objectNumber, eventID: OcaPropertyChangedEventID)
let encoder = Ocp1BinaryEncoder()
let parameters = OcaPropertyChangedEventData<Value>(
propertyID: propertyID,
propertyValue: newValue,
changeType: .currentChanged
)

try await object.deviceDelegate?.notifySubscribers(
event,
parameters: try encoder.encode(parameters)
)
}

public static subscript<T: OcaRoot>(
_enclosingInstance object: T,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<T, OcaBoundedPropertyValue<Value>>,
Expand Down

0 comments on commit 37f1977

Please sign in to comment.