From 3fea95affb3cd37771b7972a56ae58d4c104a4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Wed, 27 Dec 2017 18:23:09 +0100 Subject: [PATCH] cleanup in Unit class --- gex/Unit.py | 9 ++++++--- gex/units/Pin.py | 4 ++-- main.py | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gex/Unit.py b/gex/Unit.py index 19a0087..5208254 100644 --- a/gex/Unit.py +++ b/gex/Unit.py @@ -1,11 +1,14 @@ from gex import Client class Unit: - def __init__(self, client :Client, name :str, type :str): + def __init__(self, client :Client, name :str): self.client = client self.unit_name = name - self.unit_type = type - self.callsign = client.get_callsign(name, type) + self.unit_type = self._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): """ Send a command to the unit """ diff --git a/gex/units/Pin.py b/gex/units/Pin.py index 7f9bca2..6c372a6 100644 --- a/gex/units/Pin.py +++ b/gex/units/Pin.py @@ -1,8 +1,8 @@ import gex class Pin(gex.Unit): - def __init__(self, client, name): - super().__init__(client, name, 'PIN') + def _type(self): + return 'PIN' def off(self): self.send(0x00) diff --git a/main.py b/main.py index f31052b..da235c4 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,9 @@ import gex client = gex.Client() -s = client.ini_read() -client.ini_write(s) +if False: + s = client.ini_read() + client.ini_write(s) if False: buf = client.bulk_read(None, gex.MSG_INI_READ) @@ -13,7 +14,7 @@ if False: client.bulk_write(None, gex.MSG_INI_WRITE, buf) -if False: +if True: led = gex.Pin(client, 'LED') for i in range(0,10):