Esempio n. 1
0
        // Load and parse the REST API for a function given by class name and
        // identifier, possibly applying changes
        // Device cache will be preloaded when loading function "module" and
        // leveraged for other modules
        internal virtual async Task <YJSONObject> _devRequest(string extra)
        {
            YDevice dev = await getYDevice();

            _hwId = _yapi._yHash.imm_resolveHwID(_className, _func);
            string[] split = _hwId.Split(new char[] { '\\', '.' });
            _funId  = split[1];
            _serial = split[0];
            YJSONObject loadval = null;

            if (extra.Equals(""))
            {
                // use a cached API string, without reloading unless module is
                // requested
                YJSONObject jsonval = await dev.requestAPI();

                loadval = jsonval.getYJSONObject(_funId);
            }
            else
            {
                dev.imm_clearCache();
            }
            if (loadval == null)
            {
                // request specified function only to minimize traffic
                if (extra.Equals(""))
                {
                    string httpreq = "GET /api/" + _funId + ".json";
                    string yreq    = await dev.requestHTTPSyncAsString(httpreq, null);

                    loadval = new YJSONObject(yreq);
                    loadval.parse();
                }
                else
                {
                    string httpreq = "GET /api/" + _funId + extra;
                    await dev.requestHTTPAsync(httpreq, null, null, null);

                    return(null);
                }
            }
            return(loadval);
        }