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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Dlink Video Camera Child
* D-Link Camera Manager (Connect)
*
* Copyright 2016 Ben Lebson
* Parent/Child SmartApp based on Patrick Stuart's Generic Video Camera SmartApp
Expand All @@ -15,87 +15,45 @@
*
*/
definition(
name: "Dlink Video Camera Child",
name: "D-Link Camera Manager (Connect)",
namespace: "blebson",
author: "Ben Lebson",
description: "Dlink Child Video Camera SmartApp",
description: "This smartapp installs the D-Link Camera Manager (Connect) App so you can add multiple D-Link IP cameras",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Camera/dlink.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Camera/dlink@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Camera/dlink@3x.png")
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Camera/dlink@3x.png",
singleInstance: true)


preferences {
page(name: "mainPage", title: "Install Video Camera", install: true, uninstall:true) {
section("Camera Name") {
label(name: "label", title: "Name This Camera", required: true, multiple: false, submitOnChange: true)
}
section("Add a Camera") {
input("CameraType","enum", title: "Camera Model", description: "Please select your camera model", required:false, submitOnChange: true,
options: ["DCS-930L", "DCS-931L", "DCS-932L", "DCS-933L", "DCS-934L", "DCS-935L", "DCS-942L", "DCS-960L", "DCS-2132L", "DCS-2210L", "DCS-2310L", "DCS-2330L", "DCS-2630L"], displayDuringSetup: true)
page(name: "mainPage", title: "Existing Cameras", install: true, uninstall: true) {
if(state?.installed) {
section("Add a New Camera") {
app "Dlink Video Camera Child", "blebson", "Dlink Video Camera Child", title: "New Fixed D-Link Camera", page: "mainPage", multiple: true, install: true
app "Dlink PTZ Video Camera Child", "blebson", "Dlink PTZ Video Camera Child", title: "New PTZ D-Link Camera", page: "mainPage", multiple: true, install: true
}
section("Camera Settings:"){
input("CameraIP", "string", title:"Camera IP Address", description: "Please enter your camera's IP Address", required: true, displayDuringSetup: true)
input("CameraPort", "string", title:"Camera Port", description: "Please enter your camera's HTTP Port", defaultValue: 80 , required: true, displayDuringSetup: true)
input("VideoIP", "string", title:"Video IP Address", description: "Please enter your camera's IP Address (use external IP if you are using port forwarding)", required: true, displayDuringSetup: true)
input("VideoPort", "string", title:"Video Port", description: "Please enter your camera's Video Port (use external Port if you are using port forwarding)", required: true, displayDuringSetup: true)
input("CameraUser", "string", title:"Camera User", description: "Please enter your camera's username", required: false, displayDuringSetup: true)
input("CameraPassword", "password", title:"Camera Password", description: "Please enter your camera's password", required: false, displayDuringSetup: true)
} else {
section("Initial Install") {
paragraph "This smartapp installs the D-Link Camera Manager (Connect) App so you can add multiple D-Link IP cameras. Click 'Done' then go to smartapps in the flyout menu and add new cameras or edit existing cameras."
}
section("Hub Settings"){
input("hubName", "hub", title:"Hub", description: "Please select your Hub", required: true, displayDuringSetup: true)
}
}

}

def installed() {
log.debug "Installed"
log.debug "Installed with settings: ${settings}"

initialize()
}

def updated() {
log.debug "Updated"
log.debug "Updated with settings: ${settings}"

unsubscribe()
initialize()
}

def initialize() {

state.CameraIP = CameraIP
state.CameraPort = CameraPort
state.VideoIP = VideoIP
state.VideoPort = VideoPort
state.CameraUser = CameraUser
state.CameraPassword = CameraPassword

/*
log.debug "Camera IP: ${state.CameraIP}"
log.debug "Camera Port: ${state.CameraPort}"
log.debug "Video IP: ${state.VideoIP}"
log.debug "Video Port: ${state.VideoPort}"
log.debug "Camera User: ${state.CameraUser}"
log.debug "Camera Password: ${state.CameraPassword}"
*/

try {
def DNI = (Math.abs(new Random().nextInt()) % 99999 + 1).toString()
def cameras = getChildDevices()
if (cameras) {
cameras[0].configure()
}
else {
def childDevice = addChildDevice("blebson", CameraType, DNI, hubName.id, [name: app.label, label: app.label, completedSetup: true])
}
} catch (e) {
log.error "Error creating device: ${e}"
}
state.installed = true
}

private removeChildDevices(delete) {
delete.each {
deleteChildDevice(it.deviceNetworkId)
}
}