예제 #1
0
        private async void LoadData()
        {
            //Open connection
            var conn = AppModel.Current.Connection;
            //Get controller metadata
            ControllerInfo controllerInfo = await conn.GetControllerInfoAsync();

            ProgramDetailsInfo programs = await conn.GetProgamDetailsAsync();

            Programs     = new List <OpenSprinklerNet.Program>(programs.Programs);        //Unfortunately I have to do this because stupid WinRT type system can't do proper type conversion
            IsSequential = controllerInfo.SequentialMode == Status.On;
            OnPropertyChanged("Programs");
        }
예제 #2
0
        public MockOpenSprinklerService(string hostname, string password)
            : base(null)
        {
            m_hostname     = hostname;
            m_password     = password;
            controllerInfo = CreateFromJson <MockControllerInfo>("{\"fwv\":207,\"tz\":16,\"ntp\":0,\"dhcp\":1,\"ip1\":192,\"ip2\":168,\"ip3\":1,\"ip4\":22,\"gw1\":192,\"gw2\":168,\"gw3\":1,\"gw4\":1,\"hp0\":80,\"hp1\":0,\"ar\":0,\"ext\":0,\"seq\":1,\"sdt\":0,\"mas\":0,\"mton\":0,\"mtof\":0,\"urs\":0,\"rso\":0,\"wl\":100,\"stt\":10,\"ipas\":0,\"devid\":0,\"con\":110,\"lit\":100,\"dim\":5,\"ntp1\":204,\"ntp2\":9,\"ntp3\":54,\"ntp4\":119,\"reset\":0}");
            controllerInfo.SetTimeZone(5);
            programs = CreateFromJson <ProgramDetailsInfo>("{\"nprogs\":5,\"nboards\":1,\"mnp\":53,\"pd\":[[1,255,1,270,360,1439,600,8],[1,255,1,270,480,1439,600,16],[1,255,1,270,360,1439,480,32],[1,255,1,270,480,1439,480,64],[1,127,1,270,600,1439,720,128]]}");
            var progs = programs.Programs as IList <Program>;

            progs[2].Duration = TimeSpan.FromMinutes(30);


            statuses   = CreateFromJson <StationStatusInfo>("{\"sn\":[0,0,0,1,0,1,0,0],\"nstations\":8}");
            statusInfo = CreateFromJson <StationInfo>("{\"snames\":[\"Raised beds\",\"Planters S\",\"Planters N\",\"Backyard lawn E\",\"Backyard lawn W\",\"Frontyard lawn\",\"Sidewalk lawn\",\"Planters E\"],\"masop\":[255],\"ignore_rain\":[128],\"maxlen\":16}");
        }
예제 #3
0
        private async void Test()
        {
            try
            {
                //Open connection
                var conn = OpenSprinklerApp.ViewModels.AppModel.Current.Connection;                 // await OpenSprinklerNet.OpenSprinklerConnection.OpenAsync("http://192.168.1.15:80", "opendoor");
                //Get controller metadata
                ControllerInfo controllerInfo = await conn.GetControllerInfoAsync();

                //controllerInfoView.DataContext = controllerInfo;
                //Get current settings
                ControllerSettingsInfo settings = await conn.GetControllerSettingsAsync();

                //Get all programs
                ProgramDetailsInfo programs = await conn.GetProgamDetailsAsync();

                //Get info about the stations
                StationInfo stationInfo = await conn.GetStationsAsync();

                //Check whether sprinkler '1' is on
                bool isOn = await conn.QueryStationStatusAsync(1);

                //Check on/off status of all sprinklers
                var stations = await conn.QueryStationStatusesAsync();

                //Check if in manual mode
                if (settings.ManualMode == OpenSprinklerNet.Status.On)
                {
                    //Turn sprinkler 3 on
                    await conn.SetStationStatusAsync(3, OpenSprinklerNet.Status.On);

                    await Task.Delay(2000);

                    var bit = await conn.QueryStationStatusAsync(3);

                    stations = await conn.QueryStationStatusesAsync();

                    System.Diagnostics.Debug.Assert(bit);
                    //Turn sprinkler 3 off
                    await conn.SetStationStatusAsync(3, OpenSprinklerNet.Status.Off);
                }
            }
            catch { }
        }
예제 #4
0
        public void UpdateView(ProgramDetailsInfo info)
        {
            uiScrollbar.value = 1;

            if (uiTitle1 != null)
            {
                if (info.title1 != null)
                {
                    uiTitle1.gameObject.SetActive(true);

                    uiTitle1.text = info.title1;
                }
                else
                {
                    uiTitle1.gameObject.SetActive(false);
                }
            }

            if (uiTitle2 != null)
            {
                uiTitle2.text = info.title2;
            }

            if (uiImage != null)
            {
                if (info.image != null)
                {
                    uiImage.gameObject.SetActive(true);
                    uiImage.sprite = info.image;

                    UpdateImageLayoutElement();
                }
                else
                {
                    uiImage.gameObject.SetActive(false);
                }
            }

            if (uiDescription != null)
            {
                uiDescription.text = info.description;
            }

            if (uiDetails != null)
            {
                _sb.Length = 0;

                if (string.IsNullOrEmpty(info.duration) == false)
                {
                    _sb.Append(info.duration);
                    _sb.Append(" | ");
                }

                if (string.IsNullOrEmpty(info.startTime) == false)
                {
                    _sb.Append(info.startTime);
                    _sb.Append(" | ");
                }

                if (string.IsNullOrEmpty(info.type) == false)
                {
                    _sb.Append(info.type);
                    _sb.Append(" | ");
                }

                _sb.Append(info.region);

                uiDetails.text = _sb.ToString();
            }
        }
예제 #5
0
        public IEnumerator GetProgramDetailsByID(ProgramDetailsInfo result, string id)
        {
            string strUri = "https://external.api.yle.fi/v1/programs/items/";

            _sb.Length = 0;
            _sb.Append(strUri);
            _sb.Append(id);
            _sb.Append(".json?");
            _sb.Append(_authInfo);

            string requestData = _sb.ToString();

            while (_netThread.Request(requestData) == false)
            {
                yield return(null);
            }

            string resultString = null;

            while (_netThread.PopResponseData(ref resultString) == false)
            {
                yield return(null);
            }

            JSONObject jsonResult  = new JSONObject(resultString);
            JSONObject data        = jsonResult ["data"];
            JSONObject title       = data ["title"];
            JSONObject description = data ["description"];
            JSONObject image       = data ["image"];
            //JSONObject typeMedia = data ["typeMedia"];
            JSONObject        type              = data ["type"];
            JSONObject        duration          = data ["duration"];
            List <JSONObject> publicationEvents = data ["publicationEvent"].list;
            JSONObject        publicationEvent  = null;
            JSONObject        startTime         = null;
            JSONObject        region            = null;

            if (publicationEvents.Count > 0)
            {
                publicationEvent = publicationEvents [0];
                startTime        = publicationEvent ["startTime"];
                region           = publicationEvent ["region"];
            }

            if (title != null &&
                title ["fi"] != null)
            {
                string[] titles = Util_String.SplitTitle(Util_String.ReplaceString(title ["fi"].str));

                if (titles.Length > 1)
                {
                    result.title1 = titles[0];
                    result.title2 = titles[1];
                }
                else
                {
                    result.title1 = null;
                    result.title2 = titles[0];
                }
            }

            if (description != null &&
                description ["fi"] != null)
            {
                result.description = Util_String.ReplaceString(description ["fi"].str);
            }

            if (image != null &&
                image.Count > 0 &&
                image["id"] != null)
            {
                int    size        = Screen.width;
                string imageFormat = "jpg";
                string imageUrl    = string.Format("http://images.cdn.yle.fi/image/upload/w_{0},h_{1},c_fit/{2}.{3}", size, size, image["id"].str, imageFormat);

                WWW www = new WWW(imageUrl);

                yield return(www);

                result.image = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));

                Resources.UnloadUnusedAssets();
            }

            if (type != null)
            {
                result.type = type.str;
            }

            if (duration != null)
            {
                result.duration = Util_String.ToDisplayDuration(duration.str);
            }

            if (startTime != null)
            {
                result.startTime = Util_String.ToDisplayStartTime(startTime.str);
            }

            if (region != null)
            {
                result.region = region.str;
            }

            _netThread.FinishResponse();
        }