Skip to content

Commit

Permalink
v1.9 corrected potential issue in getVehicles() to retrieve just one …
Browse files Browse the repository at this point in the history
…specific vehicle
  • Loading branch information
yracine committed Nov 13, 2015
1 parent 24cc3b7 commit c9aa51f
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions myautomatic.devicetype
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* My Automatic Device
*
* Copyright 2015 Yves Racine
* Version 1.8.3
* Version 1.9
* linkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
* Refer to readme file for installation instructions.
*
Expand Down Expand Up @@ -568,7 +568,7 @@ metadata {
void poll() {


def vehicleId= determine_vehicle_id(settings.vehicleId)
def vehicleId= determine_vehicle_id("")
// Update the vehicle information

getVehicles(vehicleId)
Expand Down Expand Up @@ -1577,31 +1577,39 @@ void getVehicles(vehicleId, postData='false') {
api('vehicles', bodyReq) {resp->
statusCode= resp.status
if (statusCode == AUTOMATIC_SUCCESS) {
data?.vehicles=resp.data
data.vehicles.results.each {
id = it.id
def make = it.make
def model = it.model
def submodel = it.submodel
def year = it.year
def color = it.color
def displayName = it.display_name
if (settings.trace) {
sendEvent name: "verboseTrace", value:"getVehicles>vehicleId=${id},make=${make},model=${model}," +
"submodel=${model},year=${year},color=${color},displayName=${displayName}"
}
if (postData == 'true') {
if (!resp.data._metadata) {
// just one vehicle was found
data?.vehicles?.results[0]=resp.data
data.vehicles?._metadata?.count=1
} else {
data?.vehicles=resp.data
}
if (data.vehicles._metadata.count) {
for (i in 0..data.vehicles._metadata.count -1) {
id = data.vehicles.results[i].id
def make = data.vehicles.results[i].make
def model = data.vehicles.results[i].model
def submodel = data.vehicles.results[i].submodel
def year = data.vehicles.results[i].year
def color = data.vehicles.results[i].color
def displayName = data.vehicles.results[i].display_name
if (settings.trace) {
log.debug "getVehicles>adding ${data.vehicles[i]} to vehiclesData"
sendEvent name: "verboseTrace", value:"getVehicles>vehicleId=${id},make=${make},model=${model}," +
"submodel=${model},year=${year},color=${color},displayName=${displayName}"
}
vehiclesData << it // to be transformed into Json later
}
vehiclesList = vehiclesList + id + ','
} /* end each vehicle */
sendEvent name: "verboseTrace", value:"getVehicles>done"
if (postData == 'true') {
if (settings.trace) {
log.debug "getVehicles>adding ${data.vehicles.results[i]} to vehiclesData"
}
vehiclesData << data.vehicles.results[i] // to be transformed into Json later
}
vehiclesList = vehiclesList + id + ','
} /* end for vehicle */
sendEvent name: "verboseTrace", value:"getVehicles>done for vehicleId=${vehicleId}"
} /* end if metadata.vehicles.count */
} else {
log.error "getVehicles>error=${statusCode.toString()}"
sendEvent name: "verboseTrace", value:"getVehicles>error=${statusCode.toString()}"
sendEvent name: "verboseTrace", value:"getVehicles>error=${statusCode.toString()} for vehicleId=${vehicleId}"
// introduce a 1 second delay before re-attempting any other command
def cmd= []
cmd << "delay 1000"
Expand Down

0 comments on commit c9aa51f

Please sign in to comment.