Skip to content

Commit f71d75f

Browse files
committed
1-18-22 - Refined power/channel info
- Refined channel/power check (from workerThread) by implementing a list (currently only NEEWER-RGB176) that don't feed that data back - so we don't need to check them - Refined setTheTable as well, implementing a check to not update the table if the data being submitted is the same as the data already in the table - Added another second of delay before trying to re-link a light for the 2nd time
1 parent 3d97a24 commit f71d75f

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

NeewerLite-Python.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,20 @@ def setTheTable(self, infoArray, rowToChange = -1):
819819
else:
820820
currentRow = rowToChange # change data for the specified row
821821

822+
# THIS SECTION BELOW LIMITS UPDATING THE TABLE **ONLY** IF THE DATA SUPPLIED IS DIFFERENT THAN IT WAS ORIGINALLY
822823
if infoArray[0] != "": # the name of the light
823-
self.lightTable.setItem(currentRow, 0, QTableWidgetItem(infoArray[0]))
824+
if rowToChange == -1 or (rowToChange != -1 and infoArray[0] != self.returnTableInfo(rowToChange, 0)):
825+
self.lightTable.setItem(currentRow, 0, QTableWidgetItem(infoArray[0]))
824826
if infoArray[1] != "": # the MAC address of the light
825-
self.lightTable.setItem(currentRow, 1, QTableWidgetItem(infoArray[1]))
827+
if rowToChange == -1 or (rowToChange != -1 and infoArray[1] != self.returnTableInfo(rowToChange, 1)):
828+
self.lightTable.setItem(currentRow, 1, QTableWidgetItem(infoArray[1]))
826829
if infoArray[2] != "": # the Linked status of the light
827-
self.lightTable.setItem(currentRow, 2, QTableWidgetItem(infoArray[2]))
828-
self.lightTable.item(currentRow, 2).setTextAlignment(Qt.AlignCenter) # align the light status info to be center-justified
830+
if rowToChange == -1 or (rowToChange != -1 and infoArray[2] != self.returnTableInfo(rowToChange, 2)):
831+
self.lightTable.setItem(currentRow, 2, QTableWidgetItem(infoArray[2]))
832+
self.lightTable.item(currentRow, 2).setTextAlignment(Qt.AlignCenter) # align the light status info to be center-justified
829833
if infoArray[3] != "": # the current status message of the light
830-
self.lightTable.setItem(currentRow, 3, QTableWidgetItem(infoArray[3]))
834+
if rowToChange == -1 or (rowToChange != -1 and infoArray[2] != self.returnTableInfo(rowToChange, 3)):
835+
self.lightTable.setItem(currentRow, 3, QTableWidgetItem(infoArray[3]))
831836

832837
self.lightTable.resizeRowsToContents()
833838

@@ -1299,10 +1304,9 @@ async def connectToLight(selectedLight, updateGUI=True):
12991304

13001305
while isConnected == False and currentAttempt <= maxNumOfAttempts:
13011306
if threadAction != "quit":
1302-
printDebugString("Attempting to link to light " + str(selectedLight + 1) + " [" + availableLights[selectedLight][0].name + "] " + returnMACname() + " " + availableLights[selectedLight][0].address + " (Attempt " + str(currentAttempt) + " of " + str(maxNumOfAttempts) + ")")
1303-
13041307
try:
13051308
if not availableLights[selectedLight][1].is_connected: # if the current device isn't linked to Bluetooth
1309+
printDebugString("Attempting to link to light " + str(selectedLight + 1) + " [" + availableLights[selectedLight][0].name + "] " + returnMACname() + " " + availableLights[selectedLight][0].address + " (Attempt " + str(currentAttempt) + " of " + str(maxNumOfAttempts) + ")")
13061310
isConnected = await availableLights[selectedLight][1].connect() # try connecting it (and return the connection status)
13071311
else:
13081312
isConnected = True # the light is already connected, so mark it as being connected
@@ -1315,18 +1319,18 @@ async def connectToLight(selectedLight, updateGUI=True):
13151319
returnValue = False # if we're in CLI mode, and there is an error connecting to the light, return False
13161320

13171321
currentAttempt = currentAttempt + 1
1318-
await asyncio.sleep(3) # wait a few seconds before trying again
1322+
await asyncio.sleep(4) # wait a few seconds before trying to link to the light again
13191323
else:
13201324
return "quit"
13211325

13221326
if threadAction == "quit":
13231327
return "quit"
13241328
else:
13251329
if isConnected == True:
1326-
printDebugString("Successfully linked to light " + str(selectedLight + 1) + " [" + availableLights[selectedLight][0].name + "] " + returnMACname() + " " + availableLights[selectedLight][0].address)
1330+
printDebugString("Successful link on light " + str(selectedLight + 1) + " [" + availableLights[selectedLight][0].name + "] " + returnMACname() + " " + availableLights[selectedLight][0].address)
13271331

13281332
if updateGUI == True:
1329-
mainWindow.setTheTable(["", "", "LINKED\n --- / ᴄʜ. ---", "Waiting to send..."], selectedLight) # if it's successful, show that in the table
1333+
mainWindow.setTheTable(["", "", "LINKED", "Waiting to send..."], selectedLight) # if it's successful, show that in the table
13301334
else:
13311335
returnValue = True # if we're in CLI mode, and there is no error connecting to the light, return True
13321336
else:
@@ -1353,8 +1357,13 @@ async def readNotifyCharacteristic(selectedLight, diagCommand, typeOfData):
13531357
except Exception as e:
13541358
return "" # if there is an error checking the characteristic, just quit out of this routine
13551359

1356-
if receivedData != "" and len(receivedData) > 1 and receivedData[1] == typeOfData: # if we've received data, and the data returned is the right *kind* of data, then return it
1357-
break # we found data, so we can stop checking
1360+
if receivedData != "": # if the recieved data is populated
1361+
if len(receivedData) > 1: # if we have enough elements to get a status from
1362+
if receivedData[1] == typeOfData: # if the data returned is the correct *kind* of data
1363+
break # stop scanning for data
1364+
else: # if we have a list, but it doesn't have a payload in it (the light didn't supply enough data)
1365+
receivedData = "---" # then just re-set recievedData to the default string
1366+
break # stop scanning for data
13581367
else:
13591368
await asyncio.sleep(0.25) # wait a little bit of time before checking again
13601369
try:
@@ -1545,6 +1554,9 @@ async def connectToOneLight(MACAddress):
15451554
def workerThread(_loop):
15461555
global threadAction
15471556

1557+
# A LIST OF LIGHTS THAT DON'T SEND POWER/CHANNEL STATUS
1558+
lightsToNotCheckPower = ["NEEWER-RGB176"]
1559+
15481560
if findLightsOnStartup == True: # if we're set to find lights at startup, then automatically set the thread to discovery mode
15491561
threadAction = "discover"
15501562

@@ -1565,8 +1577,11 @@ def workerThread(_loop):
15651577
mainWindow.setTheTable(["", "", "NOT\nLINKED", "Light disconnected!"], a) # show the new status in the table
15661578
availableLights[a][1] = "" # clear the Bleak object
15671579
else:
1568-
_loop.run_until_complete(getLightChannelandPower(a))
1569-
mainWindow.setTheTable(["", "", "LINKED\n" + availableLights[a][7][0] + " / ᴄʜ. " + str(availableLights[a][7][1]), ""], a)
1580+
if not availableLights[a][0].name in lightsToNotCheckPower: # if the name of the current light is not in the list to skip checking
1581+
_loop.run_until_complete(getLightChannelandPower(a)) # then check the power and light status of that light
1582+
mainWindow.setTheTable(["", "", "LINKED\n" + availableLights[a][7][0] + " / ᴄʜ. " + str(availableLights[a][7][1]), ""], a)
1583+
else: # if the light we're scanning doesn't supply power or channel status, then just show "LINKED"
1584+
mainWindow.setTheTable(["", "", "LINKED", ""], a)
15701585

15711586
if threadAction == "quit":
15721587
printDebugString("Stopping the background thread")

0 commit comments

Comments
 (0)