add discrete wakeup/standby codes to /web/powerstate?newstate=.
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / PowerState.py
1 from Components.Sources.Source import Source
2
3 class PowerState(Source):
4         def __init__(self, session):
5                 self.cmd = None
6                 self.session = session
7                 Source.__init__(self)
8
9         def handleCommand(self, cmd):
10                 self.cmd = cmd
11
12         def getStandby(self):
13                 from Screens.Standby import inStandby
14                 if inStandby == None:
15                         return "false"
16                 else:
17                         return "true"
18
19         def getText(self):
20                 if self.cmd == "" or self.cmd is None:
21                         return self.getStandby()
22
23                 #-1: get current state
24                 # 0: toggle standby
25                 # 1: poweroff/deepstandby
26                 # 2: rebootdreambox
27                 # 3: rebootenigma
28                 # 4: wakeup (if not already awake)
29                 # 5: standby
30                 try:
31                         from Screens.Standby import inStandby
32                         from Screens.Standby import Standby
33                         type = int(self.cmd)
34                         if type == -1:
35                                 return self.getStandby()
36
37                         elif type == 0:
38                                 print "[PowerState.py] Standby 0"
39                                 if inStandby == None:                                   
40                                         self.session.open(Standby)
41                                         return "true"
42                                 else:
43                                         inStandby.Power()
44                                         return "false"
45                                                         
46                         elif type == 4:
47                                 print "[PowerState.py] Standby 4"
48                                 if inStandby != None:
49                                         inStandby.Power()
50                                         return "false"
51                                 else:
52                                         return "true"
53                         elif type == 5:
54                                 print "[PowerState.py] Standby 5"
55                                 if inStandby == None:                                   
56                                         self.session.open(Standby)
57                                         return "true"   
58                                 else:
59                                         return "false"
60                                 
61                         elif 0 < type < 4:
62                                 print "[PowerState.py] TryQuitMainloop"
63                                 from Screens.Standby import TryQuitMainloop
64                                 self.session.open(TryQuitMainloop, type)
65                                 return "true"
66                                                         
67                         else:
68                                 print "[PowerState.py] cmd unknown" % type
69                                 return "error"
70                         
71                 except ValueError:
72                         return "error"
73
74         text = property(getText)