Пример #1
0
        public async Task <ActionResult> NodeUpdate(NodeUpdateModel model)
        {
            await ZWaveLogStream(new { Timestamp = model.Timestamp.ToLocalTime(), Message = $"NodeUpdate: {model.NodeId}, {model.ValueType}: {model.Value}" });

            var device = jsonDatabaseService.Devices.FirstOrDefault(s => s.Source == DeviceSource.ZWave && s.SourceID == model?.NodeId.ToString());

            if (device != null)
            {
                var state = zwaveAPIService.ConvertParameterToEvent(model.ValueType, model.Value);

                logger.LogInformation($"ZWave.NodeUpdate :: {device.ID} :: NodeId:{model.NodeId}, ValueType:{model.ValueType}: Value:{model.Value}, ValueObjectType:{model.Value.GetType().Name} MappedState:{state}");
                await triggerService.FireTriggersFromDevice(device, state);
            }

            return(Ok());
        }
        public async Task <ActionResult <bool> > TelldusDeviceEvents(DeviceEventsModel model)
        {
            lock (duplicationRequestLock)
            {
                if (IsDuplicateRequest(model.DeviceID, model.Command, model.Parameter))
                {
                    return(Ok(false));
                }
            }

            await TelldusLogStream(new { Message = $"DEVICEID {model?.DeviceID}: {model?.Command.ToString()} ({model?.Parameter})" });

            var device = jsonDatabaseService.Devices.FirstOrDefault(s => s.Source == DeviceSource.Telldus && s.SourceID == model?.DeviceID.ToString());

            if (device != null)
            {
                var state = telldusAPIService.ConvertCommandToEvent(model.Command);

                logger.LogInformation($"Telldus.DeviceEvent :: {device.ID} :: DeviceId:{model?.DeviceID}, Command:{model?.Command.ToString()}, Parameter:{model?.Parameter}, MappedState:{state}");
                await triggerService.FireTriggersFromDevice(device, state);
            }

            return(Ok(true));
        }