aboutsummaryrefslogtreecommitdiff
path: root/ParrotZikTray
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 01:52:50 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 01:53:22 +0200
commit8dd3e12ec52cf993856bc0ea3601cc1c07acce1b (patch)
treeb6d3993bc0c1fc40979d8e9ce8d55f5405fff613 /ParrotZikTray
parentffa76dd958282735c1b39793351a075a3d1a64ac (diff)
downloadpyParrotZikTCP-8dd3e12ec52cf993856bc0ea3601cc1c07acce1b.tar.xz
pyParrotZikTCP-8dd3e12ec52cf993856bc0ea3601cc1c07acce1b.zip
Handle connection errors through Exceptions.
Diffstat (limited to '')
-rwxr-xr-xParrotZikTray38
1 files changed, 21 insertions, 17 deletions
diff --git a/ParrotZikTray b/ParrotZikTray
index e43ac90..55713b3 100755
--- a/ParrotZikTray
+++ b/ParrotZikTray
@@ -67,22 +67,27 @@ class ParrotZikIndicator(SysIndicator):
else:
self.reconnect.stop()
else:
- mac = bluetooth_paired_devices.get_parrot_zik_mac()
- if mac:
- self.info_item.set_label("Connecting")
- resource_manager = connect(mac)
- if resource_manager.sock:
- if resource_manager.api_version.startswith('1'):
- self.version_1_interface.activate(resource_manager)
- else:
- self.version_2_interface.activate(resource_manager)
- self.autorefresh(self)
- self.autorefresh.start(self, REFRESH_FREQUENCY)
- self.reconnect.stop()
- else:
- self.info_item.set_label("Failed to connect")
+ self.info("Trying to connect")
+ try:
+ resource_manager = connect()
+ except bluetooth_paired_devices.BluetoothIsNotOn:
+ self.info("Bluetooth is turned off")
+ except bluetooth_paired_devices.DeviceNotConnected:
+ self.info("Parrot Zik Not connected")
+ except bluetooth_paired_devices.ConnectionFailure:
+ self.info("Failed to connect")
else:
- self.info_item.set_label("Parrot Zik Not connected")
+ if resource_manager.api_version.startswith('1'):
+ self.version_1_interface.activate(resource_manager)
+ else:
+ self.version_2_interface.activate(resource_manager)
+ self.autorefresh(self)
+ self.autorefresh.start(self, REFRESH_FREQUENCY)
+ self.reconnect.stop()
+
+ def info(self, message):
+ self.info_item.set_label(message)
+ print(message)
@repeat
def autorefresh(self):
@@ -123,8 +128,7 @@ class ParrotZikBaseInterface(object):
def activate(self, resource_manager):
self.parrot = self.parrot_class(resource_manager)
self.read_battery()
- self.indicator.info_item.set_label("Connected to: "
- + self.parrot.friendly_name)
+ self.indicator.info("Connected to: " + self.parrot.friendly_name)
self.firmware_version.set_label(
"Firmware version: " + self.parrot.version)
self.auto_connection.set_active(self.parrot.auto_connect)