SSH Switch - Error in Log

So, I’m currently developing a custom component switch that operates utilizing an ssh tunnel. I have it all working, but I get an error in the hass log that I cannot fully understand. I am hopefully someone has some guidance on how to resolve it or where to start looking. Here is the error and project link. Thanks in advance!!!

Traceback (most recent call last):
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
TypeError: ‘NoneType’ object is not callable

Here are links to more details on the issue and the complete component code:


The error makes it pretty clear that at that point, self.fn is None. :slight_smile:

Since you don’t have a full stack trace, it’s hard to guess what’s wrong. After looking over your code, I’d recommend breaking out all of the ssh-related stuff into a separate module, such that you can test it in isolation. Then you can test your code outside the context of Home Assistant, and likely find the problem more quickly. I can see you’re using another module for an SSH connection, and I suspect the problem is that you’re not using the module correctly.

Also, please don’t try to connect to the ssh host in your constructor – it’s not very helpful, and could cause timeouts, especially if the host is down or otherwise unavailable when you start Home Assistant. Ideally, you would only connect to run a command, and disconnect immediately. If you’re making frequent connections, you’ll want to take advantage of the ControlMaster feature which is designed to handle that situation. I’ve no idea if the module you’re using supports that or not, but it’ll involve more in the way of process lifetime handling.