cleanup in Unit class

doublebuf
Ondřej Hruška 7 years ago
parent c6c847136c
commit 3fea95affb
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 9
      gex/Unit.py
  2. 4
      gex/units/Pin.py
  3. 7
      main.py

@ -1,11 +1,14 @@
from gex import Client from gex import Client
class Unit: class Unit:
def __init__(self, client :Client, name :str, type :str): def __init__(self, client :Client, name :str):
self.client = client self.client = client
self.unit_name = name self.unit_name = name
self.unit_type = type self.unit_type = self._type()
self.callsign = client.get_callsign(name, type) self.callsign = client.get_callsign(name, self.unit_type)
def _type(self):
raise NotImplementedError("Missing _type() in Unit class \"%s\"" % self.__class__.__name__)
def send(self, cmd, pld=None, id=None): def send(self, cmd, pld=None, id=None):
""" Send a command to the unit """ """ Send a command to the unit """

@ -1,8 +1,8 @@
import gex import gex
class Pin(gex.Unit): class Pin(gex.Unit):
def __init__(self, client, name): def _type(self):
super().__init__(client, name, 'PIN') return 'PIN'
def off(self): def off(self):
self.send(0x00) self.send(0x00)

@ -4,8 +4,9 @@ import gex
client = gex.Client() client = gex.Client()
s = client.ini_read() if False:
client.ini_write(s) s = client.ini_read()
client.ini_write(s)
if False: if False:
buf = client.bulk_read(None, gex.MSG_INI_READ) buf = client.bulk_read(None, gex.MSG_INI_READ)
@ -13,7 +14,7 @@ if False:
client.bulk_write(None, gex.MSG_INI_WRITE, buf) client.bulk_write(None, gex.MSG_INI_WRITE, buf)
if False: if True:
led = gex.Pin(client, 'LED') led = gex.Pin(client, 'LED')
for i in range(0,10): for i in range(0,10):

Loading…
Cancel
Save