aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik
diff options
context:
space:
mode:
authorMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 13:56:44 +0200
committerMarek Siarkowicz <mareksiarkowicz@gmail.com>2015-06-15 13:56:44 +0200
commitafa654af0a2d2e6b34b47af52ed214977b7a3e12 (patch)
tree7e70e98d8ba407983a3a2803b6de713b68d769d5 /parrot_zik
parentf291feaa8a33645850818f811ba8d7f9eb9d4c31 (diff)
downloadpyParrotZikTCP-afa654af0a2d2e6b34b47af52ed214977b7a3e12.tar.xz
pyParrotZikTCP-afa654af0a2d2e6b34b47af52ed214977b7a3e12.zip
Refactor. Move.
Diffstat (limited to '')
-rw-r--r--parrot_zik/interface/base.py2
-rw-r--r--parrot_zik/interface/version1.py2
-rw-r--r--parrot_zik/interface/version2.py6
-rw-r--r--parrot_zik/model/__init__.py0
-rw-r--r--parrot_zik/model/base.py58
-rw-r--r--parrot_zik/model/version1.py48
-rw-r--r--parrot_zik/model/version2.py (renamed from parrot_zik/parrot_zik_model.py)182
7 files changed, 150 insertions, 148 deletions
diff --git a/parrot_zik/interface/base.py b/parrot_zik/interface/base.py
index 9ddf47a..1611874 100644
--- a/parrot_zik/interface/base.py
+++ b/parrot_zik/interface/base.py
@@ -1,6 +1,6 @@
from .. import resource_manager
from ..indicator import MenuItem
-from ..parrot_zik_model import BatteryStates
+from ..model.base import BatteryStates
RECONNECT_FREQUENCY = 5000
diff --git a/parrot_zik/interface/version1.py b/parrot_zik/interface/version1.py
index 5a00441..1af71ec 100644
--- a/parrot_zik/interface/version1.py
+++ b/parrot_zik/interface/version1.py
@@ -1,7 +1,7 @@
from .. import resource_manager
from ..indicator import MenuItem
from ..interface.base import ParrotZikBaseInterface
-from ..parrot_zik_model import ParrotZikVersion1
+from ..model.version1 import ParrotZikVersion1
class ParrotZikVersion1Interface(ParrotZikBaseInterface):
diff --git a/parrot_zik/interface/version2.py b/parrot_zik/interface/version2.py
index fc4af21..ff21004 100644
--- a/parrot_zik/interface/version2.py
+++ b/parrot_zik/interface/version2.py
@@ -3,9 +3,9 @@ import functools
from .. import resource_manager
from ..indicator import MenuItem, Menu
from .base import ParrotZikBaseInterface
-from ..parrot_zik_model import ParrotZikVersion2
-from ..parrot_zik_model import NoiseControlTypes
-from ..parrot_zik_model import Rooms
+from ..model.version2 import ParrotZikVersion2
+from ..model.version2 import NoiseControlTypes
+from ..model.version2 import Rooms
class ParrotZikVersion2Interface(ParrotZikBaseInterface):
diff --git a/parrot_zik/model/__init__.py b/parrot_zik/model/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/parrot_zik/model/__init__.py
diff --git a/parrot_zik/model/base.py b/parrot_zik/model/base.py
new file mode 100644
index 0000000..0cd4652
--- /dev/null
+++ b/parrot_zik/model/base.py
@@ -0,0 +1,58 @@
+class ParrotZikBase(object):
+ def __init__(self, resource_manager):
+ self.resource_manager = resource_manager
+
+ @property
+ def version(self):
+ return self.resource_manager.api_version
+
+ def refresh_battery(self):
+ self.resource_manager.fetch('/api/system/battery')
+
+ @property
+ def battery_state(self):
+ answer = self.resource_manager.get("/api/system/battery")
+ return answer.system.battery["state"]
+
+ def get_battery_level(self, field_name):
+ answer = self.resource_manager.get("/api/system/battery")
+ return int(answer.system.battery[field_name])
+
+ @property
+ def friendly_name(self):
+ answer = self.resource_manager.get("/api/bluetooth/friendlyname")
+ return answer.bluetooth["friendlyname"]
+
+ @property
+ def auto_connect(self):
+ answer = self.resource_manager.get("/api/system/auto_connection/enabled")
+ return self._result_to_bool(
+ answer.system.auto_connection["enabled"])
+
+ @auto_connect.setter
+ def auto_connect(self, arg):
+ self.resource_manager.set("/api/system/auto_connection/enabled", arg)
+
+ @property
+ def anc_phone_mode(self):
+ answer = self.resource_manager.get("/api/system/anc_phone_mode/enabled")
+ return self._result_to_bool(
+ answer.system.anc_phone_mode["enabled"])
+
+ def _result_to_bool(self, result):
+ if result == "true":
+ return True
+ elif result == "false":
+ return False
+ else:
+ raise AssertionError(result)
+
+class BatteryStates:
+ CHARGED = 'charged'
+ IN_USE = 'in_use'
+ CHARGING = 'charging'
+ representation = {
+ CHARGED: 'Charged',
+ IN_USE: 'In Use',
+ CHARGING: 'Charging',
+ }
diff --git a/parrot_zik/model/version1.py b/parrot_zik/model/version1.py
new file mode 100644
index 0000000..b39684f
--- /dev/null
+++ b/parrot_zik/model/version1.py
@@ -0,0 +1,48 @@
+from .base import ParrotZikBase
+from ..resource_manager import Version1ResourceManager
+
+
+class ParrotZikVersion1(ParrotZikBase):
+ def __init__(self, resource_manager):
+ super(ParrotZikVersion1, self).__init__(
+ resource_manager.get_resource_manager(
+ Version1ResourceManager))
+
+ @property
+ def version(self):
+ answer = self.resource_manager.get('/api/software/version')
+ return answer.software['version']
+
+ @property
+ def battery_level(self):
+ return int(self.get_battery_level('level'))
+
+ @property
+ def lou_reed_mode(self):
+ answer = self.resource_manager.get("/api/audio/specific_mode/enabled")
+ return self._result_to_bool(
+ answer.audio.specific_mode["enabled"])
+
+ @lou_reed_mode.setter
+ def lou_reed_mode(self, arg):
+ self.resource_manager.get("/api/audio/specific_mode/enabled", arg)
+
+ @property
+ def concert_hall(self):
+ answer = self.resource_manager.get("/api/audio/sound_effect/enabled")
+ return self._result_to_bool(
+ answer.audio.sound_effect["enabled"])
+
+ @concert_hall.setter
+ def concert_hall(self, arg):
+ self.resource_manager.get("/api/audio/sound_effect/enabled", arg)
+
+ @property
+ def cancel_noise(self):
+ answer = self.resource_manager.get("/api/audio/noise_cancellation/enabled")
+ return self._result_to_bool(
+ answer.audio.noise_cancellation["enabled"])
+
+ @cancel_noise.setter
+ def cancel_noise(self, arg):
+ self.resource_manager.set("/api/audio/noise_cancellation/enabled", arg) \ No newline at end of file
diff --git a/parrot_zik/parrot_zik_model.py b/parrot_zik/model/version2.py
index e6a8bc7..9ef6267 100644
--- a/parrot_zik/parrot_zik_model.py
+++ b/parrot_zik/model/version2.py
@@ -1,146 +1,5 @@
-from .resource_manager import Version1ResourceManager
-from .resource_manager import Version2ResourceManager
-
-
-class BatteryStates:
- CHARGED = 'charged'
- IN_USE = 'in_use'
- CHARGING = 'charging'
- representation = {
- CHARGED: 'Charged',
- IN_USE: 'In Use',
- CHARGING: 'Charging',
- }
-
-class Rooms:
- CONCERT_HALL = 'concert'
- JAZZ_CLUB = 'jazz'
- LIVING_ROOM = 'living'
- SILENT_ROOM = 'silent'
- representation = {
- CONCERT_HALL: 'Concert Hall',
- JAZZ_CLUB: 'Jazz Club',
- LIVING_ROOM: 'Living Room',
- SILENT_ROOM: 'Silent Room',
- }
-
-class NoiseControl(object):
- def __init__(self, type, value):
- self.type = type
- self.value = value
-
- @classmethod
- def from_noise_control(cls, noise_control):
- return cls(noise_control['type'], int(noise_control['value']))
-
- def __eq__(self, other):
- return self.type == other.type and self.value == other.value
-
- def __str__(self):
- return '{}++{}'.format(self.type, self.value)
-
-class NoiseControlTypes:
- NOISE_CONTROL_MAX = NoiseControl('anc', 2)
- NOISE_CONTROL_ON = NoiseControl('anc', 1)
- NOISE_CONTROL_OFF = NoiseControl('off', 1)
- STREET_MODE = NoiseControl('aoc', 1)
- STREET_MODE_MAX = NoiseControl('aoc', 2)
-
-
-class ParrotZikBase(object):
- def __init__(self, resource_manager):
- self.resource_manager = resource_manager
-
- @property
- def version(self):
- return self.resource_manager.api_version
-
- def refresh_battery(self):
- self.resource_manager.fetch('/api/system/battery')
-
- @property
- def battery_state(self):
- answer = self.resource_manager.get("/api/system/battery")
- return answer.system.battery["state"]
-
- def get_battery_level(self, field_name):
- answer = self.resource_manager.get("/api/system/battery")
- return int(answer.system.battery[field_name])
-
- @property
- def friendly_name(self):
- answer = self.resource_manager.get("/api/bluetooth/friendlyname")
- return answer.bluetooth["friendlyname"]
-
- @property
- def auto_connect(self):
- answer = self.resource_manager.get("/api/system/auto_connection/enabled")
- return self._result_to_bool(
- answer.system.auto_connection["enabled"])
-
- @auto_connect.setter
- def auto_connect(self, arg):
- self.resource_manager.set("/api/system/auto_connection/enabled", arg)
-
- @property
- def anc_phone_mode(self):
- answer = self.resource_manager.get("/api/system/anc_phone_mode/enabled")
- return self._result_to_bool(
- answer.system.anc_phone_mode["enabled"])
-
- def _result_to_bool(self, result):
- if result == "true":
- return True
- elif result == "false":
- return False
- else:
- raise AssertionError(result)
-
-
-class ParrotZikVersion1(ParrotZikBase):
- def __init__(self, resource_manager):
- super(ParrotZikVersion1, self).__init__(
- resource_manager.get_resource_manager(
- Version1ResourceManager))
-
- @property
- def version(self):
- answer = self.resource_manager.get('/api/software/version')
- return answer.software['version']
-
- @property
- def battery_level(self):
- return int(self.get_battery_level('level'))
-
- @property
- def lou_reed_mode(self):
- answer = self.resource_manager.get("/api/audio/specific_mode/enabled")
- return self._result_to_bool(
- answer.audio.specific_mode["enabled"])
-
- @lou_reed_mode.setter
- def lou_reed_mode(self, arg):
- self.resource_manager.get("/api/audio/specific_mode/enabled", arg)
-
- @property
- def concert_hall(self):
- answer = self.resource_manager.get("/api/audio/sound_effect/enabled")
- return self._result_to_bool(
- answer.audio.sound_effect["enabled"])
-
- @concert_hall.setter
- def concert_hall(self, arg):
- self.resource_manager.get("/api/audio/sound_effect/enabled", arg)
-
- @property
- def cancel_noise(self):
- answer = self.resource_manager.get("/api/audio/noise_cancellation/enabled")
- return self._result_to_bool(
- answer.audio.noise_cancellation["enabled"])
-
- @cancel_noise.setter
- def cancel_noise(self, arg):
- self.resource_manager.set("/api/audio/noise_cancellation/enabled", arg)
+from .base import ParrotZikBase
+from ..resource_manager import Version2ResourceManager
class ParrotZikVersion2(ParrotZikBase):
@@ -220,3 +79,40 @@ class ParrotZikVersion2(ParrotZikBase):
def noise_control_enabled(self):
answer = self.resource_manager.get('/api/audio/noise_control/enabled')
return self._result_to_bool(answer.audio.noise_control['enabled'])
+
+
+class NoiseControl(object):
+ def __init__(self, type, value):
+ self.type = type
+ self.value = value
+
+ @classmethod
+ def from_noise_control(cls, noise_control):
+ return cls(noise_control['type'], int(noise_control['value']))
+
+ def __eq__(self, other):
+ return self.type == other.type and self.value == other.value
+
+ def __str__(self):
+ return '{}++{}'.format(self.type, self.value)
+
+
+class NoiseControlTypes:
+ NOISE_CONTROL_MAX = NoiseControl('anc', 2)
+ NOISE_CONTROL_ON = NoiseControl('anc', 1)
+ NOISE_CONTROL_OFF = NoiseControl('off', 1)
+ STREET_MODE = NoiseControl('aoc', 1)
+ STREET_MODE_MAX = NoiseControl('aoc', 2)
+
+
+class Rooms:
+ CONCERT_HALL = 'concert'
+ JAZZ_CLUB = 'jazz'
+ LIVING_ROOM = 'living'
+ SILENT_ROOM = 'silent'
+ representation = {
+ CONCERT_HALL: 'Concert Hall',
+ JAZZ_CLUB: 'Jazz Club',
+ LIVING_ROOM: 'Living Room',
+ SILENT_ROOM: 'Silent Room',
+ } \ No newline at end of file