mirror of
https://github.com/elisspace/core.git
synced 2026-10-09 02:21:08 +00:00
All mochad devices are sharing a single socket interface. When multiple threads are issuing requests to the mochad daemon at the same time the write read cycle might get crossed between the threads. This is normally not an issue for 1-way X10 devices because as long as the request issued successfully and data is read over the socket then we know as much as mochad will tell us (since there is no ACK from the request for most X10 devices). However, where it does matter is on the device __init__() because we're relying on the mochad daemon's internal state to take an educated guess at the device's state to intialize things with. When there are multiple devices being initialized at the same time the wires can get crossed between and the wrong device state may be read. To address this potential issue this commit adds locking using a semaphore around all pairs of send_cmd() and read_data() (which is what pymochad.device.Device.get_status() does internally) calls to the mochad controller to ensure we're only ever dealing with a single request at a time. Fixes mtreinish/pymochad#4