[SessionGlobals] add session.HddSleepingState
authorDima73 <Dima-73@inbox.lv>
Sat, 26 Sep 2015 14:15:22 +0000 (17:15 +0300)
committerErik Slagter <erik@openpli.org>
Fri, 2 Oct 2015 10:10:49 +0000 (12:10 +0200)
-only internal hdd
-default poll interval 60 sec

<widget source="session.HddSleepingState" render="Pixmap"
pixmap="skin_default/icons/hdd.png" foregroundColor="#ff0000"
size="50,60"  position="600,400" zPosition="1" alphatest="blend" >

<convert type="ConditionalShowHide"/>
  </widget>

(cherry picked from commit 94f2c93298a3fe14b85f86e5999d11cb532e25f8)
Signed-off-by: Erik Slagter <erik@openpli.org>

data/skin_default/icons/hdd.png [new file with mode: 0644]
data/skin_display_et8500.xml
lib/python/Components/Sources/HddState.py [new file with mode: 0644]
lib/python/Screens/SessionGlobals.py

diff --git a/data/skin_default/icons/hdd.png b/data/skin_default/icons/hdd.png
new file mode 100644 (file)
index 0000000..99b02d0
Binary files /dev/null and b/data/skin_default/icons/hdd.png differ
index 56cf0c3..7caa211 100644 (file)
                <widget source="session.CurrentService" render="Picon" zPosition="13" position="224,394" size="242,142" transparent="1" alphatest="blend">
                        <convert type="ServiceName">Reference</convert>
                </widget>
+               <widget source="session.HddSleepingState" render="Pixmap" pixmap="skin_default/icons/hdd.png" foregroundColor="#ff0000" size="50,60"  position="600,400" zPosition="1" alphatest="blend" >
+                       <convert type="ConditionalShowHide"/>
+               </widget>
        </screen>
 <!-- normal radiomodus-->
        <screen name="ChannelSelectionRadio_summary" position="0,0" size="720,576">
                <widget source="parent.RdsDecoder" render="Label" position="15,20" foregroundColor="#e5b243" size="670,220" font="FdLcD;40" halign="center" valign="top">
                        <convert type="RdsInfo">RtpText</convert>
                </widget>
-               <widget source="parent.Service" render="Picon" zPosition="13" position="200,300" size="400,240" transparent="1" alphatest="blend">      
+               <widget source="parent.Service" render="Picon" zPosition="13" position="200,300" size="400,240" transparent="1" alphatest="blend">
                        <convert type="ServiceName">Reference</convert>
                </widget>
        </screen>
                <widget source="session.RecordState" render="FixedLabel" text="&#174;" position="600,470" foregroundColor="#ff0000" size="80,80" font="FdLcD;80" halign="center" valign="center" zPosition="1">
                        <convert type="ConditionalShowHide">Blink</convert>
                </widget>
+               <widget source="session.HddSleepingState" render="Pixmap" pixmap="skin_default/icons/hdd.png" foregroundColor="#ff0000" size="50,60"  position="600,400" zPosition="1" alphatest="blend" >
+                       <convert type="ConditionalShowHide"/>
+               </widget>
        </screen>
 <!-- plugin browser -->
        <screen name="PluginBrowserSummary" position="0,0" size="720,576"> 
diff --git a/lib/python/Components/Sources/HddState.py b/lib/python/Components/Sources/HddState.py
new file mode 100644 (file)
index 0000000..d870975
--- /dev/null
@@ -0,0 +1,65 @@
+from Source import Source
+from Components.Element import cached
+from Components.Harddisk import harddiskmanager
+from Components.config import config
+from enigma import eTimer, eConsoleAppContainer
+
+class HddState(Source):
+       def __init__(self, session, poll=60):
+               Source.__init__(self)
+               self.isSleeping = False
+               self.session = session
+               self.standby_time = poll
+               self.timer = eTimer()
+               self.idle_time = int(config.usage.hdd_standby.value)
+               config.usage.hdd_standby.addNotifier(self.setStandbyTime, initial_call=False)
+               self.timer.callback.append(self.runIdle)
+               self.hdd = self.isInternalHDD()
+               self.container = eConsoleAppContainer()
+               if self.hdd:
+                       if self.idle_time:
+                               self.runIdle()
+                       else:
+                               self.isSleeping = True
+
+       def runIdle(self):
+               if self.hdd and self.idle_time:
+                       cmd = "hdparm -C %s" % self.hdd[1].disk_path
+                       self.container.dataAvail.append(self.setHddState)
+                       self.container.execute(cmd)
+
+       def setHddState(self, str):
+               self.container.dataAvail.remove(self.setHddState)
+               prev_state = self.isSleeping
+               if 'standby' in str:
+                       self.isSleeping = False
+                       idle = self.standby_time
+               else:
+                       self.isSleeping = True
+                       idle = self.idle_time
+               if prev_state != self.isSleeping:
+                       self.changed((self.CHANGED_ALL,))
+               self.timer.startLongTimer(idle)
+
+       def setStandbyTime(self, cfgElem):
+               self.timer.stop()
+               self.idle_time = int(cfgElem.value)
+               if self.idle_time and self.hdd:
+                       self.timer.startLongTimer(self.standby_time)
+
+       def isInternalHDD(self):
+               if harddiskmanager.HDDCount():
+                       for hdd in harddiskmanager.HDDList():
+                               if "pci" in hdd[1].phys_path or "ahci" in hdd[1].phys_path:
+                                       return hdd
+               return None
+
+       @cached
+       def getBoolean(self):
+               return self.isSleeping and True or False
+       boolean = property(getBoolean)
+
+       @cached
+       def getValue(self):
+               return self.isSleeping
+       value = property(getValue)
index 41b8431..b532e21 100644 (file)
@@ -7,6 +7,7 @@ from Components.Sources.Source import Source
 from Components.Sources.TunerInfo import TunerInfo
 from Components.Sources.Boolean import Boolean
 from Components.Sources.RecordState import RecordState
+from Components.Sources.HddState import HddState
 from Components.Converter.Combine import Combine
 from Components.Renderer.FrontpanelLed import FrontpanelLed
 
@@ -22,12 +23,14 @@ class SessionGlobals(Screen):
                self["TunerInfo"] = TunerInfo()
                self["RecordState"] = RecordState(session)
                self["Standby"] = Boolean(fixed = False)
+               self["HddSleepingState"] = HddState(session)
 
                from Components.SystemInfo import SystemInfo
 
                combine = Combine(func = lambda s: {(False, False): 0, (False, True): 1, (True, False): 2, (True, True): 3}[(s[0].boolean, s[1].boolean)])
                combine.connect(self["Standby"])
                combine.connect(self["RecordState"])
+               combine.connect(self["HddSleepingState"])
 
                #                      |  two leds  | single led |
                # recordstate  standby   red green