Add type checking for filesystem_smb (#1470)
authorJc2k <john.carr@unrouted.co.uk>
Mon, 8 Jul 2024 15:44:54 +0000 (16:44 +0100)
committerGitHub <noreply@github.com>
Mon, 8 Jul 2024 15:44:54 +0000 (17:44 +0200)
music_assistant/server/providers/filesystem_smb/__init__.py
mypy.ini

index 4ff43ee6cfc3b1d56e91a1df15e03ece38b24ff4..1e2d5fda28ce1ec690b3d0f74ccbc1cbbacc3789 100644 (file)
@@ -40,12 +40,12 @@ async def setup(
 ) -> ProviderInstanceType:
     """Initialize provider(instance) with given configuration."""
     # check if valid dns name is given for the host
-    server: str = config.get_value(CONF_HOST)
+    server = str(config.get_value(CONF_HOST))
     if not await get_ip_from_host(server):
         msg = f"Unable to resolve {server}, make sure the address is resolveable."
         raise LoginFailed(msg)
     # check if share is valid
-    share: str = config.get_value(CONF_SHARE)
+    share = str(config.get_value(CONF_SHARE))
     if not share or "/" in share or "\\" in share:
         msg = "Invalid share name"
         raise LoginFailed(msg)
@@ -171,13 +171,13 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
 
     async def mount(self) -> None:
         """Mount the SMB location to a temporary folder."""
-        server: str = self.config.get_value(CONF_HOST)
-        username: str = self.config.get_value(CONF_USERNAME)
-        password: str = self.config.get_value(CONF_PASSWORD)
-        share: str = self.config.get_value(CONF_SHARE)
+        server = str(self.config.get_value(CONF_HOST))
+        username = str(self.config.get_value(CONF_USERNAME))
+        password = self.config.get_value(CONF_PASSWORD)
+        share = str(self.config.get_value(CONF_SHARE))
 
         # handle optional subfolder
-        subfolder: str = self.config.get_value(CONF_SUBFOLDER)
+        subfolder = str(self.config.get_value(CONF_SUBFOLDER))
         if subfolder:
             subfolder = subfolder.replace("\\", "/")
             if not subfolder.startswith("/"):
@@ -198,7 +198,7 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
 
         elif platform.system() == "Linux":
             options = ["rw"]
-            if mount_options := self.config.get_value(CONF_MOUNT_OPTIONS):
+            if mount_options := str(self.config.get_value(CONF_MOUNT_OPTIONS)):
                 options += mount_options.split(",")
 
             options_str = ",".join(options)
@@ -219,14 +219,14 @@ class SMBFileSystemProvider(LocalFileSystemProvider):
         self.logger.info("Mounting //%s/%s%s to %s", server, share, subfolder, self.base_path)
         self.logger.debug(
             "Using mount command: %s",
-            [m.replace(password, "########") if password else m for m in mount_cmd],
+            [m.replace(str(password), "########") if password else m for m in mount_cmd],
         )
         env_vars = {
             **os.environ,
             "USER": username,
         }
         if password:
-            env_vars["PASSWD"] = password
+            env_vars["PASSWD"] = str(password)
 
         returncode, output = await check_output(*mount_cmd, env=env_vars)
         if returncode != 0:
index 128a6ce9eebb1be7cadbf081e350051a677bd123..2bb91c5f34e537ac49378dfaf7737ac804b7cbf3 100644 (file)
--- a/mypy.ini
+++ b/mypy.ini
@@ -21,4 +21,4 @@ disallow_untyped_decorators = true
 disallow_untyped_defs = true
 warn_return_any = true
 warn_unreachable = true
-packages=tests,music_assistant.client,music_assistant.common,music_assistant.server.providers.builtin,music_assistant.server.providers.filesystem_local,music_assistant.server.providers.jellyfin,music_assistant.server.providers.radiobrowser
+packages=tests,music_assistant.client,music_assistant.common,music_assistant.server.providers.builtin,music_assistant.server.providers.filesystem_local,music_assistant.server.providers.filesystem_smb,music_assistant.server.providers.jellyfin,music_assistant.server.providers.radiobrowser