Fix bugs, add Qot motion sensors
This commit is contained in:
parent
7b15b39d5f
commit
fa8f2cddb5
47
main.py
47
main.py
|
@ -78,7 +78,7 @@ class Sensor():
|
|||
value = {}
|
||||
prev_value = {}
|
||||
bad_keys = []
|
||||
last_update = time.time()
|
||||
last_update = None
|
||||
update_period = None
|
||||
|
||||
def __init__(self, id_, name):
|
||||
|
@ -133,7 +133,7 @@ class Sensor():
|
|||
logging.info('Wrote %s data to InfluxDB: %s', self, data)
|
||||
|
||||
def check_update(self):
|
||||
if self.update_period:
|
||||
if self.update_period and self.last_update:
|
||||
if time.time() - self.last_update > self.update_period:
|
||||
logging.warning('Missed expected update from %s.', self)
|
||||
self.last_update = time.time()
|
||||
|
@ -249,7 +249,7 @@ class Acurite606TX(Sensor):
|
|||
self.offset = offset
|
||||
|
||||
def transform(self, data):
|
||||
if data['battery_ok'] != 1:
|
||||
if data.get('battery_ok', None) != 1:
|
||||
logging.error('%s battery not ok!', self)
|
||||
data['temperature_C'] = float(data['temperature_C']) + self.offset
|
||||
|
||||
|
@ -264,16 +264,27 @@ class AcuRite6002RM(Sensor):
|
|||
update_period = 40
|
||||
offset = 0.0
|
||||
|
||||
def __init__(self, id_, name, offset=0.0):
|
||||
def __init__(self, id_, name, temp_offset=0.0, hum_offset=0.0):
|
||||
self.id_ = id_
|
||||
self.name = name
|
||||
self.offset = offset
|
||||
self.temp_offset = temp_offset
|
||||
self.hum_offset = hum_offset
|
||||
|
||||
def transform(self, data):
|
||||
if data['battery_ok'] != 1:
|
||||
if data.get('battery_ok', None) != 1:
|
||||
logging.error('%s battery not ok!', self)
|
||||
data['temperature_C'] = float(data['temperature_C']) + self.offset
|
||||
data['humidity'] = float(data['humidity'])
|
||||
data['temperature_C'] = float(data['temperature_C']) + self.temp_offset
|
||||
data['humidity'] = float(data['humidity']) + self.hum_offset
|
||||
|
||||
class QotMotionSensor(Sensor):
|
||||
type_ = 'qotmotion'
|
||||
update_period = False
|
||||
|
||||
def transform(self, data):
|
||||
split = data['data'].split(',')
|
||||
data['battery'] = int(split[0])
|
||||
data['boots'] = int(split[1])
|
||||
data['motion'] = True # useful to distinguish if I eventually add a heartbeat
|
||||
|
||||
|
||||
async def poll_sensors():
|
||||
|
@ -495,14 +506,26 @@ if __name__ == '__main__':
|
|||
sensors.add(ERTSCMSensor('78628180', 'Gas'))
|
||||
sensors.add(OwnTracksSensor('owntracks1', 'OwnTracks'))
|
||||
sensors.add(AirSensor('air1', 'Living Room'))
|
||||
sensors.add(Acurite606TX('59', 'Outside'))
|
||||
sensors.add(Acurite606TX('185', 'Outside', 0.0))
|
||||
sensors.add(AcuRite6002RM('999999', 'Seeds', 0.0)) # A
|
||||
sensors.add(AcuRite6002RM('5613', 'Misc', 0.0)) # A
|
||||
sensors.add(AcuRite6002RM('5109', 'Nook', 0.4)) # B
|
||||
sensors.add(AcuRite6002RM('11087', 'Bedroom', -0.3)) # C
|
||||
sensors.add(AcuRite6002RM('999998', 'Misc', 0.7, -1.0)) # A
|
||||
sensors.add(AcuRite6002RM('5613', 'Basement', 0.7, -1.0)) # A
|
||||
sensors.add(AcuRite6002RM('5109', 'Nook', 0.2, -1.0)) # B
|
||||
sensors.add(AcuRite6002RM('11087', 'Bedroom', -0.7, 1.0)) # C
|
||||
sensors.add(SleepSensor('sleep1', 'Bedroom'))
|
||||
sensors.add(SolarSensor('solar', 'Solar'))
|
||||
|
||||
sensors.add(QotMotionSensor('qot_dc3c', 'Bedroom'))
|
||||
sensors.add(QotMotionSensor('qot_88c3', 'Lower Stairs Hi'))
|
||||
sensors.add(QotMotionSensor('qot_7c3c', 'Theatre'))
|
||||
sensors.add(QotMotionSensor('qot_54e6', 'Lab'))
|
||||
sensors.add(QotMotionSensor('qot_10f4', 'Office'))
|
||||
sensors.add(QotMotionSensor('qot_74c3', 'Guest Bathroom'))
|
||||
sensors.add(QotMotionSensor('qot_706f', 'Nook'))
|
||||
sensors.add(QotMotionSensor('qot_8c1c', 'Kitchen S'))
|
||||
sensors.add(QotMotionSensor('qot_a83b', 'Kitchen N'))
|
||||
sensors.add(QotMotionSensor('qot_28c3', 'Side Entrance'))
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
a = loop.create_task(poll_sensors()).add_done_callback(task_died)
|
||||
b = loop.create_task(fetch_mqtt()).add_done_callback(task_died)
|
||||
|
|
Loading…
Reference in New Issue
Block a user