Hi All,

I am developing connector for Nest API. Nest Thermostat API is organized in
a single data object and every data element is addressable by a URL called
data location.

*Data model:*

{
"devices": {

"thermostats": {
"peyiJNo0IldT2YlIVtYaGQ": {
"device_id": "peyiJNo0IldT2YlIVtYaGQ" ,
"locale": "en-US" ,
"software_version": "4.0" ,
"structure_id": "VqFabWH21nwVyd4RWgJgNb292wa7hG_dUwo2i2SG7j3-BOLY0BA4sw" ,
"name": "Hallway (upstairs)" ,
"name_long": "Hallway Thermostat (upstairs)" ,
"last_connection": "2014-10-31T23:59:59.000Z" ,
"is_online": true ,
"can_cool": true ,
"can_heat": true ,
"is_using_emergency_heat": true ,
"has_fan": true ,
"fan_timer_active": true ,
"fan_timer_timeout": "2014-10-31T23:59:59.000Z" ,
"has_leaf": true ,
"temperature_scale": "C" ,
"target_temperature_f": 72 ,
"target_temperature_c": 21.5 ,
"target_temperature_high_f": 72 ,
"target_temperature_high_c": 21.5 ,
"target_temperature_low_f": 64 ,
"target_temperature_low_c": 17.5 ,
"away_temperature_high_f": 72 ,
"away_temperature_high_c": 21.5 ,
"away_temperature_low_f": 64 ,
"away_temperature_low_c": 17.5 ,
"hvac_mode": "heat" ,
"ambient_temperature_f": 72 ,
"ambient_temperature_c": 21.5 ,
"humidity": 40
}
}
,
"smoke_co_alarms": {
"RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs": {
"device_id": "RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs" ,
"locale": "en-US" ,
"software_version": "1.01" ,
"structure_id": "VqFabWH21nwVyd4RWgJgNb292wa7hG_dUwo2i2SG7j3-BOLY0BA4sw" ,
"name": "Hallway (upstairs)" ,
"name_long": "Hallway Protect (upstairs)" ,
"last_connection": "2014-10-31T23:59:59.000Z" ,
"is_online": true ,
"battery_health": "ok" ,
"co_alarm_state": "ok" ,
"smoke_alarm_state": "ok" ,
"is_manual_test_active": true ,
"last_manual_test_time": "2014-10-31T23:59:59.000Z" ,
"ui_color_state": "gray"
}
}

} ,
"structures": {
"VqFabWH21nwVyd4RWgJgNb292wa7hG_dUwo2i2SG7j3-BOLY0BA4sw": {
"structure_id": "VqFabWH21nwVyd4RWgJgNb292wa7hG_dUwo2i2SG7j3-BOLY0BA4sw" ,
"thermostats": [ "peyiJNo0IldT2YlIVtYaGQ", ... ] ,
"smoke_co_alarms": [ "RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs", ... ] ,
"away": "home" ,
"name": "Home" ,
"country_code": "US" ,
"postal_code": "94304" ,
"peak_period_start_time": "2014-10-31T23:59:59.000Z" ,
"peak_period_end_time": "2014-10-31T23:59:59.000Z" ,
"time_zone": "America/Los_Angeles" ,
"eta": {
"trip_id": "myTripHome1024" ,
"estimated_arrival_window_begin": "2014-10-31T22:42:59.000Z" ,
"estimated_arrival_window_end": "2014-10-31T23:59:59.000Z"
}
}
}
}

*Endpoints:*
To get whole object: https://developer-api.nest.com?auth=<token>
To get all device objects: https://developer-api.nest.com/devices?auth=
<token>
To get all thermostat device objects:
https://developer-api.nest.com/devices/thermostats?auth=<token>
To get a particular thermostat device object:
https://developer-api.nest.com/devices/thermostats/<device id>?auth=<token>
To get target temperature value of a particular thermostat device:
https://developer-api.nest.com/devices/thermostats/<device
id>/target_temperature_f?auth=<token>


To view whole structure object (all devices in home, away status etc):
https://developer-api.nest.com/structures?auth=<token>
To view a list of thermostat devices in home:
https://developer-api.nest.com/structures/<structure
id>/thermostats?auth=<token>

So I am planning to do this using switch mediator in a single configuration
as written below. In the proxy service, I have to define all parameters. Is
this a correct way or do I want to write each methods separately?


<?xml version="1.0" encoding="UTF-8"?>
<template name="getServices" xmlns="http://ws.apache.org/ns/synapse";>

    <parameter name="category" description="Category" />


    <!-- For devices -->
    <parameter name="device" description="Type of device" />
    <parameter name="deviceId" description="Id of device" />

    <!-- For structures -->
    <parameter name="structureId" description="Id of structure" />

    <!-- For both devices and structures -->
    <parameter name="field" description="Field of a thermostat" />  <!-- It
can be last_connection, is_online, can_cool, can_heat etc for devices and
thermostats, smoke_co_alarms, away, country_code for structures -->

    <sequence>
        <property name="uri.var.category" expression="$func:category" />
        <property name="uri.var.device" expression="$func:device" />
        <property name="uri.var.deviceId" expression="$func:deviceId" />
        <property name="uri.var.structureId" expression="$func:structureId"
/>
        <property name="uri.var.field" expression="$func:field" />

        <switch source="get-property('uri.var.category')">
            <case regex="devices">
                <property name="uri.var.param" value="devices"/>

                <filter xpath="(not(get-property('uri.var.deviceId') = ''
or (not(string(get-property('uri.var.deviceId'))))))">
                    <then>
                        <property name="uri.var.param"

expression="fn:concat(get-property('uri.var.param'),'/thermostats/',get-property('uri.var.deviceId'))"/>

                        <filter xpath="(not(get-property('uri.var.field') =
'' or (not(string(get-property('uri.var.field'))))))">
                            <then>

                                <switch
source="get-property('uri.var.field')">
                                    <case
regex="humidity|last_connection|is_online|can_cool|can_heat">
                                    <property name="uri.var.param"

expression="fn:concat(get-property('uri.var.param'),'/',get-property('uri.var.field'))"/>
                                    </case>
                                    <default/>
                                </switch>

                            </then>
                        </filter>

                    </then>
                </filter>

            </case>
            <case regex="structures">
                <property name="uri.var.param" value="structures"/>
            </case>
            <default/>
        </switch>

        <property name="Content-Type" value="application/json"/>

         <call>
            <endpoint>
                <http method="get"

uri-template="{uri.var.apiUrl}/{uri.var.param}?auth={uri.var.token}" />
            </endpoint>
        </call>
    </sequence>
</template>

I appreciate the thoughts on performance implications.

Thank you.
-- 
Shakila Sivagnanarajah
Associate Software Engineer
Mobile :+94 (0) 770 760240
[email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to