-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.py
More file actions
39 lines (31 loc) · 1.18 KB
/
Copy pathsensor.py
File metadata and controls
39 lines (31 loc) · 1.18 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
class Sensor():
def __init__(self, name, type, client, source):
self.name = name
self.type = type
self.client = client
self.source = source
def Calibrate(self):
print("Calibrating {0} ...".format(self.name))
print("Complete!")
pass
def Announce(self):
self.client.Connect()
print("Announcing {0} ...".format(self.name))
self.client.Publish("/sensor/config/{0}".format(self.name), "")
print("Complete!")
def Update(self):
# Get the sensor value
value = self.source.Next()
#print(value)
# Format the data for MQTT message
value = str(value)
# Publish the MQTT message
self.client.Publish("/sensor/{0}/{1}".format(self.type, self.name), value)
class TemperatureSensor(Sensor):
def __init__(self, *args, **kwargs):
super().__init__(type = "temperature", *args, **kwargs)
pass
class HumiditySensor(Sensor):
def __init__(self, *args, **kwargs):
super().__init__(type = "humidity", *args, **kwargs)
pass