diff options
author | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-12 23:01:36 +0200 |
---|---|---|
committer | Marek Siarkowicz <mareksiarkowicz@gmail.com> | 2015-06-12 23:01:36 +0200 |
commit | a9cfa13c5718bac0dd62a2aef0c39bc05590e55e (patch) | |
tree | 3be881c1c82808853b479953644bba049db75df4 | |
parent | efb6d2808391ffc006996cacc70273fd67f12513 (diff) | |
download | pyParrotZikTCP-a9cfa13c5718bac0dd62a2aef0c39bc05590e55e.tar.xz pyParrotZikTCP-a9cfa13c5718bac0dd62a2aef0c39bc05590e55e.zip |
Display true values.
-rw-r--r-- | ParrotZik.py | 33 | ||||
-rwxr-xr-x | ParrotZikTray | 51 |
2 files changed, 41 insertions, 43 deletions
diff --git a/ParrotZik.py b/ParrotZik.py index d159927..514be50 100644 --- a/ParrotZik.py +++ b/ParrotZik.py @@ -94,7 +94,8 @@ class ParrotZik(object): @property def auto_connect(self): data = self.get("/api/system/auto_connection/enabled/get") - return data.answer.system.auto_connection["enabled"] + return self._result_to_bool( + data.answer.system.auto_connection["enabled"]) @auto_connect.setter def auto_connect(self, arg): @@ -103,12 +104,17 @@ class ParrotZik(object): @property def anc_phone_mode(self): data = self.get("/api/system/anc_phone_mode/enabled/get") - return data.answer.system.anc_phone_mode["enabled"] + return self._result_to_bool( + data.answer.system.anc_phone_mode["enabled"]) @property def noise_cancel(self): data = self.get("/api/audio/noise_cancellation/enabled/get") - return data.answer.audio.noise_cancellation["enabled"] + try: + return self._result_to_bool( + data.answer.audio.noise_cancellation["enabled"]) + except AttributeError: + return False @noise_cancel.setter def noise_cancel(self, arg): @@ -118,9 +124,10 @@ class ParrotZik(object): def lou_reed_mode(self): data = self.get("/api/audio/specific_mode/enabled/get") try: - return data.answer.audio.specific_mode["enabled"] + return self._result_to_bool( + data.answer.audio.specific_mode["enabled"]) except TypeError: - pass + return False @lou_reed_mode.setter def lou_reed_mode(self, arg): @@ -129,18 +136,30 @@ class ParrotZik(object): @property def concert_hall(self): data = self.get("/api/audio/sound_effect/enabled/get") - return data.answer.audio.sound_effect["enabled"] + try: + return self._result_to_bool( + data.answer.audio.sound_effect["enabled"]) + except AttributeError: + return False @concert_hall.setter def concert_hall(self, arg): self.set("/api/audio/sound_effect/enabled/set", arg) + def _result_to_bool(self, result): + if result == "true": + return True + elif result == "false": + return False + else: + raise AssertionError(result) + def get(self, message): message = ParrotProtocol.getRequest(message) return self.send_message(message) def set(self, message, arg): - message = ParrotProtocol.setRequest(message, arg) + message = ParrotProtocol.setRequest(message, str(arg).lower()) return self.send_message(message) def send_message(self, message): diff --git a/ParrotZikTray b/ParrotZikTray index ee492b2..2245807 100755 --- a/ParrotZikTray +++ b/ParrotZikTray @@ -117,10 +117,7 @@ class ParrotZikBaseInterface(object): self.name = self.parrot.friendly_name self.version = self.parrot.version - if self.parrot.auto_connect == "true": - self.auto_connection.set_active(True) - else: - self.auto_connection.set_active(False) + self.auto_connection.set_active(self.parrot.auto_connect) self.indicator.active_interface = self self.indicator.menu.reposition() @@ -138,10 +135,8 @@ class ParrotZikBaseInterface(object): def toggleAuto(self, widget): if self.connected: - if self.auto_connection.get_active(): - self.parrot.auto_connection = "true" - else: - self.parrot.auto_connection = "false" + self.parrot.auto_connection = self.auto_connection.get_active() + self.auto_connection.set_active(self.parrot.auto_connection) class ParrotZikVersion1Interface(ParrotZikBaseInterface): @@ -164,20 +159,9 @@ class ParrotZikVersion1Interface(ParrotZikBaseInterface): self.concert_hall_mode.show() super(ParrotZikVersion1Interface, self).activate(parrot) - if self.parrot.noise_cancel == "true": - self.noise_cancelation.set_active(True) - else: - self.noise_cancelation.set_active(False) - - if self.parrot.lou_reed_mode == "true": - self.lou_reed_mode.set_active(True) - else: - self.lou_reed_mode.set_active(False) - - if self.parrot.concert_hall == "true": - self.concert_hall_mode.set_active(True) - else: - self.concert_hall_mode.set_active(False) + self.noise_cancelation.set_active(self.parrot.noise_cancel) + self.lou_reed_mode.set_active(self.parrot.lou_reed_mode) + self.concert_hall_mode.set_active(self.parrot.concert_hall) def deactivate(self): self.noise_cancelation.hide() @@ -187,26 +171,21 @@ class ParrotZikVersion1Interface(ParrotZikBaseInterface): def toggleANC(self, widget): if self.connected: - if self.noise_cancelation.get_active(): - self.parrot.noise_cancel = "true" - else: - self.parrot.noise_cancel = "false" + self.parrot.noise_cancel = self.noise_cancelation.get_active() + self.noise_cancelation.set_active(self.parrot.noise_cancel) def toggleLouReedMode(self, widget): if self.connected: - if self.lou_reed_mode.get_active(): - self.parrot.lou_reed_mode = "true" - self.concert_hall_mode.set_sensitive(False) - else: - self.parrot.lou_reed_mode = "false" - self.concert_hall_mode.set_sensitive(True) + self.parrot.lou_reed_mode = self.lou_reed_mode.get_active() + self.lou_reed_mode.set_active(self.parrot.lou_reed_mode) + self.concert_hall_mode.set_active(self.parrot.concert_hall) + self.concert_hall_mode.set_sensitive( + not self.lou_reed_mode.get_active()) def toggleParrotConcertHall(self, widget): if self.connected: - if self.concert_hall_mode.get_active(): - self.parrot.concert_hall = "true" - else: - self.parrot.concert_hall = "false" + self.parrot.concert_hall = self.concert_hall_mode.get_active() + self.concert_hall_mode.set_active(self.parrot.concert_hall) def refresh(self): if self.connected: |