コード例 #1
0
ファイル: RmsController.cs プロジェクト: skalpt/iris-rms
        public async Task <ActionResult <ApiResponse> > PostHeartbeat(RmsConfigModel model)
        {
            if (model == null)
            {
                return(new ApiResponse {
                    Status = Status.Error, Message = "model was empty"
                });
            }

            try
            {
                await FlushDatabase();
                await CreateDbFromModel(model);

                return(new ApiResponse {
                    Status = Status.Success, Message = "Device db recreated sucessfully"
                });
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new ApiResponse {
                    Status = Status.Error, Message = ex.Message
                }));
            }
        }
コード例 #2
0
ファイル: RmsController.cs プロジェクト: skalpt/iris-rms
        private async Task CreateDbFromModel(RmsConfigModel model)
        {
            RmsConfig rms = new RmsConfig {
                Name = model.RmsDeviceInterface.name, Location = model.RmsDeviceInterface.location, IpAddress = model.RmsDeviceInterface.localIp, MacAddress = model.RmsDeviceInterface.macAddress
            };

            foreach (RmsNode node in model.nodes)
            {
                foreach (RmsNodeDevice nodeDevice in node.devices)
                {
                    DeviceType deviceType = ParseLightType(nodeDevice.type);
                    if (deviceType == DeviceType.LightOnOff)
                    {
                        Light newLight = new Light
                        {
                            Location      = node.location,
                            Type          = deviceType,
                            MAC           = nodeDevice.macAddress,
                            CurrentStatus = nodeDevice.status
                        };

                        newLight.Hooks.Add(new WebHook {
                            ActivationCommand = RmsCommand.LightsOn, HookUrl = BuildHookUrl(nodeDevice, model.RmsDeviceInterface.localIp), Method = "POST", Body = BuildHookActiveBody(node, newLight)
                        });
                        newLight.Hooks.Add(new WebHook {
                            ActivationCommand = RmsCommand.LightsOff, HookUrl = BuildHookUrl(nodeDevice, model.RmsDeviceInterface.localIp), Method = "POST", Body = BuildHookInactiveBody(node, newLight)
                        });
                        rms.Lights.Add(newLight);
                    }

                    if (deviceType == DeviceType.Hvac)
                    {
                        Hvac newHvac = new Hvac
                        {
                            Location = node.location,
                            MAC      = nodeDevice.macAddress
                        };
                        double currentTemp;
                        if (double.TryParse(nodeDevice.currentTemperature, out currentTemp))
                        {
                            newHvac.CurrentTemperature = currentTemp;
                        }
                        double setpointTemp;
                        if (double.TryParse(nodeDevice.setTemperature, out setpointTemp))
                        {
                            newHvac.SetpointTemperature = setpointTemp;
                        }
                        newHvac.Hooks.Add(new WebHook {
                            ActivationCommand = RmsCommand.HvacSetTemperature, HookUrl = BuildHookUrl(nodeDevice, model.RmsDeviceInterface.localIp), Method = "POST", Body = BuildHookSetTemperatureBody(node, newHvac)
                        });
                        rms.Hvacs.Add(newHvac);
                    }
                }
            }
            _context.RmsList.Add(rms);
            _context.SaveChanges();
        }
コード例 #3
0
ファイル: RmsController.cs プロジェクト: skalpt/iris-rms
        private void UpdateDevice(RmsConfigModel model)
        {
            Light device = _context.Lights.SingleOrDefault(rmsDevice => rmsDevice.MAC == model.RmsDeviceInterface.macAddress);

            foreach (RmsNode node in model.nodes)
            {
                foreach (RmsNodeDevice nodeDevice in node.devices)
                {
                    //TODO: update hooks here
                }
            }
            _context.SaveChanges();
        }