Begin reworking vitalsd to not be crap. An abstract class is now used for general Cyberware. New Aggregator Reciever Cyberware is being worked on to be used as a general input (specifically for GadgetBridge). Infinitime needs updated.
This commit is contained in:
parent
e97c2815be
commit
a8fbb578e8
42
src/modules/vitalsd/aggregatorRecv.py
Normal file
42
src/modules/vitalsd/aggregatorRecv.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import subprocess
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
from flask import jsonify
|
||||||
|
from cyberwareAbs import Cyberware
|
||||||
|
|
||||||
|
class AggregatorRecv(Cyberware):
|
||||||
|
uuid = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
print("GadgetBridge Aggregator Reciever started")
|
||||||
|
print("[WARN] GadgetBridge Aggregator not implemented")
|
||||||
|
|
||||||
|
# def sendValue(self, url, jsonRequest):
|
||||||
|
# try:
|
||||||
|
# oldJson = json.loads(jsonRequest)
|
||||||
|
# uuidJson = {'uuid': self.uuid}
|
||||||
|
# oldJson.update(uuidJson)
|
||||||
|
# jsonWithUuid = json.dumps(oldJson)
|
||||||
|
#
|
||||||
|
# request = requests.post(url, json=jsonWithUuid)
|
||||||
|
#
|
||||||
|
# except:
|
||||||
|
# print(self.apiFailMsg)
|
||||||
|
# return 2 # 2 = No API contact.
|
||||||
|
#
|
||||||
|
# if request.status_code > 399:
|
||||||
|
# return 3 # 3 = API refused request.
|
||||||
|
#
|
||||||
|
# if request.status_code > 299:
|
||||||
|
# return 4 # 4 = API encountered an internal error.
|
||||||
|
#
|
||||||
|
# return 0 # 0 = Success
|
||||||
|
|
||||||
|
def sendAll(self):
|
||||||
|
o=0
|
||||||
|
|
||||||
|
def connectCyberware(self):
|
||||||
|
o=0
|
||||||
|
|
||||||
|
def disconnectCyberware(self):
|
||||||
|
o=0
|
23
src/modules/vitalsd/config.ini
Normal file
23
src/modules/vitalsd/config.ini
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
[enabled]
|
||||||
|
Infinitime = false
|
||||||
|
AggregatorRecv = false
|
||||||
|
|
||||||
|
; You should not edit any capabilities variables unless you know what you're doing.
|
||||||
|
[infinitime]
|
||||||
|
capabilities = [
|
||||||
|
"vitals/heartrate",
|
||||||
|
"vitals/steps",
|
||||||
|
"cyberware/battery"
|
||||||
|
]
|
||||||
|
priority = 999
|
||||||
|
|
||||||
|
[aggregatorRecv]
|
||||||
|
capabilities = [
|
||||||
|
"vitals/heartrate",
|
||||||
|
"vitals/steps",
|
||||||
|
"battery",
|
||||||
|
"vitals/bodytemp",
|
||||||
|
"vitals/oxygen",
|
||||||
|
"cyberware/battery"
|
||||||
|
]
|
||||||
|
priority = 0
|
56
src/modules/vitalsd/cyberwareAbs.py
Normal file
56
src/modules/vitalsd/cyberwareAbs.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import subprocess
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
from flask import jsonify
|
||||||
|
from abc import ABC,abstractmethod
|
||||||
|
|
||||||
|
class Cyberware(ABC):
|
||||||
|
# I'll expand this as necessary
|
||||||
|
urlBase = "http://localhost:5000/"
|
||||||
|
ENDPOINTS = {
|
||||||
|
"heartrate":urlBase+"api/vitals/heartrate",
|
||||||
|
"steps":urlBase+"api/vitals/steps",
|
||||||
|
"bodytemp":urlBase+"api/vitals/bodytemp",
|
||||||
|
"oxygen":urlBase+"api/vitals/oxygen",
|
||||||
|
"battery":urlBase+"api/vitals/battery",
|
||||||
|
"add":urlBase+"api/cyberware/add",
|
||||||
|
"remove":urlBase+"api/cyberware/remove"
|
||||||
|
}
|
||||||
|
|
||||||
|
def sendValue(self, url, jsonRequest):
|
||||||
|
try:
|
||||||
|
oldJson = json.loads(jsonRequest)
|
||||||
|
uuidJson = {'uuid': self.uuid}
|
||||||
|
oldJson.update(uuidJson)
|
||||||
|
jsonWithUuid = json.dumps(oldJson)
|
||||||
|
|
||||||
|
request = requests.post(url, json=jsonWithUuid)
|
||||||
|
|
||||||
|
except:
|
||||||
|
print(self.apiFailMsg)
|
||||||
|
return 2 # 2 = No API contact.
|
||||||
|
|
||||||
|
if request.status_code > 399:
|
||||||
|
return 3 # 3 = API refused request.
|
||||||
|
|
||||||
|
if request.status_code > 299:
|
||||||
|
return 4 # 4 = API encountered an internal error.
|
||||||
|
|
||||||
|
return 0 # 0 = Success
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def uuid(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def sendAll(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def connectCyberware(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def disconnectCyberware(self):
|
||||||
|
pass
|
|
@ -1,3 +1,6 @@
|
||||||
|
# TODO: Rewrite this file to use the CyberwareAbs abstract class.
|
||||||
|
# works as-is but man do I have nightmares knowing this file looks like this.
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
|
@ -160,6 +163,11 @@ class Infinitime:
|
||||||
print(self.apiFailMsg)
|
print(self.apiFailMsg)
|
||||||
self.uuid = None
|
self.uuid = None
|
||||||
|
|
||||||
|
def sendAll(self):
|
||||||
|
self.sendHeartrate()
|
||||||
|
self.sendSteps()
|
||||||
|
self.sendBattery()
|
||||||
|
|
||||||
# while True:
|
# while True:
|
||||||
# try:
|
# try:
|
||||||
# heartrate = getHeartrate()
|
# heartrate = getHeartrate()
|
||||||
|
|
|
@ -1,25 +1,54 @@
|
||||||
from infinitime import Infinitime
|
from infinitime import Infinitime
|
||||||
|
from aggregatorRecv import AggregatorRecv
|
||||||
import time
|
import time
|
||||||
|
import configparser
|
||||||
|
import json
|
||||||
|
|
||||||
pinetimeEnabled = True
|
config = configparser.ConfigParser()
|
||||||
|
config.read('config.ini')
|
||||||
|
|
||||||
|
pinetimeEnabled = config.getboolean('enabled','Infinitime')
|
||||||
|
aggregatorEnabled = config.getboolean('enabled', 'AggregatorRecv')
|
||||||
|
|
||||||
|
enabled = []
|
||||||
|
|
||||||
if(pinetimeEnabled):
|
if(pinetimeEnabled):
|
||||||
pinetime = Infinitime()
|
pinetime = Infinitime()
|
||||||
|
capabilities = json.loads(config.get('infinitime','capabilities'))
|
||||||
|
enabled.append(pinetime)
|
||||||
pinetime.connectCyberware()
|
pinetime.connectCyberware()
|
||||||
|
|
||||||
|
if(aggregatorEnabled):
|
||||||
|
aggregator = AggregatorRecv()
|
||||||
|
capabilities = json.loads(config.get('aggregatorRecv','capabilities'))
|
||||||
|
enabled.append(aggregator)
|
||||||
|
aggregator.connectCyberware()
|
||||||
|
|
||||||
continueFlag = True
|
continueFlag = True
|
||||||
|
|
||||||
|
#while continueFlag:
|
||||||
|
# try:
|
||||||
|
# if(pinetimeEnabled):
|
||||||
|
# pinetime.sendHeartrate()
|
||||||
|
# pinetime.sendSteps()
|
||||||
|
# pinetime.sendHeartrate()
|
||||||
|
#
|
||||||
|
# time.sleep(1)
|
||||||
|
# except KeyboardInterrupt:
|
||||||
|
# print("Stopping vitalsd")
|
||||||
|
# continueFlag = False
|
||||||
|
#
|
||||||
|
#if(pinetimeEnabled):
|
||||||
|
# pinetime.disconnectCyberware()
|
||||||
|
|
||||||
while continueFlag:
|
while continueFlag:
|
||||||
try:
|
try:
|
||||||
if(pinetimeEnabled):
|
for c in enabled:
|
||||||
pinetime.sendHeartrate()
|
c.sendAll()
|
||||||
pinetime.sendSteps()
|
|
||||||
pinetime.sendHeartrate()
|
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Stopping vitalsd")
|
print("Stopping vitalsd")
|
||||||
continueFlag = False
|
continueFlag = False
|
||||||
|
|
||||||
if(pinetimeEnabled):
|
for c in enabled:
|
||||||
pinetime.disconnectCyberware()
|
c.disconnectCyberware()
|
||||||
|
|
Loading…
Reference in a new issue