grinstantin / todoist-card

Todoist card for Home Assistant Lovelace UI.
MIT License
60 stars 28 forks source link

[FEATURE REQUEST] #40

Open Shablykinm opened 1 year ago

Shablykinm commented 1 year ago

I have a need to maintain three different lists. Is there any way to simplify the following config?

sensor:
    - platform: rest
      name: tasks
      method: GET
      resource: 'https://api.todoist.com/sync/v9/projects/get_data'
      params:
        project_id: 2313385717
      headers:
        Authorization: !secret todoist_api_token
      value_template: '{{ value_json[''project''][''id''] }}'
      json_attributes:
        - project
        - items
      scan_interval: 30
    - platform: rest
      name: homeplans
      method: GET
      resource: 'https://api.todoist.com/sync/v9/projects/get_data'
      params:
        project_id: 2313385679
      headers:
        Authorization: !secret todoist_api_token
      value_template: '{{ value_json[''project''][''id''] }}'
      json_attributes:
        - project
        - items
      scan_interval: 30
    - platform: rest
      name: purchases
      method: GET
      resource: 'https://api.todoist.com/sync/v9/projects/get_data'
      params:
        project_id: 2313385630
      headers:
        Authorization: !secret todoist_api_token
      value_template: '{{ value_json[''project''][''id''] }}'
      json_attributes:
        - project
        - items
      scan_interval: 30

rest_command:
  todoist:
    method: post
    url: 'https://api.todoist.com/sync/v9/{{ url }}'
    payload: '{{ payload }}'
    headers:
      Authorization: !secret todoist_api_token
    content_type: 'application/x-www-form-urlencoded'
Shablykinm commented 1 year ago

I would not like to specify the same parameters for each list I would like to minimize the code to the same structure

sensor:
     - platform: rest
      method: GET
      resource: 'https://api.todoist.com/sync/v9/projects/get_data'
      headers:
        Authorization: !secret todoist_api_token
      value_template: '{{ value_json[''project''][''id''] }}'
      json_attributes:
        - project
        - items
      scan_interval: 30
      resources:
        - type: 2313385717
          name: tasks
        - type: 7234632746
          name: homeplans
        - type: 7623476234
          name: purchases
       -  type: ....