From b3e51569ae1fb2a3cd3749e330a5d65c22298035 Mon Sep 17 00:00:00 2001 From: ole1986 Date: Thu, 2 Apr 2020 22:02:35 +0200 Subject: [PATCH 1/2] Migrate two more units --- README.md | 4 ++++ centronic-stick.py | 41 ++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6dfd4d9..1b9a927 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,10 @@ Use the argument `--mod "::"` (CAREFULLY) to set th ### CHANGELOG +**v0.6** + +- added two more units ("1737e" and "1737f") counting a total of 5 units (35 possible channels) + **v0.5** - save incremental numbers (per unit) into sqlite3 db diff --git a/centronic-stick.py b/centronic-stick.py index 89ff562..5e5fabf 100755 --- a/centronic-stick.py +++ b/centronic-stick.py @@ -42,11 +42,11 @@ def showhelp(): print(" --send : submit a completely generated code for UP/UP2/DOWN/DOWN2/HALT/TRAIN/REMOVE commands / requires '--channel'") print(" While UP2 and DOWN2 are the intermediate position (E.g. sun protection)") print(" --device : set the device if it differs from the default, also host:port possible (ser2net)") - print("--channel <[unit:]channel>: define the unit (1-3) and channel (1-7) being used for '--send'. Example: 2:15 will close shutter for unit 2 on all channels") + print("--channel <[unit:]channel>: define the unit (1-5) and channel (1-7) being used for '--send'. Example: 2:15 will close shutter for unit 2 on all channels") print(" --checksum : add a checksum to the given 40 char code and output (without STX, ETX)") print(" --mod : used to manipulate the db entries - FOR VERY ADVANCED USERS") print('') - print('Version 0.5 - Authors: ole1986, toolking') + print('Version 0.6 - Authors: ole1986, toolking') class Database: @@ -67,28 +67,35 @@ def check(self): checkTable = c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='unit'") if checkTable.fetchone() is None: self.create() - self.migrate() + + self.migrate() def migrate(self): - # migrate the previous *.num file into its sqllite database - self.oldfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), NUMBER_FILE) - - if not os.path.isfile(self.oldfile): - return - try: - print('Migrate previous *.num file...') - with open(self.oldfile, "r") as file: - number = int(file.read()) - + # migrate the previous *.num file into its sqllite database + self.oldfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), NUMBER_FILE) + if os.path.isfile(self.oldfile): + print('Migrate previous *.num file...') + with open(self.oldfile, "r") as file: + number = int(file.read()) + c = self.conn.cursor() + c.execute("UPDATE unit SET increment = ?, configured = ? WHERE code = ?", (number, 1, '1737b',)) + self.conn.commit() + os.remove(self.oldfile) + + # add additional units c = self.conn.cursor() - c.execute("UPDATE unit SET increment = ?, configured = ? WHERE code = ?", (number, 1, '1737b',)) - self.conn.commit() - os.remove(self.oldfile) + count = c.execute("SELECT COUNT(*) FROM unit").fetchone()[0] + if count <= 3: + print('Migrate more units...') + c.execute("INSERT INTO unit VALUES (?, ?, ?, ?)", ('1737e', 0, 0, 0,)) + c.execute("INSERT INTO unit VALUES (?, ?, ?, ?)", ('1737f', 0, 0, 0,)) + self.conn.commit() + except: print('Migration failed') self.conn.rollback() - + def create(self): # create the database table From 9a01b6081b95d8aa503f4bed8d626b8643af7fa1 Mon Sep 17 00:00:00 2001 From: ole1986 Date: Thu, 2 Apr 2020 22:05:27 +0200 Subject: [PATCH 2/2] Updated README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b9a927..0183956 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,11 @@ It is necessary to own such USB device and to PAIR it first, before using comman --send : submit a completely generated code for UP/UP2/DOWN/DOWN2/HALT/TRAIN/REMOVE commands / requires '--channel' While UP2 and DOWN2 are the intermediate position (E.g. sun protection) --device : set the device if it differs from the default, also host:port possible (ser2net) ---channel <[unit:]channel>: define the unit (1-3) and channel (1-7) being used for '--send'. Example: 2:15 will close shutter for unit 2 on all channels +--channel <[unit:]channel>: define the unit (1-5) and channel (1-7) being used for '--send'. Example: 2:15 will close shutter for unit 2 on all channels --checksum : add a checksum to the given 40 char code and output (without STX, ETX) --mod : used to manipulate the db entries - FOR VERY ADVANCED USERS -Version 0.5 - Authors: ole1986, toolking +Version 0.6 - Authors: ole1986, toolking ``` ### INSTALLATION