telegen-iot 0.1.4.dev9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- TeleGen/__init__.py +9 -0
- TeleGen/actuators.py +102 -0
- TeleGen/binary_sensors.py +75 -0
- TeleGen/i2c_sensors.py +199 -0
- TeleGen/sensors.py +375 -0
- TeleGen/serial_sensors.py +296 -0
- TeleGen/static/images/CounterFitLogo.png +0 -0
- TeleGen/static/images/favicon.png +0 -0
- TeleGen/static/socket.io.min.js +7 -0
- TeleGen/static/socket.io.min.js.map +1 -0
- TeleGen/static/style.css +14 -0
- TeleGen/telegen.py +508 -0
- TeleGen/templates/binary_sensor_create_settings.html +8 -0
- TeleGen/templates/boolean_sensor.html +94 -0
- TeleGen/templates/camera_sensor.html +268 -0
- TeleGen/templates/float_sensor.html +142 -0
- TeleGen/templates/gps_sensor.html +232 -0
- TeleGen/templates/home.html +404 -0
- TeleGen/templates/i2c_float_sensor.html +142 -0
- TeleGen/templates/i2c_integer_sensor.html +142 -0
- TeleGen/templates/i2c_sensor_create_settings.html +21 -0
- TeleGen/templates/integer_sensor.html +142 -0
- TeleGen/templates/led_actuator.html +125 -0
- TeleGen/templates/pin_sensor_create_settings.html +21 -0
- TeleGen/templates/relay_actuator.html +97 -0
- TeleGen/templates/serial_sensor_create_settings.html +8 -0
- telegen_iot-0.1.4.dev9.dist-info/METADATA +71 -0
- telegen_iot-0.1.4.dev9.dist-info/RECORD +34 -0
- telegen_iot-0.1.4.dev9.dist-info/WHEEL +5 -0
- telegen_iot-0.1.4.dev9.dist-info/entry_points.txt +2 -0
- telegen_iot-0.1.4.dev9.dist-info/licenses/LICENSE +21 -0
- telegen_iot-0.1.4.dev9.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/test_serial_sensors.py +417 -0
TeleGen/__init__.py
ADDED
TeleGen/actuators.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ActuatorType(Enum):
|
|
6
|
+
FLOAT = 1
|
|
7
|
+
BOOLEAN = 2
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ActuatorBase(ABC):
|
|
11
|
+
def __init__(self, port: str):
|
|
12
|
+
self.__port = port
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def actuator_name() -> str:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def actuator_type() -> ActuatorType:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def port(self) -> str:
|
|
26
|
+
return self.__port
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
# pylint: disable=invalid-name
|
|
30
|
+
def id(self) -> str:
|
|
31
|
+
return self.__port
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class FloatActuatorBase(ActuatorBase):
|
|
35
|
+
def __init__(self, port: str):
|
|
36
|
+
super().__init__(port)
|
|
37
|
+
self.__value = 0
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def actuator_name() -> str:
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def actuator_type() -> ActuatorType:
|
|
46
|
+
return ActuatorType.FLOAT
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def value(self) -> float:
|
|
50
|
+
return self.__value
|
|
51
|
+
|
|
52
|
+
@value.setter
|
|
53
|
+
def value(self, val: float):
|
|
54
|
+
self.__value = val
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class BooleanActuatorBase(ActuatorBase):
|
|
58
|
+
def __init__(self, port: str):
|
|
59
|
+
super().__init__(port)
|
|
60
|
+
|
|
61
|
+
self.__value = False
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def actuator_name() -> str:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def actuator_type() -> ActuatorType:
|
|
70
|
+
return ActuatorType.BOOLEAN
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def value(self) -> bool:
|
|
74
|
+
return self.__value
|
|
75
|
+
|
|
76
|
+
@value.setter
|
|
77
|
+
def value(self, val: bool):
|
|
78
|
+
self.__value = val
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class RelayActuator(BooleanActuatorBase):
|
|
82
|
+
@staticmethod
|
|
83
|
+
def actuator_name() -> str:
|
|
84
|
+
return "Relay"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class LedActuator(BooleanActuatorBase):
|
|
88
|
+
def __init__(self, port: str):
|
|
89
|
+
super().__init__(port)
|
|
90
|
+
self.__color = "#FF0000"
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def actuator_name() -> str:
|
|
94
|
+
return "LED"
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def color(self) -> str:
|
|
98
|
+
return self.__color
|
|
99
|
+
|
|
100
|
+
@color.setter
|
|
101
|
+
def color(self, val: str):
|
|
102
|
+
self.__color = val
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from enum import Enum
|
|
3
|
+
import io
|
|
4
|
+
|
|
5
|
+
from TeleGen.sensors import SensorBase, SensorType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BinarySensorBase(SensorBase):
|
|
9
|
+
def __init__(self, name: str):
|
|
10
|
+
super().__init__(name)
|
|
11
|
+
self.__value = io.BytesIO()
|
|
12
|
+
self._next_repeat_time = None
|
|
13
|
+
self._value_position = 0
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def sensor_type() -> SensorType:
|
|
17
|
+
return SensorType.BINARY
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def sensor_name() -> str:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def id(self) -> str:
|
|
26
|
+
return self.port.replace("/", "").replace(" ", "")
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def value(self) -> io.BytesIO:
|
|
30
|
+
return self.__value
|
|
31
|
+
|
|
32
|
+
@value.setter
|
|
33
|
+
def value(self, val: io.BytesIO):
|
|
34
|
+
self.__value = val
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class CameraImageSource(Enum):
|
|
38
|
+
FILE = 1
|
|
39
|
+
WEBCAM = 2
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class CameraSensor(BinarySensorBase):
|
|
43
|
+
def __init__(self, name: str):
|
|
44
|
+
super().__init__(name)
|
|
45
|
+
self.__image_source = CameraImageSource.FILE
|
|
46
|
+
self.__image_file_name = ""
|
|
47
|
+
self.__web_cam_device_id = ""
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def sensor_name() -> str:
|
|
51
|
+
return "Camera"
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def image_source(self) -> CameraImageSource:
|
|
55
|
+
return self.__image_source
|
|
56
|
+
|
|
57
|
+
@image_source.setter
|
|
58
|
+
def image_source(self, val: CameraImageSource):
|
|
59
|
+
self.__image_source = val
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def image_file_name(self) -> str:
|
|
63
|
+
return self.__image_file_name
|
|
64
|
+
|
|
65
|
+
@image_file_name.setter
|
|
66
|
+
def image_file_name(self, val: str):
|
|
67
|
+
self.__image_file_name = val
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def web_cam_device_id(self) -> str:
|
|
71
|
+
return self.__web_cam_device_id
|
|
72
|
+
|
|
73
|
+
@web_cam_device_id.setter
|
|
74
|
+
def web_cam_device_id(self, val: str):
|
|
75
|
+
self.__web_cam_device_id = val
|
TeleGen/i2c_sensors.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import List
|
|
4
|
+
import random
|
|
5
|
+
|
|
6
|
+
from TeleGen.sensors import SensorBase, SensorType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class I2CSensorBase(SensorBase):
|
|
10
|
+
@staticmethod
|
|
11
|
+
def sensor_type() -> SensorType:
|
|
12
|
+
return SensorType.I2C
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def sensor_unit_type() -> SensorType:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def sensor_name() -> str:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def id(self) -> str:
|
|
26
|
+
return self.port
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def address(self) -> str:
|
|
30
|
+
return f"0x{int(self.port):02x}"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class FloatI2CSensorBase(I2CSensorBase):
|
|
34
|
+
def __init__(self, port: str, valid_min: float, valid_max: float):
|
|
35
|
+
super().__init__(port)
|
|
36
|
+
|
|
37
|
+
self.__valid_min = valid_min
|
|
38
|
+
self.__valid_max = valid_max
|
|
39
|
+
self.value = valid_min
|
|
40
|
+
self.random_min = float(valid_min)
|
|
41
|
+
self.random_max = float(valid_max)
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def sensor_name() -> str:
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def sensor_units() -> List[str]:
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def sensor_unit_type() -> SensorType:
|
|
55
|
+
return SensorType.FLOAT
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
@abstractmethod
|
|
59
|
+
def unit(self) -> str:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def value(self) -> float:
|
|
64
|
+
if self._random:
|
|
65
|
+
return round(random.uniform(self.__random_min, self.__random_max), 2)
|
|
66
|
+
|
|
67
|
+
return self.__value
|
|
68
|
+
|
|
69
|
+
@value.setter
|
|
70
|
+
def value(self, val: float):
|
|
71
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
72
|
+
raise ValueError()
|
|
73
|
+
self.__value = val
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def random_min(self) -> float:
|
|
77
|
+
return self.__random_min
|
|
78
|
+
|
|
79
|
+
@random_min.setter
|
|
80
|
+
def random_min(self, val: float):
|
|
81
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
82
|
+
raise ValueError()
|
|
83
|
+
self.__random_min = val
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def random_max(self) -> float:
|
|
87
|
+
return self.__random_max
|
|
88
|
+
|
|
89
|
+
@random_max.setter
|
|
90
|
+
def random_max(self, val: float):
|
|
91
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
92
|
+
raise ValueError()
|
|
93
|
+
self.__random_max = val
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def valid_min(self) -> float:
|
|
97
|
+
return self.__valid_min
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def valid_max(self) -> float:
|
|
101
|
+
return self.__valid_max
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class IntegerI2CSensorBase(I2CSensorBase):
|
|
105
|
+
def __init__(self, port: str, valid_min: int, valid_max: int):
|
|
106
|
+
super().__init__(port)
|
|
107
|
+
|
|
108
|
+
self.__valid_min = valid_min
|
|
109
|
+
self.__valid_max = valid_max
|
|
110
|
+
self.value = valid_min
|
|
111
|
+
self.random_min = int(valid_min)
|
|
112
|
+
self.random_max = int(valid_max)
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
@abstractmethod
|
|
116
|
+
def sensor_name() -> str:
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
@abstractmethod
|
|
121
|
+
def sensor_units() -> List[str]:
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def sensor_unit_type() -> SensorType:
|
|
126
|
+
return SensorType.INTEGER
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
@abstractmethod
|
|
130
|
+
def unit(self) -> str:
|
|
131
|
+
pass
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def value(self) -> int:
|
|
135
|
+
if self._random:
|
|
136
|
+
return random.randint(self.__random_min, self.__random_max)
|
|
137
|
+
|
|
138
|
+
return self.__value
|
|
139
|
+
|
|
140
|
+
@value.setter
|
|
141
|
+
def value(self, val: int):
|
|
142
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
143
|
+
raise ValueError()
|
|
144
|
+
self.__value = val
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def random_min(self) -> int:
|
|
148
|
+
return self.__random_min
|
|
149
|
+
|
|
150
|
+
@random_min.setter
|
|
151
|
+
def random_min(self, val: int):
|
|
152
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
153
|
+
raise ValueError()
|
|
154
|
+
self.__random_min = val
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def random_max(self) -> int:
|
|
158
|
+
return self.__random_max
|
|
159
|
+
|
|
160
|
+
@random_max.setter
|
|
161
|
+
def random_max(self, val: int):
|
|
162
|
+
if val < self.__valid_min or val > self.__valid_max:
|
|
163
|
+
raise ValueError()
|
|
164
|
+
self.__random_max = val
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def valid_min(self) -> int:
|
|
168
|
+
return self.__valid_min
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def valid_max(self) -> int:
|
|
172
|
+
return self.__valid_max
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# pylint: disable=C0103
|
|
176
|
+
class DistanceUnit(Enum):
|
|
177
|
+
Millimeter = 1
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class DistanceSensor(IntegerI2CSensorBase):
|
|
181
|
+
def __init__(self, port: str, unit):
|
|
182
|
+
if isinstance(unit, str):
|
|
183
|
+
unit = DistanceUnit[unit]
|
|
184
|
+
|
|
185
|
+
self.__unit = unit
|
|
186
|
+
|
|
187
|
+
super().__init__(port, 0, 999999)
|
|
188
|
+
|
|
189
|
+
@staticmethod
|
|
190
|
+
def sensor_name() -> str:
|
|
191
|
+
return "Distance"
|
|
192
|
+
|
|
193
|
+
@property
|
|
194
|
+
def unit(self) -> str:
|
|
195
|
+
return self.__unit.name
|
|
196
|
+
|
|
197
|
+
@staticmethod
|
|
198
|
+
def sensor_units() -> List[str]:
|
|
199
|
+
return [DistanceUnit.Millimeter.name]
|