Closed Jylze closed 2 years ago
Oh and final code for me was just two if statements to check for None : if str(d.name) != "None":
Hi @Jylze! Thanks for saying so, and thanks for the debug information! I haven't used Win11 yet, and I also haven't used PyCharm myself, but I want to check that out, as it definitely looks more in-depth for debugging than VS Code. For instance, I don't get any asyncio errors, but that might just be due to my test environment (it makes sense after seeing that that I should check first to see if an asyncio loop is running first before "asking" it which one is, which is why that error is being thrown I'm guessing, but VS Code and Python itself just skip past that part when debugging). As far as the name.index thing, that's one of the ways that I found to test to see if a substring has the word "Neewer" in it, but this is the first time I've heard of Bleak not returning a "name" string - .index only fails if the result is not a string, but Bleak should always return a string from any result it finds (which it apparently isn't if it's coming back as NoneType here...) That might be a Windows 11 anomaly, but it's worth checking into.
You could feasibly also do a one line check (I'm fairly certain, I don't have any lights with me to test it with at the moment, but will later on) by just adding the
if str(d.name) != "None":
line before the try block, and then indenting the try block, so the whole check block would be:
for d in devices: # go through all of the devices Bleak just found
if str(d.name) != "None": # check to make sure Bleak returns a valid string
try:
d.name.index("NEEWER") # try to see if the current device has the name "NEEWER" in it
except ValueError: # if the name doesn't have "NEEWER" in it, then check to see if it's whitelisted
if d.address in whiteListedMACs: # if the MAC address is in the list of whitelisted addresses, add this device anyway
printDebugString("Matching whitelisted address found - " + returnMACname() + " " + d.address + ", adding to the list")
currentScan.append(d)
else:
currentScan.append(d) # and if it finds the phrase, add it to this session's available lights
OK, @Jylze - I've reworked this section a bit for the latest commit - NeewerLite-Python first checks to see if the current device being checked against is "whitelisted", and if not, it then checks to see if it has a proper string from Bleak, and if it does, then it checks to see if it has "NEEWER" in the title. More streamlined this way, and it should work where the last version you tried originally did not.
Amazing, works perfectly. Thanks you for the quick reply @taburineagle :)
I'm quite impressed with PyCharm with its inline debugging, mind you its been over 9 years since I have done any coding, but it was quick to pickup and use.
You're welcome! :) Yeah, it looks fairly comprehensive! I downloaded it, but haven't really had a chance to kick the tires on it yet - hopefully I will soon!
Hey
For starters this project is brilliant, only way I have been able to control my Neewer 660 Pro's from Win 11.
I had to teach myself Python today and also how to use PyCharm as I couldn't get the script to run, so please feel free to shoot me down if this issue is a me problem.
Originally I thought it was related to the depreciated asyncio.get_event_loop() warnings but after placing in a few debugs I found that the findDevices() discover() would come back with Unknown -> 'None' (AttributeError: 'NoneType' object has no attribute 'index') error for the d.name.index("NEEWER").
I'm not sure if its a Winn 11 issue or I haven't loaded something correctly, however I added a few debugs and found that some of the Bluetooth devices were coming back with a device.name 'None' as below which was causing the issue.
I added a very basic checks to see if the device name was 'None' and to skip if it was detected which worked for me. (I am by no way a programmer and I'm sure this could be done with a oneliner)
If this isn't a relevant issue please just close.
Now to work out how to add to the Stream Deck :/ Thank you again for the hard work you have put into creating this script....keep up the amazing work!
Jylze