Skip to content
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
28 changes: 20 additions & 8 deletions DiskStation/DiskstationCamera.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,20 @@ def putImageInS3(map) {
def s3ObjectContent

try {
def imageBytes = getS3Object(map.bucket, map.key + ".jpg")
def s3Object = getS3Object(map.bucket, map.key + ".jpg")

if(imageBytes)
if(s3Object)
{
// ILLEGAL METHOD CALL??? WTF
//log.trace "s3Object size " + s3Object.getObjectMetadata()?.getContentLength()
def picName = getPictureName()
s3ObjectContent = imageBytes.getObjectContent()
s3ObjectContent = s3Object.getObjectContent()
def bytes = new ByteArrayInputStream(s3ObjectContent.bytes)
storeImage(picName, bytes)
log.trace "image stored = " + picName
}

} else {
log.trace "The image (" + picName + ") is missing"
}
}
catch(Exception e) {
log.error e
Expand Down Expand Up @@ -228,6 +231,7 @@ def take() {
log.error e
sendEvent(name: "takeImage", value: "0")
}

def hubAction = null
def cameraId = getCameraID()
if ((takeStream != null) && (takeStream != "")){
Expand Down Expand Up @@ -416,11 +420,15 @@ def recordEventFailure() {

def motionActivated() {
if (device.currentState("motion")?.value != "active") {
log.trace "activate"
sendEvent(name: "motion", value: "active")
} else {
log.trace "motion detected, already active, not sending an event"
}
}

def motionDeactivate() {
log.trace "deactivate"
sendEvent(name: "motion", value: "inactive")
}

Expand Down Expand Up @@ -482,6 +490,10 @@ def queueDiskstationCommand_Child(String api, String command, String params, int

//helper methods
private getPictureName() {
def pictureUuid = java.util.UUID.randomUUID().toString().replaceAll('-', '')
return device.deviceNetworkId.replaceAll(" ", "_") + "_$pictureUuid" + ".jpg"
}
def lastNum = device.currentState("takeImage")?.integerValue ?: 0

Date rightNow = new Date()
def pictureDate = rightNow.toString().replaceAll(" ", "_").replaceAll(":", "")

return device.deviceNetworkId.replaceAll(" ", "_") + "_$pictureDate" + "_" + lastNum + ".jpg"
}