Problem getting uBus integration working

I’m trying to get OpenWRT uBus integration working but it does not seem to start.

My configuration looks something like this:

device_tracker:
  - platform: ubus
    host: https://10.10.0.1
    dhcp_software: none
    username: viewer
    password: !secret uap_ubus_viewer

logger:
  default: warn
  logs:
    homeassistant.components.device_tracker: debug

When I reload HA I get the following error and nothing else.

home-assistant.log.1:2021-12-12 01:57:29 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.ubus
home-assistant.log.1:2021-12-12 01:57:34 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy ubus
home-assistant.log.1:  File "/usr/src/homeassistant/homeassistant/components/device_tracker/legacy.py", line 245, in async_setup_legacy
home-assistant.log.1:  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 43, in get_scanner
home-assistant.log.1:  File "/usr/src/homeassistant/homeassistant/components/ubus/device_tracker.py", line 87, in __init__

Digging through sources some, I realize that the url scheme is hardcoded to http. There’s no way to specify https, and probably not way to allow for self signed certs.

Having had a look at the supporting ubus-rpc library, we can see that the library supports https as well as self signed certificates, given that this is a default on openwrt these days it seems surprising that this isn’t supported in the integration. I have written then following patch that should allow these parameters to be configured properly. It is currently untested, I’ll update when I get a chance to try it out.

diff --git a/homeassistant/components/ubus/device_tracker.py b/homeassistant/components/ubus/device_tracker.py
index 4ccba81d86..bd904aa65f 100644
--- a/homeassistant/components/ubus/device_tracker.py
+++ b/homeassistant/components/ubus/device_tracker.py
@@ -17,8 +17,12 @@ import homeassistant.helpers.config_validation as cv
 _LOGGER = logging.getLogger(__name__)
 
 CONF_DHCP_SOFTWARE = "dhcp_software"
+CONF_VERIFY = "verify"
+CONF_SCHEME = "scheme"
 DEFAULT_DHCP_SOFTWARE = "dnsmasq"
 DHCP_SOFTWARES = ["dnsmasq", "odhcpd", "none"]
+DEFAULT_URI_SCHEME = "http"
+URI_SCHEMES = ["http", "https"]
 
 PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
     {
@@ -28,6 +32,10 @@ PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
         vol.Optional(CONF_DHCP_SOFTWARE, default=DEFAULT_DHCP_SOFTWARE): vol.In(
             DHCP_SOFTWARES
         ),
+        vol.Optional(CONF_SCHEME, default=DEFAULT_URI_SCHEME): vol.In(
+            URI_SCHEMES
+        ),
+        vol.Optional(CONF_VERIFY, default=true): cv.boolean,
     }
 )
 
@@ -74,14 +82,16 @@ class UbusDeviceScanner(DeviceScanner):
     def __init__(self, config):
         """Initialize the scanner."""
         host = config[CONF_HOST]
+        scheme = config[CONF_SCHEME]
         self.username = config[CONF_USERNAME]
         self.password = config[CONF_PASSWORD]
+        self.verify = config[CONF_VERIFY]
 
         self.parse_api_pattern = re.compile(r"(?P<param>\w*) = (?P<value>.*);")
         self.last_results = {}
-        self.url = f"http://{host}/ubus"
+        self.url = f"{scheme}://{host}/ubus"
 
-        self.ubus = Ubus(self.url, self.username, self.password)
+        self.ubus = Ubus(self.url, self.username, self.password, self.verify)
         self.hostapd = []
         self.mac2name = None
         self.success_init = self.ubus.connect() is not None

Did the provided patch work out? I see that this is still a problem.