Add battery pack manager.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:47:44 +0000 (16:47 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:47:44 +0000 (16:47 +0200)
tabakrolletjie/battery.py [new file with mode: 0644]

diff --git a/tabakrolletjie/battery.py b/tabakrolletjie/battery.py
new file mode 100644 (file)
index 0000000..c543698
--- /dev/null
@@ -0,0 +1,36 @@
+""" Keep 'em charged and they'll never let you down. """
+
+
+class BatteryManager(object):
+    """ Manages a battery. """
+
+    def __init__(self, gamestate):
+        self._state = gamestate.station["battery"]
+
+    @property
+    def current(self):
+        return self._state["current"]
+
+    @current.setter
+    def current(self, value):
+        self._state["current"] = min(max(0, value), self.max)
+
+    @property
+    def max(self):
+        return self._state["max"]
+
+    @max.setter
+    def max(self, value):
+        self._state["max"] = max(0, value)
+
+    @property
+    def recharge(self):
+        return self._state["recharge"]
+
+    @recharge.setter
+    def recharge(self, value):
+        self._state["recharge"] = max(0, value)
+
+    def apply_recharge(self):
+        self.current += self.recharge
+        print self.current