Skip to content

Commit

Permalink
Bug fix: Apply --sshTimeout arg value to timeout parameter of paramik…
Browse files Browse the repository at this point in the history
…o.client.SSHClient exec_command(); use local scope for Queue variable.
  • Loading branch information
joelp committed Jan 12, 2024
1 parent d051337 commit f6f2163
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Works fine generally, basically like the existing HA unifi_direct, and allows me

History
-
### v0.0.9
- Bug fix: Apply ```--sshTimeout``` arg value to ```timeout``` parameter of ```paramiko.client.SSHClient exec_command()```; use local scope for Queue variable.
### v0.0.8
- Bug fix: Recreate paho.mqtt.client.Client to avoid ```ERROR:labtracker:SSL/TLS has already been configured.``` on MQTT disconnect/reconnect.
### v0.0.7
Expand Down
16 changes: 8 additions & 8 deletions app/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

Retained_maxcount = 100
Retained_timeout = 1
Retained_queue = Queue(maxsize=Retained_maxcount)
Topic_base = 'device_tracker/unifi_tracker'
Home_payload = "home"
Away_payload = None
Expand Down Expand Up @@ -71,20 +70,20 @@ def mqtt_disconnect():
Mqtt_client.disconnect()


def on_retained_message(client, queue, message):
def on_retained_message(_, queue, message):
'''Process callback; enqueue retained topic.'''
Log.debug(message.topic)
if not queue.full():
queue.put_nowait(message.topic)


def get_retained_messages():
def get_retained_messages(retained_queue):
'''Multiprocess Process method to retrieve retained topic.
Fill queue with topics in callback.
'''
Log.debug('Started get retrained messages process')
subscribe.callback(callback=on_retained_message,
userdata=Retained_queue,
userdata=retained_queue,
topics=f"{Topic_base}/+",
qos=Mqtt_qos,
hostname=Mqtt_host,
Expand All @@ -96,9 +95,10 @@ def get_retained_messages():

def get_existing_clients():
'''Retrieve persisted MQTT topics for existing client MACs'''
retained_queue = Queue(maxsize=Retained_maxcount)
Log.info('Retrieving retained clients')
try:
p = Process(target=get_retained_messages)
p = Process(target=get_retained_messages, args=(retained_queue,))
p.start()
p.join(timeout=Retained_timeout)
p.terminate()
Expand All @@ -107,12 +107,12 @@ def get_existing_clients():
p.close()
except ValueError as e:
Log.debug(e)
if Retained_queue.empty():
if retained_queue.empty():
Log.info('No retained clients retrieved.')
return {}
existing_macs = {}
while not Retained_queue.empty():
topic = Retained_queue.get_nowait()
while not retained_queue.empty():
topic = retained_queue.get_nowait()
if not topic:
break
mac = topic.split('/')[-1]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = unifi_tracker
version = 0.0.8
version = 0.0.9
author = Joel P.
author_email = joelp@live.com
description = Track the comings and goings of WiFi clients on multiple Unifi APs and generate a diff between scans.
Expand Down
2 changes: 1 addition & 1 deletion src/unifi_tracker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''Track the comings and goings of WiFi clients on multiple Unifi APs and generate a diff between scans.'''

__version__ = '0.0.8'
__version__ = '0.0.9'

from .unifi_tracker import *
4 changes: 3 additions & 1 deletion src/unifi_tracker/unifi_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def exec_ssh_cmdline(self, user: str, host: str, cmdline: str):
username=user,
look_for_keys=True,
timeout=self._sshTimeout)
_, stdout, stderr = self.ssh_client.exec_command(cmdline)
_LOGGER.debug("SSH connected.")
_, stdout, stderr = self.ssh_client.exec_command(cmdline, timeout=self._sshTimeout)
_LOGGER.debug("SSH command executed.")
out = stdout.read()
err = stderr.read()
finally:
Expand Down

0 comments on commit f6f2163

Please sign in to comment.