fix behaviour of remote
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / RemoteControl.py
1 from enigma import eActionMap
2 from Components.Sources.Source import Source
3 from Tools.HardwareInfo import HardwareInfo
4 from Components.config import config
5 class RemoteControl(Source):
6         # Flags
7         FLAG_MAKE = 0
8         FLAG_BREAK = 1
9         FLAG_REPEAT = 2
10         FLAG_LONG = 3
11         FLAG_ASCII = 4
12         
13         #Device Types
14         TYPE_STANDARD = "dreambox remote control (native)"
15         TYPE_ADVANCED = "dreambox advanced remote control (native)"
16         TYPE_KEYBOARD = "dreambox ir keyboard"
17                 
18         def __init__(self, session):
19                 self.cmd = None
20                 self.session = session
21                 Source.__init__(self)
22                 self.res = ( False, "Missing or wrong argument" )
23                 self.eam = eActionMap.getInstance()
24                 
25                 #Advanced remote or standard?
26                 
27                 if config.misc.rcused.value == 0:
28                         self.remotetype = self.TYPE_ADVANCED
29                 else:
30                         self.remotetype = self.TYPE_STANDARD
31                         
32                 print "[RemoteControl.__init__] Configured RCU-Type is '%s'" %(self.remotetype)                                                                         
33
34         def handleCommand(self, cmd):
35                 self.cmd = cmd
36                 self.res = self.sendEvent()
37
38         def sendEvent(self):
39                 if not self.cmd:
40                         print "[RemoteControl.sendEvent] cmd is empty or None"
41                         return self.res
42                 
43                 key = self.cmd.get("command", None)
44                 if key is None:
45                         print "[RemoteControl.sendEvent] Obligatory parameter 'command' is missing!"
46                         return ( False, "Obligatory parameter 'command' is missing!" )
47
48                 key = int(key)
49
50                 if key <= 0:                    
51                         print "[RemoteControl.sendEvent] command <= 0 (%s)" % key
52                         return ( False, "the command was not > 0" )
53
54                 #type can be "long" or "ascii", everything else will result in FLAG_MAKE
55                 type = self.cmd.get('type', '')
56                 flag = self.FLAG_MAKE
57                 if type == "long":
58                         #Doesn't work yet (WHY?)
59                         #TODO Fix long key press
60                         flag = self.FLAG_LONG
61                 elif type == "ascii":
62                         flag = self.FLAG_ASCII
63                         
64                 remotetype = self.cmd.get("rcu", None)
65
66                 if remotetype == "standard":
67                         remotetype = self.TYPE_STANDARD
68                 elif remotetype == "advanced":
69                         remotetype = self.TYPE_ADVANCED
70                 elif remotetype == "keyboard":
71                         remotetype == self.TYPE_KEYBOARD
72                 else:
73                         remotetype = self.remotetype
74                 
75                 #If type=="long" we need to press send FLAG_MAKE first 
76                 if(flag == self.FLAG_LONG):                     
77                         self.eam.keyPressed(remotetype, key, self.FLAG_MAKE)
78                 
79                 #press the key with the desired flag
80                 self.eam.keyPressed(remotetype, key, flag)
81                 #Release the key                
82                 self.eam.keyPressed(remotetype, key, self.FLAG_BREAK)
83                         
84                 print "[RemoteControl.sendEvent] command was was sent (key: %s, flag: %s)" %(key, flag)
85                 return ( True, "RC command '" + str(key) + "' has been issued" ) 
86
87         result = property(lambda self: self.res)