Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding spotClean command #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* for the specific language governing permissions and limitations under the License.
*
* VERSION HISTORY
* 20-04-2018: 1.10 - Added Spot clean command.
* 18-04-2018: 1.9b - Incorrect Persistent Map mode label fix.
* 18-04-2018: 1.9 - Support for D7 persistent map cleaning and deep cleaning mode.
* 15-04-2018: 1.8.1 - Fix support for D7 with houseCleaning basic-3 support.
Expand Down Expand Up @@ -72,6 +73,7 @@ metadata {
command "toggleNavigationMode"
command "togglePersistentMapMode"
command "findMe"
command "spotClean"

attribute "network","string"
attribute "bin","string"
Expand Down Expand Up @@ -181,6 +183,12 @@ metadata {
main("switch")
details(["clean","smartScheduleStatusMessage", "forceCleanStatusMessage", "status", "battery", "charging", "bin", "dockStatus", "dockHasBeenSeen", "cleaningMode", "navigationMode", "persistentMapMode", "scheduled", "resetSmartSchedule", "network", "refresh", "mapHTML"])
}

preferences {
input "spotCleanSizeMetric", "enum", title: "Spot Clean Unit of Measurement", options: ["Feet", "Centimeters"], displayDuringSetup: true
input "spotCleanWidth", "number", title: "Spot Clean Width", description: "Width of spot cleaning area", displayDuringSetup: true
input "spotCleanHeight", "number", title: "Spot Clean Height", description: "Height of spot cleaning area", displayDuringSetup: true
}
}

mappings {
Expand Down Expand Up @@ -327,6 +335,48 @@ def togglePersistentMapMode() {
runIn(2, refresh)
}

def convertToCentimeters(distance) {
if(spotCleanSizeMetric == 'Feet') {
return (distance * 30.48).toInteger()
}
return distance
}

def spotClean() {
log.debug "Executing 'spotClean'"
def currentState = device.latestState('status').stringValue
if (currentState != 'error') {
if (currentState == 'paused') {
nucleoPOST("/messages", '{"reqId":"1", "cmd":"stopCleaning"}')
}
def modeParam = 1
if (isTurboCleanMode()) modeParam = 2

def navParam = 1
if (isExtraCareNavigationMode()) navParam = 2

def modifier = 1
def spotCleanWidthInCm = convertToCentimeters(spotCleanWidth)
def spotCleanHeightInCm = convertToCentimeters(spotCleanHeight)

switch (state.spotCleaning) {
case "basic-1":
nucleoPOST("/messages", '{"reqId":"1", "cmd":"startCleaning", "params":{"category": 3, "mode": ' + modeParam + ', "modifier": ' + modifier + ', "spotWidth":' + spotCleanWidthInCm + ', "spotHeight":' + spotCleanHeightInCm + '}}')
break;
case "micro-2":
nucleoPOST("/messages", '{"reqId":"1", "cmd":"startCleaning", "params":{"category": 3, "navigationMode": ' + navParam + '}}')
break;
case "basic-2":
nucleoPOST("/messages", '{"reqId":"1", "cmd":"startCleaning", "params":{"category": 3, "mode": ' + modeParam + ', "modifier": ' + modifier + ', "navigationMode": ' + navParam + ', "spotWidth":' + spotCleanWidthInCm + ', "spotHeight":' + spotCleanHeightInCm + '}}')
break;
case "minimal-2":
nucleoPOST("/messages", '{"reqId":"1", "cmd":"startCleaning", "params":{"category": 3, "modifier": ' + modifier + ', "navigationMode": ' + navParam + '}}')
break;
}
}
runIn(2, refresh)
}

def poll() {
log.debug "Executing 'poll'"
def resp = nucleoPOST("/messages", '{"reqId":"1", "cmd":"getRobotState"}')
Expand Down Expand Up @@ -924,4 +974,4 @@ def getFileBase64(url, preType, fileType) {
}

def cssUrl() { return "https://raw.githubusercontent.com/desertblade/ST-HTMLTile-Framework/master/css/smartthings.css" }
def nucleoURL(path = '/') { return "https://nucleo.neatocloud.com:4443/vendors/neato/robots/${device.deviceNetworkId.tokenize("|")[0]}${path}" }
def nucleoURL(path = '/') { return "https://nucleo.neatocloud.com:4443/vendors/neato/robots/${device.deviceNetworkId.tokenize("|")[0]}${path}" }