private static NEEODevice BuildAndRegisterDevice(DeviceBuilder device, string adapterName) { NEEOOptionalCallbacks optionalCallbacks = null; var deviceModel = device.Build(adapterName); if (deviceModel.SubscriptionFunction != null) { NEEONotificationFunc boundNotificationFunction = async(param) => { NEEOEnvironment.Logger.LogDebug($"Device | notification {param.Component}.{param.Value}"); await BrainModule.SendNotification(param, deviceModel.AdapterName); }; if (device._hasPowerStateSensor) { NEEOPowerNotificationFunc powerOnNotificationFunction = async(uniqueDeviceId) => { var msg = new NEEONotification { UniqueDeviceId = uniqueDeviceId, Component = "powerstate", Value = true }; await BrainModule.SendNotification(msg, deviceModel.AdapterName); }; NEEOPowerNotificationFunc powerOffNotificationFunction = async(uniqueDeviceId) => { var msg = new NEEONotification { UniqueDeviceId = uniqueDeviceId, Component = "powerstate", Value = false }; await BrainModule.SendNotification(msg, deviceModel.AdapterName); }; optionalCallbacks = new NEEOOptionalCallbacks(powerOnNotificationFunction, powerOffNotificationFunction); } deviceModel.SubscriptionFunction(boundNotificationFunction, optionalCallbacks); } return(deviceModel); }
public NEEOOptionalCallbacks(NEEOPowerNotificationFunc powOn, NEEOPowerNotificationFunc powOff) { PowerOnNotificationFunction = powOn; PowerOffNotificationFunction = powOff; }