Repository: AppDaemon/appdaemon

Issue:
register_endpoint fails since version 4.0.1
Hello,

since version 4.1.0 register_endpoint() does not work when more than one app registers endpoints and one of these apps is restarted. It always says that the endpoint is already registered to another app (which is not true). The endpoints are correctly registered (and deregistered) and there are no duplicate endpoint names.

I had a look at the file http.py:

```
async def register_endpoint(self, cb: Callable, endpoint: str, name: str, **kwargs: Optional[dict]) -> str:

        handle = uuid.uuid4().hex

        # first we check to ensure that endpoint not been used before
        for name in self.app_endpoints:
            for _, handle_data in self.app_endpoints[name].items():
                if handle_data["endpoint"] == endpoint:
                    # it exists already so don't let it pass
                    raise AttributeError(f"The given endpoint '{endpoint}' already exists and used by {name}")

        if name not in self.app_endpoints:
            self.app_endpoints[name] = {}

        self.app_endpoints[name][handle] = {"callback": cb, "endpoint": endpoint, "kwargs": kwargs}

        return handle
```
`name` is defined twice: as function parameter and as variable of the for loop. Could this be a bug?


Discussion:
@danhei,

That is a good point. 

Can you kindly make a PR to fix this?

Kind regards 

Resolving patch:
diff --git a/appdaemon/http.py b/appdaemon/http.py
--- a/appdaemon/http.py
+++ b/appdaemon/http.py
@@ -892,11 +892,11 @@ async def register_endpoint(self, cb: Callable, endpoint: str, name: str, **kwar
         handle = uuid.uuid4().hex
 
         # first we check to ensure that endpoint not been used before
-        for name in self.app_endpoints:
-            for _, handle_data in self.app_endpoints[name].items():
+        for app_name in self.app_endpoints:
+            for _, handle_data in self.app_endpoints[app_name].items():
                 if handle_data["endpoint"] == endpoint:
                     # it exists already so don't let it pass
-                    raise AttributeError(f"The given endpoint '{endpoint}' already exists and used by {name}")
+                    raise AttributeError(f"The given endpoint '{endpoint}' already exists and used by {app_name}")
 
         if name not in self.app_endpoints:
             self.app_endpoints[name] = {}
@@ -954,11 +954,11 @@ async def register_route(self, cb: Callable, route: str, name: str, **kwargs: Op
         handle = uuid.uuid4().hex
 
         # first we check to ensure that route not been used before
-        for name in self.app_routes:
-            for _, handle_data in self.app_routes[name].items():
+        for app_name in self.app_routes:
+            for _, handle_data in self.app_routes[app_name].items():
                 if handle_data["route"] == route:
                     # it exists already so don't let it pass
-                    raise AttributeError(f"The given route '{route}' already exists and used by {name}")
+                    raise AttributeError(f"The given route '{route}' already exists and used by {app_name}")
 
         if name not in self.app_routes:
             self.app_routes[name] = {}


Test patch: