def test_datetime_command(): dt_obj = openhab.get_item('TheDateTime') dt_utc_now = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc) dt_obj.command(dt_utc_now) assert dt_obj.state.isoformat(timespec='seconds') == dt_utc_now.isoformat( timespec='seconds')
def test_null_undef(): float_obj = openhab.get_item('floattest') float_obj.update_state_null() assert float_obj.is_state_null() float_obj.update_state_undef() assert float_obj.is_state_undef()
def convert_hls_to_rgb(hls): h, l, s = hls.split(',') rgb = colorsys.hls_to_rgb( round(float(h)) / 360.0, round(float(l)) / 100., round(float(s)) / 100.) return rgb base_url = 'http://localhost:8080/rest' #--------------- GET THE COLOR #get the Item color from OpenHab plafond_couleur = openhab.get_item(base_url, 'plafond_couleur') #get the Color HLS HLS = plafond_couleur.state #COnvert Hls to RGB Triplet RGB = convert_hls_to_rgb(plafond_couleur.state) #Convert from % to Value R = int(RGB[0] * 255) G = int(RGB[1] * 255) B = int(RGB[2] * 255) print('RGB : ( ', R, ' -- ', G, ' -- ', B, ' )') #--------------- GET THE FREQUENCE Propertie_frequence = openhab.get_item(base_url, 'plafond_frequence')
@author: E-Wall Group """ import sqlite3 import openhab import datetime import selectionBDD as DB base_url = 'http://localhost:8080/rest' # fetch all items #items = openhab.fetch_all_items(base_url) #--------------------------------------get Sentiment from OpenHub print('GET SENTIMENT ...') sentiment = openhab.get_item(base_url, 'emotion_item') #sentiment.state = 'Suprised' #Happy Sad Suprised Neutral Angry #--------------------------------------get dependances of configurations from Sqlite ( ) print('GET DEPENDANCES FROM DATABASE ...') #Connection Database conn = sqlite3.connect( '/home/amine/projets/Emotions_project/Dependances/db/WALL-E-Motion.db') #get Properties and Animation properties = DB.getProperties(conn, sentiment.state)[0] animation = DB.getAnimation(conn, sentiment.state)[0] property_color = properties[0] property_frequence = properties[1]
def test_float(): float_obj = openhab.get_item('floattest') float_obj.state = 1.0 assert float_obj.state == 1.0
#!/usr/bin/python # -*- coding: utf-8 -*- import openhab import display # Create display display = display.Display() value = openhab.get_item("Present") display.set_line_1("# Status #",1,True) display.set_line_2("Present:"+str(value.text),2,False)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with python-openhab. If not, see <http://www.gnu.org/licenses/>. # import openhab base_url = 'http://localhost:8080/rest' openhab = openhab.OpenHAB(base_url) # fetch all items print(" - Print all items:") all_items = openhab.fetch_all_items() for i in all_items.values(): print(i) # fetch some group lights_group = openhab.get_item("Lights") print(" - Send command to group") lights_group.on() print(" - Update all lights to OFF") for v in lights_group.members.values(): v.update('OFF') print(" - Print all lights:") for v in lights_group.members.values(): print(v)
def test_non_latin1_string(): string_obj = openhab.get_item('stringtest') string_obj.state = 'שלום' assert string_obj.state == 'שלום'
def is_switch_on(): switch_item = openhab.get_item(base_url, 'test_switch') if (switch_item.state == "ON"): return True return False
def set_openhab_emotion_text(emotion_result): emotion_text = openhab.get_item(base_url, 'emotion_item') emotion_text.state = emotion_result