Пример #1
0
        public static ValueSet GetReturnData(ValueSet message)
        {
            ValueSet returnData = new ValueSet();

            string type = message["Type"] as string;

            switch (type.ToUpper())
            {
            case "COMMON":
                GetReturnData(message, ref returnData);
                break;

            case "ZIGBEE":
                ZigBeeService.GetReturnData(message, ref returnData);
                //zigBeeService.GetReturnData(message, ref returnData);
                break;

            default:
            {
                returnData.Add("Status", "Fail: unknown Type");
                break;
            }
            }

            return(returnData);
        }
Пример #2
0
        private static void GetReturnData(ValueSet message, ref ValueSet returnData)
        {
            string command = message["Command"] as string;

            switch (command.ToUpper())
            {
            case "INIT":
            {
                Hashtable result = CommonInit();
                string    status = "OK";
                if (!(bool)result[TypeZigBee])
                {
                    status = "\nFail to init ZigBee";
                }
                returnData.Add("Status", status);
            }
            break;

            case "GETPHRASELIST":
            {
                List <string> result = null;
                try
                {
                    using (var db = new IOTOI.Model.Db.Context())
                    {
                        result = (from ep in db.ZigBeeEndPoint
                                  where ep.CustomName != null
                                  select ep.CustomName)
                                 .ToList();
                    }
                }
                catch (Exception e)
                {
                    loggingServices.Write(Log, e.Message, LogLevel.Error, e);
                }
                returnData.Add("Result", JsonConvert.SerializeObject(result));
                returnData.Add("Status", "OK");
            }
            break;

            case "GETDEVICE":
            {
                returnData.Add("Result", JsonConvert.SerializeObject(ZigBeeService.GetEndPoint(message["Target"] as string)));
                returnData.Add("Status", "OK");
            }
            break;

            case "GETSTATUS":
            {
                returnData.Add("Result", ZigBeeService.GetEndPointStatus(message["Target"] as string));
                returnData.Add("Status", "OK");
            }
            break;

            case "SETNESTTOKEN":
            {
                strNestToken = message["NESTTOKEN"].ToString();

                Nest.NestCommandHandler.ThermostatAPI.ApplyAccessToken(strNestToken);

                returnData.Add("Status", "OK");
            }
            break;

            case "GETNESTSTATUS":
            {
                //TODO : NEST GET STATUS
                //Result CASE 1(temperature : 60)
                //Result CASE 2(fan : true or false)

                #region
                if (message["Target"].ToString() == "temperature")
                {
                    string r = Nest.NestCommandHandler.CurrentTemperature();
                    if (r.Contains("Fail:"))
                    {
                        returnData.Add("Status", r);
                    }
                    else
                    {
                        returnData.Add("Result", r);
                        returnData.Add("Status", "OK");
                    }
                }
                else
                if (message["Target"].ToString() == "fan")
                {
                    string r = Nest.NestCommandHandler.CurrentFanStatus();
                    if (r.Contains("Fail:"))
                    {
                        returnData.Add("Status", r);
                    }
                    else
                    {
                        returnData.Add("Result", r);            // FanRunning , FanStopped
                        returnData.Add("Status", "OK");
                    }
                }
                #endregion
            }
            break;

            default:
            {
                returnData.Add("Status", "Fail: unknown command");
                break;
            }
            }
        }
Пример #3
0
 private static int StartZigBeeInit()
 {
     //zigBeeService = new ZigBeeService();
     //return zigBeeService.InitZigBee();
     return(ZigBeeService.InitZigBee());
 }