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

Cleanup methods #2

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
95 changes: 53 additions & 42 deletions alexattschild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,72 +22,83 @@
* 2018-11-18 Stephan Hackett Added support for Virtual Containers
* 2020-07-29 nh.schottfam Remove characters from message text that may cause issues
* 2020-09-25 lgk add volume
* 2020-10-04 lgk add set volume as command so it can be called from rule machione.
*/

attribute "currentVolume", "number"
capability "Configuration"

command "setVolume", [[name: "volumeLevel", type: "intteger", range: "1..100"]]

metadata {
definition (name: "Child Alexa TTS", namespace: "ogiewon", author: "Dan Ogorchock", importUrl: "https://raw.githubusercontent.com/ogiewon/Hubitat/master/AlexaTTS/Drivers/child-alexa-tts.src/child-alexa-tts.groovy") {

capability "Speech Synthesis"
capability "Configuration"
capability "Refresh"

attribute "level", "number"

command "initialize"
command "setLevel", ["number"]
}
}


preferences {
input("volumeLevel", "integer", title: "Volume level for this device (0-99)?", range: "1…100", defaultValue: 75, required: true)
input("level", "integer", title: "Volume level for this device (0-100)?", range: "1..100", defaultValue: 75, required: true)
}

def refresh(){
// this should query current volume setting and match device state to it
//updateDevState(num)
}

def configure()
{
def updateDevState(num){
num=num!=null ? num.toInteger() : -1
if(num>=0 && num<=100) {
sendEvent(name: 'level', value: num)
device.updateSetting('level', [value:num, type:'integer'])
state.level = num.toInteger()
}
}

def updated()
def updateVolume(num) {
log.debug "updateVolume($num)"

{
log.debug "in updated current volume = $volumeLevel, prior volume = $state.currentVolume"
if (state.currentVolume != volumeLevel)
{
log.debug "Resetting Volume"
sendEvent(name: "currentVolume", value: volumeLevel)
updateVolume()
}
num=num!=null ? num.toInteger() : -1
if(num>=0 && num<=100) {
def name = device.deviceNetworkId.split("-")[-1]
def vId = device.data.vcId
if(vId) parent.childComm("setVolume", num, vId)
else parent.setVolume(num, name)

updateDevState(num) // or it could have called refresh to ensure it gets current value
}
}

def updateVolume(newLevel)
{
log.debug "In update volume ... new level = $newLevel!"
def setLevel(num){
log.debug "setLevel($num)"
updateVolume(num)
}

def name = device.deviceNetworkId.split("-")[-1]
def vId = device.data.vcId

if(vId) parent.childComm("setVolume", newLevel, vId)
else parent.setVolume(newLevel.toInteger(), name)

def configure() {
}
def updateVolume()
{
updateVolume(volumeLevel)

def updated() {
log.debug "updated current volume = $level, prior volume = $state.level"
if (state.level != level) {
updateVolume(level)
}
}

def installed()
{
log.debug "in initialize"
state.currentVolume = volumeLevel
def installed() {
log.debug "installed"
initialize()
}

def setVolume(level)
{
if (level)
{
log.debug "In setVolume command: new level = $level"
sendEvent(name: "currentVolume", value: level)
state.currentVolume = level
updateVolume(level)
}
def initialize(){
log.debug "initialize"
// really should call refresh() after a runIn
Integer vol = level!=null ? level.toInteger() : 75
if (state.level != vol) {
updateDevState(vol)
}
}

def speak(message) {
Expand Down