New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth and headers support for REST sensor #3592
Conversation
Perhaps we should supersede this PR with an |
Let's leave the |
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Setup the REST binary sensor.""" | ||
name = config.get(CONF_NAME) | ||
resource = config.get(CONF_RESOURCE) | ||
method = config.get(CONF_METHOD) | ||
payload = config.get(CONF_PAYLOAD) | ||
verify_ssl = config.get(CONF_VERIFY_SSL) | ||
username = config.get(CONF_USERNAME) | ||
password = config.get(CONF_PASSWORD) | ||
headers = json.loads(config.get(CONF_HEADERS, '{}')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify default in PLATFORM_SCHEMA
. Also, YAML parses JSON so I doubt the string is really valid JSON here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also never expect JSON in YAML. Just make it a dict:
binary_sensor:
platform: rest
headers:
hello: world
Thus validation it as {cv.string: cv.string}
will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Thanks.
🐬 |
* Add auth and header support * Update header part
Description:
Support for HTTP authentication and headers for the REST sensor.
This will require an update of the REST Binary sensor and the PI Hole sensor.
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#1050
Example entry for
configuration.yaml
(if applicable):With the configuration sample from above the header will look like this:
Checklist:
If user exposed functionality or configuration variables are added/changed:
If code communicates with devices, web services, or a:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.