Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
QuinnDamerell committed Aug 22, 2024
1 parent 5d754b4 commit 56313f2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion homeway/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- https://developers.home-assistant.io/docs/add-ons/presentation#keeping-a-changelog -->
<!-- This is used in the homeway UI to show updates, so keep it up to date. -->

## 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!

Expand Down
2 changes: 1 addition & 1 deletion homeway/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 22 additions & 9 deletions homeway/homeway/httprequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,27 +496,40 @@ 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:
# If we got something back from the main try, always return it (we should only get here on a 404)
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)
6 changes: 4 additions & 2 deletions homeway/homeway/mdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 56313f2

Please sign in to comment.