Fix http call to home assistant#21
Conversation
|
Important is to add CORS settings to the http in configuration.yaml, see |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the HTTP call functionality to Home Assistant by correcting a typo and updating the formatting in the header build process.
- Corrects the use of keys for HTTP headers by switching from "extras" to "headers".
- Adjusts the escaping methodology for the HTTP action body and adds additional debug logging for improved traceability.
Comments suppressed due to low confidence (2)
custom_components/ntfy/notify.py:324
- The updated escaping for the body does not actually escape double or single quotes as intended. Consider using double backslashes (e.g., '\"') for proper escaping.
body = action.get('body','').replace('"', '"').replace("'", "'").replace('=', '\=')
custom_components/ntfy/notify.py:309
- [nitpick] The added debug logging is useful for diagnosis, but verify that none of the logged data includes sensitive information such as authorization tokens.
_LOGGER.debug("action: %s", action)
| for key, value in action.get('headers').items(): | ||
| tmp_header += f", headers.{key}={value}" |
There was a problem hiding this comment.
The loop now correctly iterates over action['headers'], but please ensure that the 'headers' key always returns a dictionary as defined in the schema.
| for key, value in action.get('headers').items(): | |
| tmp_header += f", headers.{key}={value}" | |
| headers = action.get('headers') | |
| if isinstance(headers, dict): | |
| for key, value in headers.items(): | |
| tmp_header += f", headers.{key}={value}" | |
| else: | |
| _LOGGER.warning("Invalid headers format: expected a dictionary, got %s", type(headers).__name__) |
|
@hbrennhaeuser I would like to add that I can only confirm this to be working when using the browser on laptop. For the app, it is not working on my ios stuff and no way to debug that (am not a ios specialist). I have no android devices so that may be something you (or anyone else) can test. My main challenges were understanding the required message, then getting the right format and resolving the cors blockers. |
|
@vingerha I can confirm this is working on Android. |
|
It works from the app on iPhone and iPad |
I have a solution to allow to use the http 'action' from ntfy, it required a typo-fix and a minor change to the formatting.
The below works with this changed code: