InputDevice: Simplify RcTypeControl class
authorAthanasios Oikonomou <athoik@gmail.com>
Tue, 5 Jan 2016 12:39:27 +0000 (14:39 +0200)
committerErik Slagter <erik@openpli.org>
Wed, 6 Jan 2016 09:50:16 +0000 (10:50 +0100)
Do not use pathExists but use directly os.path.exists

Also, make sure that rctype has value else write the default 0, this prevents
the following error to happen when switching RC.

TypeError: %d format: a number is required, not NoneType
(cherry picked from commit 10d3a8108688f2e387bed06924a77ee0fdcb6344)
Signed-off-by: Erik Slagter <erik@openpli.org>

lib/python/Components/InputDevice.py

index be7b68c..c570a74 100644 (file)
@@ -1,5 +1,4 @@
 from config import config, ConfigSlider, ConfigSubsection, ConfigYesNo, ConfigText, ConfigInteger
-from Tools.Directories import pathExists
 from SystemInfo import SystemInfo
 from fcntl import ioctl
 import os
@@ -197,15 +196,10 @@ config.plugins.remotecontroltype.rctype = ConfigInteger(default = 0)
 
 class RcTypeControl():
        def __init__(self):
-               if SystemInfo["RcTypeChangable"] and pathExists('/proc/stb/info/boxtype'):
+               if SystemInfo["RcTypeChangable"] and os.path.exists('/proc/stb/info/boxtype'):
                        self.isSupported = True
-
-                       fd = open('/proc/stb/info/boxtype', 'r')
-                       self.boxType = fd.read()
-                       fd.close()
-
-                       if config.plugins.remotecontroltype.rctype.value != 0:
-                               self.writeRcType(config.plugins.remotecontroltype.rctype.value)
+                       self.boxType = open('/proc/stb/info/boxtype', 'r').read().strip()
+                       self.writeRcType(config.plugins.remotecontroltype.rctype.value)
                else:
                        self.isSupported = False
 
@@ -216,8 +210,6 @@ class RcTypeControl():
                return self.boxType
 
        def writeRcType(self, rctype):
-               fd = open('/proc/stb/ir/rc/type', 'w')
-               fd.write('%d' % (rctype))
-               fd.close()
+               open('/proc/stb/ir/rc/type', 'w').write(rctype and '%d' % rctype or '0')
 
 iRcTypeControl = RcTypeControl()