Exemple #1
0
        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);
        }
Exemple #2
0
        public static async Task <bool> SendNotification(NEEONotification msg, string deviceId)
        {
            if (_notification == null)
            {
                _logger.LogWarning("Brain | server not started, ignore notification");
                return(false);
            }
            string notificationKey = await _notificationMapping.GetNotificationKey(msg.UniqueDeviceId, deviceId, msg.Component);

            if (notificationKey != null)
            {
                _logger.LogDebug($"Brain | notificationKey {notificationKey}");
                Notification.MessageData notificationData = new Notification.MessageData {
                    Type = notificationKey, Data = msg.Value
                };
                return(await _notification.Send(notificationData));
            }
            return(false);
        }