Skip to content
krishnabangalore edited this page Dec 12, 2013 · 2 revisions

In order to get a reference to the API, you will have to discover the API. You can use the dashboard to allow the user pick the service for you, but you can also do this manually in code (see the API description for the dashboard use).

##Service Discovery This is the list of URIs used to declare this API's features, for use in the widget config.xml and as identifier for service type in service discovery functionality. For each URI, the list of functions covered is provided.

webinos.discovery.findServices(new ServiceType   
           ('http://webinos.org/api/devicestatus'), {onFound:function (service) {
     //Stores the Service in a local variable
     foundService = service
     }

From this point we will refer to the found service as if it was stored in the foundService variable.

##Bind Before using a service, you need to bind to it. Binding is similar on all services. The following code shows how to bind to the DeviceStatus API. Bind to the found and select a service and use. This is required to make calls possible on the webinos service that we created.

    devicestatusService.bindService({onBind:function (service) {
            alert('DeviceStatus API ' + service.api + ' bound.');
            loadAspects();
        }});

provides means to get the components of an aspect. An aspect is an abstract nameable thing (e.g., a "Device", "Battery", "Display", etc.) that the user agent knows about and can interact with. An aspect can contain one or more components.

devicestatusService.getComponents(aspect, successCB, errorCB);

The getPropertyValue() method asyncrhonously attemps to read the value of a given component. However, if no component is given, the user agent will default to the active component or the default component of a given aspect. deviceStatusService is the device status service, discovered through the webinos Discovery API, that has been selected by the user

    deviceStatusService.getPropertyValue(
            function(value) {
            console.log("The battery level is at " + value + "%");
            },
      null, {
      property: "batteryLevel",
      aspect: "Battery"
    });

The isSupported() method checks if an aspect is supported and, optionally, if a property that would correspond to a component of that aspect is supported (e.g., a Battery aspect's batteryLevel property).

    if (deviceStatusService.isSupported('Battery', 'batteryLevel')) {
    console.log("batteryLevel property is available");
    } else {
    console.log("batteryLevel property is not available");
    }
Clone this wiki locally