Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
152 stars 55 forks source link

XiaomiGatewayDiscovery.listen and XiaomiGatewayDiscovery.stop_listen bad architecture #105

Open PaulAnnekov opened 5 years ago

PaulAnnekov commented 5 years ago

XiaomiGatewayDiscovery.listen() and XiaomiGatewayDiscovery.stop_listen() look like shouldn't be called multiple times, because listen() sets self._mcastsocket (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L143) property and calling it for the 2nd time will overwrite this property. But from the other side there is a self._threads.append(thread) (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L146) call inside listen() which appends newly created thread to a thread pool. What's going on in these methods?

Also, stop_listen() will never end, because thread.join() (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L165) waits until a thread will stop execution, but data, (ip_add, _) = self._mcastsocket.recvfrom(self.SOCKET_BUFSIZE) (https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/xiaomi_gateway/__init__.py#L171) inside thread is blocking. Thread won't stop until something will arrive to this socket and we will go out of the loop.

andriej commented 5 years ago

Anything was fixed with that?