From 2d12b23595a7c893231d5238f406054d040aac01 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Sat, 13 Jun 2015 03:25:22 +0200 Subject: Fix flight mode. --- ParrotProtocol.py | 4 ++-- ParrotZik.py | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ParrotProtocol.py b/ParrotProtocol.py index a844820..a4e1677 100644 --- a/ParrotProtocol.py +++ b/ParrotProtocol.py @@ -13,8 +13,8 @@ def generateHeader(requestString): def getRequest(resource): - return generateRequest("GET " + resource + '/get') + return generateRequest("GET " + resource) def setRequest(resource, args): - return generateRequest("SET " + resource + '/set' + "?arg=" + args) + return generateRequest("SET " + resource + "?arg=" + args) diff --git a/ParrotZik.py b/ParrotZik.py index 80dc591..c6cfd92 100644 --- a/ParrotZik.py +++ b/ParrotZik.py @@ -67,11 +67,19 @@ class ParrotZikApi(object): return data.answer.software['sip6'] def get(self, resource): - message = ParrotProtocol.getRequest(resource) + message = ParrotProtocol.getRequest(resource + '/get') + return self.send_message(message) + + def toggle_on(self, resource): + message = ParrotProtocol.getRequest(resource + '/enable') + return self.send_message(message) + + def toggle_off(self, resource): + message = ParrotProtocol.getRequest(resource + '/disable') return self.send_message(message) def set(self, resource, arg): - message = ParrotProtocol.setRequest(resource, str(arg).lower()) + message = ParrotProtocol.setRequest(resource + '/set', str(arg).lower()) return self.send_message(message) def send_message(self, message): @@ -81,9 +89,9 @@ class ParrotZikApi(object): self.sock = "" return if sys.platform == "darwin": - data = self.sock.recv(30) + self.sock.recv(30) else: - data = self.sock.recv(7) + self.sock.recv(7) data = self.sock.recv(1024) data = BeautifulSoup(data) return data @@ -216,7 +224,10 @@ class ParrotZikVersion2(ParrotZikBase): @flight_mode.setter def flight_mode(self, arg): - self.api.set('/api/flight_mode', arg) + if arg: + self.api.toggle_on('/api/flight_mode') + else: + self.api.toggle_off('/api/flight_mode') @property def sound_effect(self): -- cgit v1.2.1