Skip to content

Commit

Permalink
Merge pull request #4 from bsileo/NJSPC6
Browse files Browse the repository at this point in the history
initial checkin
  • Loading branch information
bsileo authored Apr 26, 2020
2 parents 80289d7 + 36c4dd5 commit 355368c
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions pool_controller_pump.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Copyright 2020 Brad Sileo
*
* Pump
*
* Author: Brad Sileo
*
*/
metadata {
definition (name: "Pool Controller Pump",
namespace: "bsileo",
author: "Brad Sileo",
importUrl: 'https://raw.githubusercontent.com/bsileo/hubitat_poolcontroller/master/pool_controller_pump.groovy') {
capability "Switch"
capability "PowerMeter"
capability "Refresh"
attribute "RPM", "number"
attribute "Status", "string"
attribute "friendlyName", "string"
attribute "circuitFunction", "string"
}

preferences {
section("General:") {
input (
name: "configLoggingLevelIDE",
title: "IDE Live Logging Level:\nMessages with this level and higher will be logged to the IDE.",
type: "enum",
options: [
"0" : "None",
"1" : "Error",
"2" : "Warning",
"3" : "Info",
"4" : "Debug",
"5" : "Trace"
],
defaultValue: "3",
displayDuringSetup: true,
required: false
)
}
}
}

def installed() {
state.loggingLevelIDE = (settings.configLoggingLevelIDE) ? settings.configLoggingLevelIDE.toInteger() : 5
}

def updated () {
state.loggingLevelIDE = (settings.configLoggingLevelIDE) ? settings.configLoggingLevelIDE.toInteger() : 5
}

def refresh() {
def id = getDataValue("pumpID")
def params = [
uri: getParent().getControllerURI(),
path: "/state/pump/${id})"
]
logger("Sending refresh with ${params}","debug")
asynchttpGet('parseRefresh', params, data)
}

def parseRefresh(response, data) {
logger("parserefresh - ${response} - ${data}","trace")
def json = response.getJson()
logger("parserefresh - ${res}","trace")
sendEvent(name: "power", value: json.watts)
sendEvent(name: "RPM", value: json.rpm)
sendEvent(name: "flow", value: json.flow)
sendEvent(name: "driveState", value: json.driveState)
sendEvent(name: "command", value: json.command)
sendEvent(name: "mode", value: json.mode)

}

def on() {
def id = getDataValue("circuitID")
def data = [id: id, state: 1]
def params = [
uri: getParent().getControllerURI(),
path: "/state/circuit/setState"
]
logger("Turn on pump with ${params} - ${data}","debug")
asynchttpPut('stateChangeCallback', params, data)
sendEvent(name: "switch", value: "on", displayed:false,isStateChange:false)
}

def off() {
def id = getDataValue("circuitID")
def data = [id: id, state: 0]
def params = [
uri: getParent().getControllerURI(),
path: "/state/circuit/setState)"
]
logger("Turn off pump with ${params}","debug")
asynchttpPut('stateChangeCallback', params, data)
sendEvent(name: "switch", value: "off", displayed:false,isStateChange:false)
}

def stateChangeCallback(response, data) {
logger("State Change Result ${response.getStatus()}","debug")
logger("State Change Result Data ${response.getData()}","debug")
}

/**
* logger()
*
* Wrapper function for all logging.
**/

private logger(msg, level = "debug") {

switch(level) {
case "error":
if (state.loggingLevelIDE >= 1) log.error msg
break

case "warn":
if (state.loggingLevelIDE >= 2) log.warn msg
break

case "info":
if (state.loggingLevelIDE >= 3) log.info msg
break

case "debug":
if (state.loggingLevelIDE >= 4) log.debug msg
break

case "trace":
if (state.loggingLevelIDE >= 5) log.trace msg
break

default:
log.debug msg
break
}
}

0 comments on commit 355368c

Please sign in to comment.