Beispiel #1
0
 def sonos_write_szene(self, player):
     dicti = {}
     dicti['MasterZone'] = "Own"
     posinfo = self.GetPositionInfo(player)
     pos = self.GetPosition(player)
     transinfo = self.GetTransportInfo(player)
     for zone in self.Zones:
         if zone in posinfo:
             dicti['MasterZone'] = zone
     if dicti.get('MasterZone') == "Own":
         if "PLAYING" in transinfo:
             dicti['Pause'] = 0
         else:
             dicti['Pause'] = 1
         if "file" in posinfo:
             dicti['Radio'] = 0
         else:
             dicti['Radio'] = 1
         antwort = posinfo
         pos1 = antwort.find ('<TrackURI>',0) #('*&quot;&gt;',0)
         pos2 = antwort.find ('</TrackURI>',0) #('&lt;/res&gt;&lt;r:',0)
         dicti['Sender'] = antwort [pos1+10:pos2]
         dicti['TitelNr'] = int(pos[0])
         dicti['Time'] = pos[1]
     dicti['Volume'] = self.GetVolume(player)
     if player == self.WohnZi:
         playern = "WohnZi"
         plnum = 33
     elif player == self.Kueche:
         playern = "Kueche"
         plnum = 40
     elif player == self.Bad:
         playern = "Bad"
         plnum = 34
     elif player == self.SchlafZi:
         playern = "SchlafZi"
         plnum = 35
     else:
         playern = player
         plnum = 0
     self.SaveList(player, playern, plnum)
     mdb_set_table(table.name,self.Names.get(player),dicti) 
     return True
Beispiel #2
0
 def itera(self,some_object, only_change = False):
     dicti = {}
     if self.check_iter(some_object):
         if some_object.get('type') == 'group':
             eingang = some_object.get('name')
             if eingang in self.eingaenge and eingang <> None:
                 for aktuator in self.inputs:
                     if str(aktuator.get('Id')) == str(eingang):  
                         for kind in some_object.get('children'):
                             wert = some_object.get('children').get(kind).get('value')
                             if wert == '': wert = None
                             if wert <> aktuator.get(kind):
                                 dicti[kind] = wert
                         if self.isInputs:
                             mdb_set_table(table='cmd_inputs', device=str(aktuator.get('Id')), commands=dicti, primary = 'Id')
             else:
                 self.itera(some_object.get('children'))
         else:
             for item in some_object: 
                 self.itera(some_object.get(item))
 def itera(self,some_object):
     dicti = {}
     if self.check_iter(some_object):
         if some_object.get('type') == 'group':
             eingang = some_object.get('name')
             if eingang in self.eingaenge and eingang <> None:
                 for aktuator in self.inputs:
                     if str(aktuator.get('Id')) == str(eingang):  
                         for kind in some_object.get('children'):
                             wert = some_object.get('children').get(kind).get('value')
                             if wert == '': wert = None
                             if wert <> aktuator.get(kind):
                                 dicti[kind] = wert
                         if self.isInputs:
                             mdb_set_table(table=constants.sql_tables.inputs.name, device=str(aktuator.get('Id')), commands=dicti, primary = 'Id')
                         elif len(dicti) > 0:
                             mdb_set_table(table=self.cmdTable, device=str(aktuator.get('Id')), commands=dicti, primary = 'Id', translate = False)
             else:
                 self.itera(some_object.get('children'))
         else:
             for item in some_object: 
                 self.itera(some_object.get(item))
Beispiel #4
0
 def saveWecker(self):
     parent = {}
     for ii in weckerButtons:
         name = ii.objectName().split('.')[0]
         if name in parent:
             child = parent.get(name)
         else:
             parent[name] = {}
             child = {'Name':name}
         if "timeEdit" in ii.objectName():
             child['Time'] = ii.time().toString('HH:mm')
         elif "comboBox" in ii.objectName():
             child['Szene'] = ii.currentText()
         else:   
             if ii.checkState()  == 2:
                 child[ii.objectName().split('.')[1]] = True
             else:
                 child[ii.objectName().split('.')[1]] = False
         parent[name] = child
     liste = []
     for wecker in parent:
         liste.append(parent.get(wecker))
         mdb_set_table(table=constants.sql_tables.cron.name, device=parent.get(wecker).get('Name'), commands=parent.get(wecker), primary = 'Name')
Beispiel #5
0
 def set_device(self, device, commd):
     h_dev = Light(hbridge, device)
     keys = ['bri', 'hue', 'sat', 'transitiontime']
     szene = mdb_read_table_entry(table.name,commd)
     success = False
     if szene.get('bri')<=0:
         szene['bri'] = 0
         szene['on'] = False
     if commd in ["man", "auto"]:
         set_val_in_szenen(device=device, szene="Auto_Mode", value=commd)
         return True
     elif commd == 'Save': 
         hue = hbridge.get_light(device, 'hue')
         bri = hbridge.get_light(device, 'bri')
         sat = hbridge.get_light(device, 'sat')
         an = hbridge.get_light(device, 'on') 
         #{'hue': '7', 'bri': '2', 'sat': 'True', 'on': 'False'}
         setting = {'hue': hue, 'bri': bri, 'sat': sat, 'an': an}
         mdb_set_table(table.name,device, setting)
         return True
     elif commd == 'Umschalten':
         an = hbridge.get_light(device, 'on') 
         if an:
             szene['on'] = False
         else:
             szene['on'] = True
     elif commd == 'sz_toggle':
         an = hbridge.get_light(device, 'on') 
         if an:
             commd="SZ_Aus"
         else:
             szene['on'] = True
     bright = szene.get('bri')
     if bright <> None and bright>0:
         szene['bri'] = int(bright)
     if bright <> None and bright<=0:
         pass            
     if str(szene.get('on')) == "1" or str(szene.get('on')) == "True":
         success = h_dev.on
         retry = 1
         while not success and retry < max_retry:
             try:
                 hbridge.set_light(device, {'on':True}) 
                 success = h_dev.on
             except:
                 time.sleep(1)
                 success = False
                 retry += 1
         if not success:
             return success            
         time.sleep(0.5)
     command = {}
     for key in keys:
         if ((szene.get(key) <> "") and (str(szene.get(key)) <> "None")):
             command[key] = int(szene.get(key))
     if command <> {} and h_dev.on:
         success = False
         retry = 1
         while not success and retry < max_retry:
             try:
                 hbridge.set_light(device, command)
                 success = True
             except:
                 time.sleep(1)
                 success = False 
                 retry += 1
     if str(szene.get('on')) == "0" or str(szene.get('on')) == "False":
         success = not h_dev.on
         retry = 1
         if 'transitiontime' in command:
             if command['transitiontime'] > 0:
                 time.sleep(command['transitiontime']/10)
         while not success and retry < max_retry:
             try:
                 hbridge.set_light(device, {'on':False})  
                 success = not h_dev.on
             except:
                 time.sleep(1)
                 success = False 
                 retry += 1
     set_val_in_szenen(device=device, szene="Value", value=szene.get('on'))
     if not h_dev.reachable:
         success = False
         aes.new_event(description=str(device) + " not reachable", prio=1)
     return success
 def save(self):
     global state
     self.state = self.p.saveState()
     neu_szene = self.itera(self.state)
     print neu_szene
     mdb_set_table(table='set_Szenen', device=neu_szene.get('Id'), commands=neu_szene, primary = 'Id')
Beispiel #7
0
    def execute(self, szene, check_bedingung=False, wert = 0):
        szene_dict = mdb_read_table_entry(constants.sql_tables.szenen.name, szene)
        start_t = datetime.datetime.now()
#        print start_t, szene_dict.get("Beschreibung"), szene_dict.get("Follows")
        #check bedingung
        bedingungen = {}
        global kommando_dict
        erfuellt = True
        erfolg = False
        szn_id = uuid.uuid4()
        self.kommando_dict[szn_id] = []
        if str(szene_dict.get("Bedingung")) <> "None":
            bedingungen = eval(str(szene_dict.get("Bedingung")))   
        erfuellt = self.__bedingung__(bedingungen)
        if str(szene_dict.get("Latching")) <> 'None':
            next_start = szene_dict.get("LastUsed") + datetime.timedelta(hours=0, minutes=int(szene_dict.get("Latching")), seconds=0)
            if start_t < next_start:
                erfuellt = False
        if str(szene_dict.get("Karenz")) <> 'None':
            Karenz = (szene_dict.get("Karenz"))
        else:
            Karenz = 0.03  
        Prio = (szene_dict.get("Prio"))            
        if check_bedingung:
            return erfuellt
#==============================================================================
# commandos to devices and internal commands        
#==============================================================================
        if erfuellt:
            if (str(szene_dict.get("Delay")) <> "None"):
                time.sleep(float(szene_dict.get("Delay")))
            if str(szene_dict.get("Beschreibung")) in ['None','']:
                aes.new_event(description="Szenen: " + szene, prio=Prio, karenz = Karenz)
            else:
                aes.new_event(description= str(szene_dict.get("Beschreibung")), prio=Prio, karenz = Karenz) 
            interlocks = {}  
            hue_count = 0
            hue_delay = 0            
            if str(szene_dict.get("AutoMode")) == "True":
                interlocks = mdb_read_table_entry(constants.sql_tables.szenen.name,"Auto_Mode")
            for idk, key in enumerate(szene_dict):        
                if ((szene_dict.get(key) <> "") and (str(szene_dict.get(key)) <> "None") and (str(interlocks.get(key)) in ["None", "auto"])):
                    kommandos = self.__return_enum__(szene_dict.get(key))
                    if constants.redundancy_.master:
                        for kommando in kommandos:
                            if key in cmd_devs:
                                t_list = self.kommando_dict.get(szn_id)
                                t_list.append([key,kommando])
                                self.kommando_dict[szn_id] = t_list
                            text=szene_dict.get("Durchsage")
                            t = threading.Thread(target=self.__sub_cmds__, args=[szn_id, key, kommando, text])
                            t.start()  
#==============================================================================
# Internal                               
#==============================================================================
            key = "intCmd"
            if ((szene_dict.get(key) <> "") and (str(szene_dict.get(key)) <> "None") ):#and (str(interlocks.get(key)) in ["None", "auto"])):
                kommandos = self.__return_enum__(szene_dict.get(key))
                for kommando in kommandos:
                    #print kommando, kommandos.get(kommando)
                    set_del = Timer(0, interna.execute, [kommando])
                    #timer set to 0 for following actions
                    set_del.start()                              
#==============================================================================
# change settings table                                
#==============================================================================
            key = "Setting"
            if ((szene_dict.get(key) <> "") and (str(szene_dict.get(key)) <> "None") and (str(interlocks.get(key)) in ["None", "auto"])):
                kommandos = self.__return_enum__(szene_dict.get(key))
                for kommando in kommandos:
#                    #print kommando, kommandos.get(kommando)
#                    set_del = Timer(0, setting_s, [str(kommando), str(kommandos.get(kommando))])
#                    #timer set to 0 for following actions
#                    set_del.start() 
                    # solution above could give timing issues
                    setting_s(str(kommando), str(kommandos.get(kommando)))
            mdb_set_table(table=constants.sql_tables.szenen.name, device=szene, commands={'LastUsed':start_t})
        else:
            if str(szene_dict.get("Beschreibung")) in ['None','']:
                aes.new_event(description="Szene nicht erfuellt: " + szene, prio=1, karenz = Karenz)
            else:
                aes.new_event(description="Szene nicht erfuellt: " + str(szene_dict.get("Beschreibung")), prio=1, karenz = Karenz)                 
#==============================================================================
# cacnel timers                              
#==============================================================================     
        if ((szene_dict.get("Cancels") <> "") and (str(szene_dict.get("Cancels")) <> "None")):
            kommandos = self.__return_enum__(szene_dict.get("Cancels"))   
            for kommando in kommandos:           
                self.sz_t.cancel_timer(parent = szene, child = kommando)
#==============================================================================
# start timer with following actions                               
#==============================================================================
        if ((szene_dict.get("Follows") <> "") and (str(szene_dict.get("Follows")) <> "None")):
            kommandos = self.__return_enum__(szene_dict.get("Follows"))
            for kommando in kommandos:
                szn = kommando[0]
                dlay = kommando[1]
                ex_re = kommando[2]
                immer = False
                depErfolg = 0
                if len(kommando) > 3:
                    immer = not kommando[3]
                if len(kommando) == 5:
                    depErfolg = kommando[4]
                if (immer or erfuellt) and depErfolg == 0:
                    if ex_re == 0:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = False, retrig = True)
                    elif ex_re == 1:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = True, retrig = True)
                    elif ex_re == 2:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = False, retrig = False)  
#==============================================================================
# Check for timeout
#==============================================================================
        while datetime.datetime.now() - start_t < self.timeout:
            t_list = self.kommando_dict.get(szn_id)
            time.sleep(.1)
            if len(t_list) == 0:
                erfolg = True
                # write back to table
                break
        t_list = self.kommando_dict.get(szn_id)
        for item in t_list:
            aes.new_event(description="CMD Timeout: " + str(item), prio=1, karenz = 0.03)
        del self.kommando_dict[szn_id]
#==============================================================================
# start timer with following actions nur wenn erfolg oder nicht erfolg                              
#==============================================================================
        if ((szene_dict.get("Follows") <> "") and (str(szene_dict.get("Follows")) <> "None")):
            kommandos = self.__return_enum__(szene_dict.get("Follows"))
            for kommando in kommandos:
                szn = kommando[0]
                dlay = kommando[1]
                ex_re = kommando[2]
                immer = False
                depErfolg = 0
                if len(kommando) > 3:
                    immer = kommando[3]
                if len(kommando) == 5:
                    depErfolg = kommando[4]
                if (immer or erfuellt) and ((depErfolg == 1 and erfolg) or (depErfolg == 2 and not erfolg)):
                    if ex_re == 0:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = False, retrig = True)
                    elif ex_re == 1:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = True, retrig = True)
                    elif ex_re == 2:
                        self.sz_t.retrigger_add(parent = szene,delay = float(dlay), child = szn, exact = False, retrig = False)           
        return erfolg