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:
Innovation 2025-02-08 06:14:18 +00:00
parent e97c2815be
commit a8fbb578e8
5 changed files with 166 additions and 8 deletions

View 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

View 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

View 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

View file

@ -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 requests
import sys
@ -160,6 +163,11 @@ class Infinitime:
print(self.apiFailMsg)
self.uuid = None
def sendAll(self):
self.sendHeartrate()
self.sendSteps()
self.sendBattery()
# while True:
# try:
# heartrate = getHeartrate()

View file

@ -1,25 +1,54 @@
from infinitime import Infinitime
from aggregatorRecv import AggregatorRecv
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):
pinetime = Infinitime()
capabilities = json.loads(config.get('infinitime','capabilities'))
enabled.append(pinetime)
pinetime.connectCyberware()
if(aggregatorEnabled):
aggregator = AggregatorRecv()
capabilities = json.loads(config.get('aggregatorRecv','capabilities'))
enabled.append(aggregator)
aggregator.connectCyberware()
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:
try:
if(pinetimeEnabled):
pinetime.sendHeartrate()
pinetime.sendSteps()
pinetime.sendHeartrate()
for c in enabled:
c.sendAll()
time.sleep(1)
except KeyboardInterrupt:
print("Stopping vitalsd")
continueFlag = False
if(pinetimeEnabled):
pinetime.disconnectCyberware()
for c in enabled:
c.disconnectCyberware()