Bladeren bron

add neuron taskeer autoremote

nico 8 jaren geleden
bovenliggende
commit
5edb5b117c

+ 12 - 11
Docs/neuron_list.md

@@ -2,15 +2,16 @@
 
 A neuron is a module you can use in your synapses. See the [complete neuron documentation](neurons.md) for more information.
 
-| Name                                                | Description                                                                             |
-|-----------------------------------------------------|-----------------------------------------------------------------------------------------|
-| [ansible_task](../neurons/ansible_task/README.md)   | Run an ansible playbook                                                                 |
-| [command](../neurons/command/README.md)             | Run a shell command                                                                     |
-| [gmail_checker](../neurons/gmail_checker/README.md) | Get the number of unread email and their subjects from a gmail account                  |
-| [kill_switch](../neurons/kill_switch/README.md)     | Stop Jarvis process                                                                     |
-| [push_message](../neurons/push_message/README.md)   | Send a push message to a remote device like Android/iOS/Windows Phone or Chrome browser |
-| [say](../neurons/say/README.md)                     | Make Jarvis talk by using TTS                                                           |
-| [script](../neurons/script/README.md)               | Run an executable script                                                                |
-| [sleep](../neurons/sleep/README.md)                 | Make Jarvis sleep for a while before continuing                                         |
-| [systemdate](../neurons/systemdate/README.md)       | Give the local system date and time                                                     |
+| Name                                               | Description                                                                             |
+|----------------------------------------------------|-----------------------------------------------------------------------------------------|
+| [ansible_task](../neurons/ansible_task/)           | Run an ansible playbook                                                                 |
+| [command](../neurons/command/)                     | Run a shell command                                                                     |
+| [gmail_checker](../neurons/gmail_checker/)         | Get the number of unread email and their subjects from a gmail account                  |
+| [kill_switch](../neurons/kill_switch/)             | Stop Jarvis process                                                                     |
+| [push_message](../neurons/push_message/)           | Send a push message to a remote device like Android/iOS/Windows Phone or Chrome browser |
+| [say](../neurons/say/)                             | Make Jarvis talk by using TTS                                                           |
+| [script](../neurons/script/)                       | Run an executable script                                                                |
+| [sleep](../neurons/sleep/)                         | Make Jarvis sleep for a while before continuing                                         |
+| [systemdate](../neurons/systemdate/)               | Give the local system date and time                                                     |
+| [tasker_autoremote](../neurons/tasker_autoremote/) | Send a message to Android tasker app                                                    |
 

+ 9 - 0
brain.yml

@@ -142,3 +142,12 @@
       - order: "I would like to hear the song {{ music_name }}"
       - order: "I would like to hear {{ artist_name }}"
 
+  - name: "find my phone"
+    neurons:
+      - say:
+          message: "Je fais sonner le téléphone, monsieur"
+      - tasker_autoremote:
+          key: "APA91bqmY"
+          message: "lost"
+    signals:
+      - order: "où est mon téléphone"

+ 4 - 0
core/NeuronModule.py

@@ -12,6 +12,10 @@ logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
 
+class MissingParameterException(Exception):
+    pass
+
+
 class NoTemplateException(Exception):
     pass
 

+ 1 - 0
neurons/__init__.py

@@ -7,3 +7,4 @@ from sleep import Sleep
 from systemdate import Systemdate
 from gmail_checker import Gmail_checker
 from push_message import Push_message
+from tasker_autoremote import Tasker_autoremote

+ 79 - 0
neurons/tasker_autoremote/Readme.md

@@ -0,0 +1,79 @@
+# Tasker autoremote
+
+## Synopsis
+
+[Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm) is an application for Android which performs 
+tasks (sets of actions) based on contexts (application, time, date, location, event, gesture) in user-defined profiles or in 
+clickable or timer home screen widgets.
+
+[Tasker autoremote](https://play.google.com/store/apps/details?id=com.joaomgcd.autoremote&hl=fr) is a plugin for Tasker that allow 
+the program to receive push message from the cloud as profile.
+
+This is how it works:
+- Send an AutoRemote message from Kalliope
+- Setup an AutoRemote profile in Tasker to react to the message
+- Do whatever you like with that message!
+
+The example usage is a "find my phone" task. 
+You could send a "Where are you?" message to your phone, and have Tasker respond with a repetitive "I'm here! I'm here!" 
+or play a music.
+
+
+## Options
+
+| parameter | required | default | choices | comment                                                       |
+|-----------|----------|---------|---------|---------------------------------------------------------------|
+| key       | yes      |         |         | API key. Can be found in your personal URL given by the app.  |
+| message   | yes      |         |         | Message to send to your phone                                 |
+
+## Return Values
+
+None
+
+## Synapses example
+
+Description of what the synapse will do
+```
+ - name: "find my phone"
+    neurons:
+      - say:
+          message: "I'll make your phone ringing, sir"
+      - tasker_autoremote:
+          key: "MY_VERY_LONG_KEY"
+          message: "lost"
+    signals:
+      - order: "where is my phone"
+```
+
+
+## Notes
+
+### How to create a find my phone task
+This walk through will show you how to send a message to your phone so that even if it is set to silent, 
+will play any music file at full volume so you can find your phone if you have lost it in the couch.
+
+First, create a task, that you could call "start_ringing" that will perform:
+- Disable the silent mode
+- Set media volume to the maximum value
+- Play a local music
+![task play music](images/task_play_music.png)
+
+Then, create a new task with just one action:
+- Stop the music
+![task stop music](images/task_stop_music.png)
+
+Create the input profile. 
+- create a context of type Event > Plugin > Autoremote
+- Set the word you want
+- Attach the event to the task "start_ringing"
+![task stop music](images/profile_auto_remote.png)
+
+Finally, create a event, to stop the music when we unlock the phone
+- create a context of type Event > Display > Display Unlocked
+- Attach the event to the stop that stop the music
+![task stop music](images/profile_display_unlocked.png)
+
+Exit Tasker with the exit menu to be sure all events and task have been saved.
+
+
+ 

+ 1 - 0
neurons/tasker_autoremote/__init__.py

@@ -0,0 +1 @@
+from tasker_autoremote import Tasker_autoremote

BIN
neurons/tasker_autoremote/images/profile_auto_remote.png


BIN
neurons/tasker_autoremote/images/profile_display_unlocked.png


BIN
neurons/tasker_autoremote/images/task_play_music.png


BIN
neurons/tasker_autoremote/images/task_stop_music.png


+ 33 - 0
neurons/tasker_autoremote/tasker_autoremote.py

@@ -0,0 +1,33 @@
+import logging
+
+import requests
+
+from core.NeuronModule import NeuronModule, MissingParameterException
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+class Tasker_autoremote(NeuronModule):
+    def __init__(self, **kwargs):
+        super(Tasker_autoremote, self).__init__(**kwargs)
+
+        # check if parameters have been provided
+        key = kwargs.get('key', None)
+        message = kwargs.get('message', None)
+
+        if key is None:
+            raise MissingParameterException("key parameter required")
+
+        if message is None:
+            raise MissingParameterException("message parameter required")
+
+        # create the payload
+        data = {'key': key,
+                'message': message}
+        url = "https://autoremotejoaomgcd.appspot.com/sendmessage"
+        # post
+        r = requests.post(url, data=data)
+        logging.debug("Post to tasker automore response: %s" % r.status_code)
+
+

+ 18 - 59
test.py

@@ -4,71 +4,30 @@ import re
 from collections import Counter
 
 from core import OrderAnalyser
+from neurons.tasker_autoremote.tasker_autoremote import Tasker_autoremote
+
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
 logger.setLevel(logging.DEBUG)
 
 
-# This does not work because of different encoding when using accent
-from core import OrderAnalyser
-# order = "kalliope régle le réveil pour sept heures et vingt minutes"
-# order = "mais nous de la musique"
+# # This does not work because of different encoding when using accent
+# from core import OrderAnalyser
+# # order = "kalliope régle le réveil pour sept heures et vingt minutes"
+# # order = "mais nous de la musique"
+#
+# order = "arrête la musique"
+# # order = order.decode('utf-8')
+# # print type(order)
+# oa = OrderAnalyser(order)
+#
+# oa.start()
+key = "mykey"
+message = "lost my phone"
+
+tk = Tasker_autoremote(key=key, message=message)
+
 
-order = "arrête la musique"
-# order = order.decode('utf-8')
-# print type(order)
-oa = OrderAnalyser(order)
 
-oa.start()
 
 
-# user_said = "kalliope régle le réveil pour sept heures et pour vingts minutes"
-#
-# order = "régle le réveil pour {{ hour }} heures et pour {{ minute }} minutes"
-#
-#
-# def counterSubset(list1, list2):
-#     """
-#     check if the number of occurrences matches
-#     :param list1:
-#     :param list2:
-#     :return:
-#     """
-#     c1, c2 = Counter(list1), Counter(list2)
-#     for k, n in c1.items():
-#         if n > c2[k]:
-#             return False
-#     return True
-#
-#
-# def _spelt_order_match_brain_order_via_table(order_to_analyse, user_said):
-#     list_word_user_said = user_said.split()
-#     split_order_without_bracket = _get_list_word_without_bracket(order_to_analyse)
-#
-#     number_of_word_in_order = len(split_order_without_bracket)
-#     # if all words in the list of what the user said in in the list of word in the order
-#     # return len(set(split_order_without_bracket).intersection(list_word_user_said)) == number_of_word_in_order
-#     return counterSubset(split_order_without_bracket, list_word_user_said)
-#
-#
-# def _get_list_word_without_bracket(order):
-#     """
-#     Get an order with bracket inside like: "hello my name is {{ name }}.
-#     return a list of string without bracket like ["hello", "my", "name", "is"]
-#     :param order: sentence to split
-#     :return: list of string without bracket
-#     """
-#     pattern = r"((?:{{\s*)[\w\.]+(?:\s*}}))"
-#     # find everything like {{ word }}
-#     matches = re.findall(pattern, order)
-#     for match in matches:
-#         order = order.replace(match, "")
-#     # then split
-#     split_order = order.split()
-#     return split_order
-#
-# # main test
-# if _spelt_order_match_brain_order_via_table(order, user_said):
-#     print "order matched"
-# else:
-#     print "order does not match"