dirkse 8 лет назад
Родитель
Сommit
507973d003
2 измененных файлов с 28 добавлено и 1 удалено
  1. 23 1
      alexa/app/domo.py
  2. 5 0
      alexa/readme.md

+ 23 - 1
alexa/app/domo.py

@@ -4,6 +4,9 @@ import os
 
 import logging
 from timeit import default_timer
+from random import choice
+import time
+
 import requests
 
 from ameise import app, ask, log
@@ -23,6 +26,15 @@ ROOM2POWER_DOMO_IDX = {
     'wohnzimmer': 2840,
 }
 
+class RoomState(object):
+    def __init__(self):
+        self.last_switches = {}
+        for room in ROOM2POWER_DOMO_IDX:
+            self.last_switches[room] = time.time()
+
+
+STATE = RoomState()
+
 # map alexa slot to domoticz switch value
 ON_OFF_SLOT = {'an': 'On', 'aus': 'Off'}
 
@@ -61,4 +73,14 @@ def toggle_switch(OnOff):
     log.info('domoticz: device %s switch: %s' % (domo_idx, switchcmd))
 
     domo_command(param='switchlight', idx=domo_idx, switchcmd=switchcmd)
-    return statement('Ich habe das Licht im %s %sgeschaltet.' % (room, OnOff))
+
+    delta_last = time.time() - STATE.last_switches[room]
+    STATE.last_switches[room] = time.time()
+
+    if delta_last < 30:
+        return statement('')
+    else:
+        if choice(range(10)) == 0:
+            return statement('Ich habe das Licht im %s %sgeschaltet.' % (room, OnOff))
+        else:
+            return statement('OK')

+ 5 - 0
alexa/readme.md

@@ -2,6 +2,11 @@ high level
 ==========
 * https://alexa.amazon.de
 
+skill entrypoint
+================
+* https://developer.amazon.com/edw/home.html#/skills
+* designing a entrypoint: https://developer.amazon.com/de/docs/custom-skills/understanding-how-users-invoke-custom-skills.html
+
 Ameisenhaufen
 ===============
 * Application Id: amzn1.ask.skill.0d944823-e51c-47a3-bddb-5043d6d9f3eb