From 7218029b3405581284959b30a357c27a852fe194 Mon Sep 17 00:00:00 2001 From: Pavel Pletenev Date: Sat, 8 Sep 2018 14:34:56 +0200 Subject: [PATCH] Docs for Habitica component (#5923) * Docs for Habitica component (1/2) Signed-off-by: delphi * Added sensor docs. Updated docs to match habitica code. Signed-off-by: delphi * Fix docs according to docs Signed-off-by: delphi * Fix typos and code review Signed-off-by: delphi --- source/_components/habitica.markdown | 132 ++++++++++++++++++ source/_components/sensor.habitica.markdown | 21 +++ .../images/screenshots/habitica_new_task.png | Bin 0 -> 2535 bytes source/images/supported_brands/habitica.png | Bin 0 -> 5677 bytes 4 files changed, 153 insertions(+) create mode 100644 source/_components/habitica.markdown create mode 100644 source/_components/sensor.habitica.markdown create mode 100644 source/images/screenshots/habitica_new_task.png create mode 100644 source/images/supported_brands/habitica.png diff --git a/source/_components/habitica.markdown b/source/_components/habitica.markdown new file mode 100644 index 00000000000..fbd51c31267 --- /dev/null +++ b/source/_components/habitica.markdown @@ -0,0 +1,132 @@ +--- +layout: page +title: "Habitica" +description: "Instructions on enabling Habitica support for your Home Assistant" +date: 2018-08-09 00:00 +sidebar: true +comments: false +sharing: true +footer: true +logo: habitica.png +ha_category: Hub +ha_version: 0.78 +ha_iot_class: "Cloud Polling" +--- + +This component allows you to monitor and manage your Habitica profile. This component exposes the [Habitica's API](https://habitica.com/apidoc/) as a Home Assistant service. It supports multiple users and allows you to automate checking out your habits and daily tasks or casting magics using Home Assistant. +This component enables usage of [`sensor.habitica` platform.](/components/sensor.habitica/) +To use the component you should use this example configuration: + +```yaml +# Minimum viable configuration.yaml entry +habitica: + - api_user: 'REPLACE_ME_WITH_YOUR_USER_ID' + api_key: 'REPLACE_ME_WITH_YOUR_API_KEY' +``` + +You can specify several users, providing `api_user` and `api_key` for each. +At runtime you will be able to use API for each respective user by their Habitica's username. +You can override this by passing `name` key, this value will be used instead of the username. +If you are hosting your own instance of Habitica, you can specify a URL to it in `url` key. + +{% configuration %} +api_user: + description: "Habitica's API user ID. This value can be grabbed from [account setting](https://habitica.com/user/settings/api)" + required: true + type: string +api_key: + description: "Habitica's API password (token). This value can be grabbed from [account setting](https://habitica.com/user/settings/api) by pressing 'Show API token'" + required: true + type: string +name: + description: "Override for Habitica's username. Will be used for service calls" + required: false + type: string + default: Deduced at startup +url: + description: "URL to your Habitica instance, if you are hosting your own" + required: false + type: string + default: http://habitica.com +sensors: + description: List of sensors to generate for this user. If you don't specify this entry then the default (all sensors) will be generated. If you specify this entry empty then no sensors will be generated. + required: false + type: list + default: all (`name`, `hp`, `maxHealth`, `mp`, `maxMP`, `exp`, `toNextLevel`, `lvl`, `gp`, `class`) +{% endconfiguration %} + +### {% linkable_title API Service Parameters %} + +The API is exposed to Home Assistant as a service called `habitica.api_call`. To call it you should specify this keys in service data: + +| Service data attribute | Required | Type | Description | +|----------------------|--------|--------|----------------| +| `name` | yes | string | Habitica's username as per `configuration.yaml` entry. | +| `path` | yes | [string] | Items from API URL in form of an array with method attached at the end. See the example below. | +| `args` | no | map | Any additional json or url parameter arguments. See the example below and [apidoc](https://habitica.com/apidoc/). | + +A successful call to this service will fire an event `habitica_api_call_success`. + +| Event data attribute | Type | Description | +|----------------------|--------|----------------| +| `name` | string | Copied from service data attribute. | +| `path` | [string] | Copied from service data attribute. | +| `data` | map | Deserialized `data` field of JSON object Habitica's server returned in response to api call. For more info see [docs](https://habitica.com/apidoc/). | + +#### Let's consider some examples on how to call the service. + +For example, let's say that there is a configured `habitica` platform for user `xxxNotAValidNickxxx` with their respective `api_user` and `api_key`. +Let's create a new task (a todo) for this user via Home Assistant. There is an [API call](https://habitica.com/apidoc/#api-Task-CreateUserTasks) for this purpose. +To create a new task one should hit `https://habitica.com/api/v3/tasks/user` endpoint with `POST` request with a json object with task properties. +So let's call the API on `habitica.api_call`. +* The `name` key becomes `xxxNotAValidNickxxx`. +* The `path` key is trickier. + * Remove 'https://habitica.com/api/v3/' at the beginning of the endpoint URL. + * Split the remaining on slashes (/) and **append the lowercase method** at the end. + * You should get `["tasks", "user", "post"]`. To get a better idea of the API you are recommended to try all of the API calls in IPython console [using this package](https://github.com/ASMfreaK/habitipy/blob/master/README.md). +* The `args` key is more or less described in the [docs](https://habitica.com/apidoc/). + +Combining all together: +call `habitica.api_call` with data +``` +{ + "name": "xxxNotAValidNickxxx", + "path": ["tasks", "user", "post"], + "args": {"text": "Use API from Home Assistant", "type": "todo"} +} +``` + +This call will create a new todo on `xxxNotAValidNickxxx`'s account with text `Use API from Home Assistant` like this: + +![example task created](/images/screenshots/habitica_new_task.png) + +Also an event `habitica_api_call_success` will be fired with the following data: +``` +{ + "name": "xxxNotAValidNickxxx", + "path": ["tasks", "user", "post"], + "data": { + "challenge": {}, + "group": {"approval": {"required": false, + "approved": false, + "requested": false}, + "assignedUsers": [], + "sharedCompletion": "recurringCompletion"}, + "completed": false, + "collapseChecklist": false, + "type": "todo", + "notes": "", + "tags": [], + "value": 0, + "priority": 1, + "attribute": "str", + "text": "Use API from Home Assistant", + "checklist": [], + "reminders": [], + "_id": "NEW_TASK_UUID", + "createdAt": "2018-08-09T18:03:27.759Z", + "updatedAt": "2018-08-09T18:03:27.759Z", + "userId": "xxxNotAValidNickxxx's ID", + "id": "NEW_TASK_UUID"} +} +``` diff --git a/source/_components/sensor.habitica.markdown b/source/_components/sensor.habitica.markdown new file mode 100644 index 00000000000..4e94148bb9f --- /dev/null +++ b/source/_components/sensor.habitica.markdown @@ -0,0 +1,21 @@ +--- +layout: page +title: "Habitica Sensor" +description: "Instructions on enabling Habitica support for your Home Assistant" +date: 2018-08-09 00:00 +sidebar: true +comments: false +sharing: true +footer: true +logo: habitica.png +ha_category: Sensor +ha_iot_class: "Cloud Polling" +ha_version: 0.78 +--- + +The `habitica` sensor platform allows you to view and monitor your player data from [Habitica](https://habitica.com/) in Home Assistant. + +

+You must have the [`habitica` component](/components/habitica/) +configured to use this platform. After configuring that component, sensors specified there will automatically appear. +

diff --git a/source/images/screenshots/habitica_new_task.png b/source/images/screenshots/habitica_new_task.png new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Ia!-qHhs;QB&XD3s_heY z#i$>WJS|U%bQ~a8Rbfoc#KpxI7w4>OA}csU8IxP_i~nAky3?VO-DJ9!W~%G)OX=M% zm(RAVfS={<-BFZs9?D*tn6R}Jh{G7*CO6F+Q&OB*c@5tk7&daUJ9~TQqrc>6+02u} za63gWy~w5ok$RvzC48x=EMJX~nOJkq93kai+9H)A1f}v9i#wkrE6P9f&^N+n7PX+> zygqwRDdp$r=({lW&~9EN((e6zi8Eu$3~$PJfB&|&9&P33?Fm|Bcom34!R>vSnBcO} zQ0ESn^U*Y6>TXcp*U%mZPD6Qx#yLpFERD9&bJdOf^!lImxr{?|ScEP!#i zcNc~CFmT!xX*qqXQ{@U24!0%A4SB8{QhL!N()B6Zrh`Mn@M@a9Kqe7wAxLsNm&CSn z-lKE-Z#(@h2(3}nf;mQ*VU}+ZT*k-7E(epvc2CVYFA!2wDT6p!sc0AL1X#azEdAl8 z_0-gBlh6$IT#?7E7QuXX0}8z-*L0zNAE*j(jx%sD>(f4JHo`{hWR8&gmrg6`y;AXy z_?+H#xaUf|9=T_IiL0*2CmXpuNAIM)D*k-w$U#?^jG5O5$;mfGO0Fce;1~nSDTB+8 z537F<4GYr@*|_mGkh!_^g$+q0^)K~g_Z%){re#<+sZ|HdNaLcGW?ZHNu4oG=2*6PI z`g%)_0yH*i9NjQaGoQe1*Rif5nKVLLTTOm}Vww>Z{fs=KcU12wv5sH;jMBI!?_$aBsD6cL;+yL?FcbURlg-~rpAnsNIW zO4%TeXHDlP4Thp^QKi?{iS(~F4bGdfkD~lKsXZ5?Lqba|aE*Uq4-$%=n-Ymc?M&6d zo}Tr%{2GMsUi|m&m)ttxI-AU= zbIS4g!z*H7JSA@k26z zyvyA0Y{_}xIXyD-;1cw;)=7f4LU$iWFjGTRcaZlMT?NWT42hhd8=$Xie6t*7|Kwkf CPt$e) literal 0 HcmV?d00001 diff --git a/source/images/supported_brands/habitica.png b/source/images/supported_brands/habitica.png new file mode 100644 index 0000000000000000000000000000000000000000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