<commit_before>/**
 *  Color Coordinator 
 *  Version 1.0.1 - 12/28/15
 *  By <NAME>
 *
 *  1.0.0 - Initial release
 *  1.0.1 - Interface revisions and fix to temperature syncing issue between master and slaves
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
	name: "Color Coordinator",
	namespace: "MichaelStruck",
	author: "<NAME>",
	description: "Ties multiple colored lights to one specific light's settings",
	category: "Convenience",
	iconUrl: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC.png",
	iconX2Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC@2x.png"
)

preferences {
	page name: "mainPage"
}

def mainPage() {
	dynamicPage(name: "mainPage", title: "", install: true, uninstall: false) {
		section("Master Light") {
			input "master", "capability.colorControl", title: "Colored Light"
		}
		section("Lights that follow the master settings") {
			input "slaves", "capability.colorControl", title: "Colored Lights",  multiple: true, required: false
		}
    	section([mobileOnly:true], "Options") {
			label(title: "Assign a name", required: false)
			href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license, instructions or to remove the application"
        }
	}
}

page(name: "pageAbout", title: "About ${textAppName()}", uninstall: true) {
	section {
    	paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
	}
	section("Instructions") {
		paragraph textHelp()
	}
    section("Tap button below to remove application"){
    }
}

def installed() {   
	init() 
}

def updated(){
	unsubscribe()
    init()
}

def init() {
	subscribe(master, "switch", onOffHandler)
	subscribe(master, "level", colorHandler)
    subscribe(master, "hue", colorHandler)
    subscribe(master, "saturation", colorHandler)
    subscribe(master, "colorTemperature", tempHandler)
}
//-----------------------------------
def onOffHandler(evt){
	if (master.currentValue("switch") == "on"){
    	slaves?.on()
    }
    else {
		slaves?.off()  
    }
}

def colorHandler(evt) {
   	def dimLevel = master.currentValue("level")
    def hueLevel = master.currentValue("hue")
    def saturationLevel = master.currentValue("saturation")
	def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
    slaves?.setColor(newValue)
    def tempLevel = master.currentValue("colorTemperature")
    slaves?.setColorTemperature(tempLevel)
}

def tempHandler(evt){
    if (evt.value != "--") {
    	def tempLevel = master.currentValue("colorTemperature")
    	slaves?.setColorTemperature(tempLevel)
    }
}

//Version/Copyright/Information/Help

private def textAppName() {
	def text = "Color Coordinator"
}	

private def textVersion() {
    def text = "Version 1.0.1 (12/28/2015)"
}

private def textCopyright() {
    def text = "Copyright © 2015 <NAME>"
}

private def textLicense() {
    def text =
		"Licensed under the Apache License, Version 2.0 (the 'License'); "+<commit_msg>Update ColorCoordinator.groovy<commit_after>/**
 *  Color Coordinator 
 *  Version 1.0.1 - 12/28/15
 *  By <NAME>
 *
 *  1.0.0 - Initial release
 *  1.0.1 - Interface revisions and fix to temperature syncing issue between master and slaves
 *
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
definition(
	name: "Color Coordinator",
	namespace: "MichaelStruck",
	author: "<NAME>",
	description: "Ties multiple colored lights to one specific light's settings",
	category: "Convenience",
	iconUrl: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC.png",
	iconX2Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC@2x.png"
)

preferences {
	page name: "mainPage"
}

def mainPage() {
	dynamicPage(name: "mainPage", title: "", install: true, uninstall: false) {
		section("Master Light") {
			input "master", "capability.colorControl", title: "Colored Light"
		}
		section("Lights that follow the master settings") {
			input "slaves", "capability.colorControl", title: "Colored Lights",  multiple: true, required: false
		}
    	section([mobileOnly:true], "Options") {
			label(title: "Assign a name", required: false)
			href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license, instructions or to remove the application"
        }
	}
}

page(name: "pageAbout", title: "About ${textAppName()}", uninstall: true) {
	section {
    	paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
	}
	section("Instructions") {
		paragraph textHelp()
	}
    section("Tap button below to remove application"){
    }
}

def installed() {   
	init() 
}

def updated(){
	unsubscribe()
    init()
}

def init() {
	subscribe(master, "switch", onOffHandler)
	subscribe(master, "level", colorHandler)
    subscribe(master, "hue", colorHandler)
    subscribe(master, "saturation", colorHandler)
    subscribe(master, "colorTemperature", tempHandler)
}
//-----------------------------------
def onOffHandler(evt){
	if (master.currentValue("switch") == "on"){
    	slaves?.on()
    }
    else {
		slaves?.off()  
    }
}

def colorHandler(evt) {
   	log.debug "Changing Slave units H,S,L"
    def dimLevel = master.currentValue("level")
    def hueLevel = master.currentValue("hue")
    def saturationLevel = master.currentValue("saturation")
	def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
    slaves?.setColor(newValue)
    try {
    	log.debug "Changing Slave color temp"
        def tempLevel = master.currentValue("colorTemperature")
    	slaves?.setColorTemperature(tempLevel)
    }
    catch (e){
    	log.debug "Color temp for master --"
    }
}

def tempHandler(evt){
    if (evt.value != "--") {
    	log.debug "Changing Slave color temp based on Master change"
        def tempLevel = master.currentValue("colorTemperature")
    	slaves?.setColorTemperature(tempLevel)
    }
}

//Version/Copyright/Information/Help

private def textAppName() {
	def text = "Color Coordinator"
}	

private def textVersion() {
    def text = "Version 1.0.1 (12/28/2015)"
}

private def textCopyright() {
    def text = "Copyright © 2015 <NAME>"
}

private def textLicense() {
    def text =
		"Licensed under the Apache License, Version 2.0 (the 'License'); "+
{'fraction_non_alphanumeric': 0.13758389261744966, 'fraction_numerical': 0.010201342281879194, 'mean_word_length': 3.8859016393442625, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6610760', 'n_tokens_mistral': 2359, 'n_tokens_neox': 2254, 'n_words': 654}