From 56313f20fa8ec68e0fb43b88d7d87ca5e075d035 Mon Sep 17 00:00:00 2001 From: Quinn Damerell Date: Thu, 22 Aug 2024 10:50:37 -0700 Subject: [PATCH] Minor bug fixes --- homeway/CHANGELOG.md | 2 +- homeway/config.yaml | 2 +- homeway/homeway/httprequest.py | 31 ++++++++++++++++++++++--------- homeway/homeway/mdns.py | 6 ++++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/homeway/CHANGELOG.md b/homeway/CHANGELOG.md index d5d2853..bb82c8d 100644 --- a/homeway/CHANGELOG.md +++ b/homeway/CHANGELOG.md @@ -1,7 +1,7 @@ -## 1.4.0-2 +## 1.4.0-3 - 🐋 Adding a standalone docker image! Using the built in Home Assistant addon is the best option, but for those who can't, they can now use docker! diff --git a/homeway/config.yaml b/homeway/config.yaml index bb63f58..b1a5802 100644 --- a/homeway/config.yaml +++ b/homeway/config.yaml @@ -38,4 +38,4 @@ image: ghcr.io/homewayio/homeway/{arch} # Note when this version number changes, we must make a release to start a docker container build immediately, since HA will start looking for the new version. # Basically: Make the final commit -> test and check lint actions (if a docker change, push to docker-test to ensure it builds) -> bump the version number -> create GitHub release. # UPDATE THE CHANGE LOG! -version: 1.4.2 +version: 1.4.3 diff --git a/homeway/homeway/httprequest.py b/homeway/homeway/httprequest.py index f390680..ad30884 100644 --- a/homeway/homeway/httprequest.py +++ b/homeway/homeway/httprequest.py @@ -496,20 +496,21 @@ def MakeHttpCallAttempt(logger, attemptName, method, url, headers, data, mainRes logger.info(attemptName + " http NO HEADERS URL threw an exception: "+str(e)) # Check if we got a valid response. - if response is not None and response.status_code != 404: - # We got a valid response, we are done. - # Return true and the result object, so it can be returned. - return HttpRequest.AttemptResult(True, HttpRequest.Result(response.status_code, response.headers, url, isFallback, requestLibResponseObj=response)) + if response is not None: + if response.status_code != 404: + # We got a valid response, we are done. + # Return true and the result object, so it can be returned. + return HttpRequest.AttemptResult(True, HttpRequest._buildHttRequestResultFromResponse(response, url, isFallback)) + else: + # We got a 404, which is a valid response, but we need to keep going to the next fallback. + logger.info(attemptName + " failed with a 404. Trying the next fallback.") # Check if we have another fallback URL to try. if nextFallbackUrl is not None: # We have more fallbacks to try. # Return false so we keep going, but also return this response if we had one. This lets # use capture the main result object, so we can use it eventually if all fallbacks fail. - result = None - if response is not None: - result = HttpRequest.Result(response.status_code, response.headers, url, isFallback, requestLibResponseObj=response) - return HttpRequest.AttemptResult(False, result) + return HttpRequest.AttemptResult(False, HttpRequest._buildHttRequestResultFromResponse(response, url, isFallback)) # We don't have another fallback, so we need to end this. if mainResult is not None: @@ -517,6 +518,18 @@ def MakeHttpCallAttempt(logger, attemptName, method, url, headers, data, mainRes logger.info(attemptName + " failed and we have no more fallbacks. Returning the main URL response.") return HttpRequest.AttemptResult(True, mainResult) else: + # If we have a response, return it. + if response is not None: + logger.error(attemptName + " failed and we have no more fallbacks. We DON'T have a main response.") + return HttpRequest.AttemptResult(True, HttpRequest._buildHttRequestResultFromResponse(response, url, isFallback)) + # Otherwise return the failure. - logger.error(attemptName + " failed and we have no more fallbacks. We DON'T have a main response.") + logger.error(attemptName + " failed and we have no more fallbacks. We have no main response, but will return the current response.") return HttpRequest.AttemptResult(True, None) + + + @staticmethod + def _buildHttRequestResultFromResponse(response:requests.Response, url:str, isFallback:bool) -> Result: + if response is None: + return None + return HttpRequest.Result(response.status_code, response.headers, url, isFallback, requestLibResponseObj=response) diff --git a/homeway/homeway/mdns.py b/homeway/homeway/mdns.py index 1ed43e9..df60a60 100644 --- a/homeway/homeway/mdns.py +++ b/homeway/homeway/mdns.py @@ -84,8 +84,10 @@ def TryToResolveIfLocalHostnameFound(self, url): hostname = url[protocolEnd:hostnameEnd] self.LogDebug("Found hostname "+hostname+" in url "+url) - # Check if there is a .local hostname. Anything else we will ignore. - if ".local" not in hostname.lower(): + # Check if the hostname ends with .local, which is a special domain that we can resolve. + # We can't do a string contains, because there can be DNS names like "something.local.hostname.com" + hostnameLower = hostname.lower() + if hostnameLower.endswith(".local") or hostnameLower.endswith(".internal"): self.LogDebug("No local domain found in "+url) return None