-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccessories.py
More file actions
108 lines (77 loc) · 3.29 KB
/
accessories.py
File metadata and controls
108 lines (77 loc) · 3.29 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: UTF-8 -*-
from random import randint
from pyhap.accessory import Accessory
from pyhap.const import CATEGORY_SENSOR
from integrapy.integra import Integra
from config import Config
integra = Integra(user_code=Config.usercode, host=Config.host, port=Config.port, encoding=Config.encoding)
class ContactSensor(Accessory):
"""Contact Sensor simplest configuration"""
category = CATEGORY_SENSOR
def __init__(self, integra_no, *args, **kwargs):
super().__init__(*args, **kwargs)
self.integra_no = integra_no
service = self.add_preload_service('ContactSensor')
self.sensor_char = service.configure_char('ContactSensorState')
@Accessory.run_at_interval(randint(10, 20))
async def run(self):
if self.integra_no in await integra.get_violated_zones():
self.sensor_char.set_value(1)
else:
self.sensor_char.set_value(0)
class MotionSensor(Accessory):
"""Motion Sensor simplest configuration"""
category = CATEGORY_SENSOR
def __init__(self, integra_no, *args, **kwargs):
super().__init__(*args, **kwargs)
self.integra_no = integra_no
service = self.add_preload_service('MotionSensor')
self.sensor_char = service.configure_char('MotionDetected')
@Accessory.run_at_interval(randint(1, 2))
async def run(self):
if self.integra_no in await integra.get_violated_zones():
self.sensor_char.set_value(1)
else:
self.sensor_char.set_value(0)
class LeakSensor(Accessory):
"""Leak Sensor simplest configuration"""
category = CATEGORY_SENSOR
def __init__(self, integra_no, *args, **kwargs):
super().__init__(*args, **kwargs)
self.integra_no = integra_no
service = self.add_preload_service('LeakSensor')
self.sensor_char = service.configure_char('LeakDetected')
@Accessory.run_at_interval(randint(1, 3))
async def run(self):
if self.integra_no in await integra.get_violated_zones():
self.sensor_char.set_value(1)
else:
self.sensor_char.set_value(0)
class SmokeSensor(Accessory):
"""Smoke Sensor simplest configuration"""
category = CATEGORY_SENSOR
def __init__(self, integra_no, *args, **kwargs):
super().__init__(*args, **kwargs)
self.integra_no = integra_no
service = self.add_preload_service('SmokeSensor')
self.sensor_char = service.configure_char('SmokeDetected')
@Accessory.run_at_interval(randint(1, 3))
async def run(self):
if self.integra_no in await integra.get_violated_zones():
self.sensor_char.set_value(1)
else:
self.sensor_char.set_value(0)
class CarbonDioxideSensor(Accessory):
"""Carbon Dioxide Sensor simplest configuration"""
category = CATEGORY_SENSOR
def __init__(self, integra_no, *args, **kwargs):
super().__init__(*args, **kwargs)
self.integra_no = integra_no
service = self.add_preload_service('CarbonDioxideSensor')
self.sensor_char = service.configure_char('CarbonDioxideDetected')
@Accessory.run_at_interval(randint(1, 3))
async def run(self):
if self.integra_no in await integra.get_violated_zones():
self.sensor_char.set_value(1)
else:
self.sensor_char.set_value(0)