Skip to content

Instantly share code, notes, and snippets.

@ppat
Created April 24, 2020 16:30
Show Gist options
  • Save ppat/9ae93bc63e10e777f866d2a488fa2857 to your computer and use it in GitHub Desktop.
Save ppat/9ae93bc63e10e777f866d2a488fa2857 to your computer and use it in GitHub Desktop.
Home Assistant Integrations configuration
integration:
unifi:
host: "127.0.0.1"
port: 8443
username: "{{ credentials.unifi_username }}"
password: "{{ credentials.unifi_password }}"
cast: {}
wemo: {}
---
- name: configure integration
include_tasks: configure_integration.yaml
tags: integration
with_dict: "{{ integration }}"
---
- name: "init config flow: {{ item.key }}"
uri:
method: POST
url: "{{ homeassistant_url }}/api/config/config_entries/flow"
body_format: json
body:
handler: "{{ item.key }}"
headers:
Authorization: "Bearer {{ access_token }}"
register: init_flow_response
failed_when: "init_flow_response.json.flow_id is undefined or (init_flow_response.json.type not in ['form', 'abort'])"
changed_when: false
- name: "configure: {{ item.key }}"
uri:
method: POST
url: "{{ homeassistant_url }}/api/config/config_entries/flow/{{ init_flow_response.json.flow_id }}"
body_format: json
body: "{{ item.value }}"
headers:
Authorization: "Bearer {{ access_token }}"
status_code: 200
register: config_flow_response
changed_when: "'type' in config_flow_response.json and config_flow_response.json.type == 'create_entry'"
when: "init_flow_response.json.type == 'form'"
- name: "assert config success: {{ item.key }}"
assert:
that:
- "'errors' not in config_flow_response.json or config_flow_response.json.errors is undefined"
fail_msg: "configuring {{ item.key }} failed with errors: {{ config_flow_response.json.get('errors', {}) }}"
success_msg: "{{ item.key }} {{ config_flow_response.changed | ternary('configured', 'already configured') }}"
when: "init_flow_response.json.type == 'form'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment