#!/usr/bin/python
"""
openhab_test - Sends a command from ROS to Openhab, via the openhab_bridge.
The command will turn the Ground Floor Corridor heating unit off
The commented publisher would instead set the status for the GF Corridor heating unit
"""
"""
Copyright (c) 2015, Answer17.  All rights reserved.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of openhab_bridge nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
import rospy
from diagnostic_msgs.msg import KeyValue
from time import sleep

# Publish a value to openhab to send a command to a device
pub = rospy.Publisher('openhab_command', KeyValue, queue_size=10)

# alternatively, publish a value to openhab to set the state of a device
# pub = rospy.Publisher('openhab_set', KeyValue, queue_size=10)

rospy.init_node('habtest', anonymous=True)
print "Turning Heating_GF_Corridor ON"

# First value must match name of item in openhab .items file
# Second value must be a valid setting for the item.  
pub.publish("Heating_GF_Corridor", "ON")

# Send command to get a full refresh of all (ROS) items
#pub.publish("ROS_COMMAND", "REFRESH")
sleep(2)    # Give time for command to be published
