diff --git a/btdevicesmanager/src/bluetoothctl.py b/btdevicesmanager/src/bluetoothctl.py index 6d3da0eb2..504d60b11 100644 --- a/btdevicesmanager/src/bluetoothctl.py +++ b/btdevicesmanager/src/bluetoothctl.py @@ -214,10 +214,14 @@ def trust(self, mac_address): print(e) return False else: - res = self.process.expect( - [".*not available\r\n", "trust succe", EOF] - ) - return res == 1 + try: + res = self.process.expect( + [".*not available\r\n", "trust succe", EOF] + ) + return res == 1 + except Exception as e: + print(e) + return False def remove(self, mac_address): """Remove paired device by mac address, return success of the operation.""" @@ -227,10 +231,14 @@ def remove(self, mac_address): print(e) return False else: - res = self.process.expect( - ["not available", "Device has been removed", EOF] - ) - return res == 1 + try: + res = self.process.expect( + ["not available", "Device has been removed", EOF] + ) + return res == 1 + except Exception as e: + print(e) + return False def connect(self, mac_address): """Try to connect to a device by mac address.""" @@ -240,10 +248,14 @@ def connect(self, mac_address): print(e) return False else: - res = self.process.expect( - ["Failed to connect", "Connection successful", EOF] - ) - return res == 1 + try: + res = self.process.expect( + ["Failed to connect", "Connection successful", EOF] + ) + return res == 1 + except Exception as e: + print(e) + return False def disconnect(self, mac_address): """Try to disconnect to a device by mac address.""" @@ -253,10 +265,14 @@ def disconnect(self, mac_address): print(e) return False else: - res = self.process.expect( - ["Failed to disconnect", "Successful disconnected", EOF] - ) - return res == 1 + try: + res = self.process.expect( + ["Failed to disconnect", "Successful disconnected", EOF] + ) + return res == 1 + except Exception as e: + print(e) + return False def agent_noinputnooutput(self): """Start agent""" diff --git a/btdevicesmanager/src/plugin.py b/btdevicesmanager/src/plugin.py index b60827c01..c4614f552 100644 --- a/btdevicesmanager/src/plugin.py +++ b/btdevicesmanager/src/plugin.py @@ -30,6 +30,7 @@ from Components.ActionMap import ActionMap from Components.config import config, ConfigText, ConfigSubsection, ConfigYesNo from Components.MenuList import MenuList +from Components.SystemInfo import BoxInfo from Components.ServiceEventTracker import ServiceEventTracker from Plugins.Plugin import PluginDescriptor from Screens.Screen import Screen @@ -57,12 +58,13 @@ class BluetoothDevicesManager(Screen): + - + """ @@ -84,7 +86,7 @@ def __init__(self, session): self["key_red"] = StaticText(_("Exit")) self["key_green"] = StaticText(_("Scan")) - self["key_yellow"] = StaticText(_("Connect")) + self["key_yellow"] = StaticText("") self["key_blue"] = StaticText("") self["ConnStatus"] = Label(_("Not connected to any device")) @@ -152,7 +154,14 @@ def readDeviceList(self): if self.devicelist: self["ConnStatus"].setText("") else: - self["ConnStatus"].setText(_("No connected to any device")) + info_text = "" + if BoxInfo.getItem("model") == "gbquad4kpro": + info_text = "\n" +_("Press Menu+OK keys on the BT/IR remote control until the LED starts flashing. The 'GIGABLUE-BT20' remote will appear during the scan.") + elif BoxInfo.getItem("model") == "gbtrio4kpro": + info_text = "\n" +_("Press Info+OK keys on the BT/IR remote control until the LED starts flashing.") + #elif BoxInfo.getItem("model") == "sf8008": + # info_text = "\n" +_("Hold down the OK button on the BT remote control (bluetooth RCU06) until the LED flashes. The 'DEFINE' remote will appear during the scan.") + self["ConnStatus"].setText(_("Not connected to any device") + info_text) self["devicelist"].setList(self.devicelist) self.selectionChanged() @@ -335,8 +344,9 @@ def poll(self): def flush(self): try: - pid = open("/var/run/aplay.pid").read().split()[0] - kill(int(pid), SIGUSR2) + if isfile("/var/run/aplay.pid"): + pid = open("/var/run/aplay.pid").read().split()[0] + kill(int(pid), SIGUSR2) except Exception: pass self.timestamp = datetime.now()