-
Notifications
You must be signed in to change notification settings - Fork 2
/
__init__.py
90 lines (72 loc) · 3.42 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from modules import cbpi
from modules.core.props import Property
from modules.core.hardware import ActorBase
import logging
import time
import requests
@cbpi.actor
class IFTTTWebhookProActor(ActorBase):
ifttt_url = "https://maker.ifttt.com/trigger/{}/with/key/{}?value1={}"
api_key = Property.Text("1. Maker Webhook Key", configurable=True,
default_value="", description="The key to be able to use this webhook")
hook_name = Property.Text("2. Webhook Name", configurable=True,
default_value="", description="The webhook name")
on_payload = Property.Text("3. On Payload", configurable=True,
default_value="ON", description="The value to send for the on command")
zoff_payload = Property.Text("4. Off Payload", configurable=True,
default_value="OFF", description="The value to send for the off command")
power = 100
def send(self, value):
print(self.api_key)
if self.api_key is None or self.api_key == '':
cbpi.notify("IFTTT Key Error", "The IFTTT maker key must be set",
type="warning", timeout=None)
url = self.ifttt_url.format(self.hook_name, self.api_key, value)
try:
response = requests.get(url)
response.raise_for_status()
except requests.exceptions.RequestException as err:
cbpi.notify(
"IFTTT Send Error", "There was an error sending the request to IFTTT. Please check your key", type="danger", timeout=20000)
self.api.app.logger.error(
"FAILED to switch IFTTT actor: {}".format(self.hook_name))
def on(self, power=None):
self.send(self.on_payload)
if power is not None:
self.set_power(power)
def off(self):
self.send(self.zoff_payload)
def set_power(self, power):
power = 100
@cbpi.actor
class IFTTTWebhookActor(ActorBase):
ifttt_url = "https://maker.ifttt.com/trigger/{}/with/key/{}"
key = Property.Text("Maker Webhook Key", configurable=True,
default_value="", description="The key to be able to use this webhook")
on_hook = Property.Text("On Hook Name", configurable=True,
default_value="", description="The webhook name for the on command")
off_hook = Property.Text("Off Hook Name", configurable=True,
default_value="", description="The webhook name for the off command")
power = 100
def send(self, command):
print(self.key)
if self.key is None or self.key == '':
cbpi.notify("IFTTT Key Error", "The IFTTT maker key must be set",
type="warning", timeout=None)
url = self.ifttt_url.format(command, self.key)
try:
response = requests.get(url)
response.raise_for_status()
except requests.exceptions.RequestException as err:
cbpi.notify(
"IFTTT Send Error", "There was an error sending the request to IFTTT. Please check your key", type="danger", timeout=20000)
self.api.app.logger.error(
"FAILED to switch IFTTT actor: {}".format(command))
def on(self, power=None):
self.send(self.on_hook)
if power is not None:
self.set_power(power)
def off(self):
self.send(self.off_hook)
def set_power(self, power):
power = 100