-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
79 lines (60 loc) · 1.95 KB
/
__init__.py
File metadata and controls
79 lines (60 loc) · 1.95 KB
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
import time
try:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
except Exception as e:
print e
pass
from modules import cbpi
from modules.core.hardware import ActorBase, SensorPassive, SensorActive
from modules.core.props import Property
class RemoteSwitch(object):
repeat = 10
pulselength = 300
GPIOMode = GPIO.BCM
def __init__(self, key=[1, 1, 1, 1, 1], pin=4):
self.pin = pin
self.key = key
GPIO.setmode(self.GPIOMode)
GPIO.setup(self.pin, GPIO.OUT)
def switchOn(self, device):
self._switch(device,GPIO.HIGH)
def switchOff(self, device):
self._switch(device,GPIO.LOW)
def _switch(self, device, switch):
self.bit = [142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 136, 128, 0, 0, 0]
for t in range(5):
if self.key[t]:
self.bit[t] = 136
x = 1
for i in range(1, 6):
if device & x > 0:
self.bit[4 + i] = 136
x = x << 1
if switch == GPIO.HIGH:
self.bit[10] = 136
self.bit[11] = 142
bangs = []
for y in range(16):
x = 128
for i in range(1, 9):
b = (self.bit[y] & x > 0) and GPIO.HIGH or GPIO.LOW
bangs.append(b)
x = x >> 1
GPIO.output(self.pin, GPIO.LOW)
for z in range(self.repeat):
for b in bangs:
GPIO.output(self.pin, b)
time.sleep(self.pulselength / 1000000.)
@cbpi.actor
class Socket433MHz(ActorBase):
socket = Property.Select("socket", options=[1, 2, 3, 4, 5, 6])
@classmethod
def init_global(cls):
default_key = [1, 0, 0, 0, 1]
default_pin = 17
cls.device = RemoteSwitch(key=default_key, pin=default_pin)
def on(self, power=100):
self.device.switchOn(int(self.socket))
def off(self):
self.device.switchOff(int(self.socket))