jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
923 stars 165 forks source link

Rework logging #300

Open uzlonewolf opened 1 year ago

uzlonewolf commented 1 year ago

I recently discovered another issue with having tons of devices. Like I mentioned in https://github.com/jasonacox/tinytuya/discussions/208#discussioncomment-4082687, I'm dumping a bunch of device sockets into select.select() just like the scanner does. Do you know what happens if you turn debug on and then poll the status of 52 devices simultaneously? It's... not pretty. So, I reworked the logging. Log messages now include the "name" of the source, which for devices is i.e. "tinytuya.OutletDevice.eb1######s". Initially I removed the red coloring of the text from the message, but then decided it was probably there for a reason and put it back. I did keep the device ID in cyan though. Red removed: Screenshot from 2023-03-13 20-14-56 cropped

Red put back: Screenshot from 2023-03-13 23-55-49 cropped

When I added the per-device debug toggle I also made its color selection independent (default is to match the global). I didn't intend it to be this way, but it worked out really well as it allows things like: Screenshot from 2023-03-14 01-42-14 cropped

Anyway, I have this as a draft as it needs a *lot* more testing. I've only verified it works for basic functions.

jasonacox commented 1 year ago

I love this!!!