mirror of
https://github.com/bckelley/tconnectsync.git
synced 2026-08-24 03:34:12 -05:00
attempt to mutate battery charge percent
This commit is contained in:
@@ -83,13 +83,13 @@ def eventNameFormat(text):
|
||||
def fieldNameFormat(text):
|
||||
if not text or all([i.isupper() for i in text]):
|
||||
return text
|
||||
return firstLower(text.replace('_', ' ').title().replace(' ', ''))
|
||||
return firstLower(text.replace('_', ' ').title().replace(' ', '')).replace('raw', 'Raw')
|
||||
|
||||
|
||||
def build_fields(event_def):
|
||||
ret = []
|
||||
for name, field in event_def["data"].items():
|
||||
suffix = 'Raw' if "transform" in field else ''
|
||||
suffix = 'Raw' if "transform" in field and name[-3:] != 'Raw' else ''
|
||||
f = f'{fieldNameFormat(name)}{suffix}: {TYPE_TO_PYOBJ[field["type"]]}'
|
||||
if "uom" in field:
|
||||
f += ' # ' + field['uom']
|
||||
@@ -105,7 +105,7 @@ def build_decode(event_def):
|
||||
p1 = f'{fieldNameFormat(name)}, = {unpack_command_for(field)}'
|
||||
p1s.append(p1)
|
||||
|
||||
suffix = 'Raw' if "transform" in field else ''
|
||||
suffix = 'Raw' if "transform" in field and name[-3:] != 'Raw' else ''
|
||||
|
||||
p2 = f'{fieldNameFormat(name)}{suffix} = {fieldNameFormat(name)},'
|
||||
p2s.append(p2)
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
"offset": 8,
|
||||
"uom": "units"
|
||||
},
|
||||
"finalEventForDay": {
|
||||
"batteryChargePercentMSBRaw": {
|
||||
"type": "uint8",
|
||||
"offset": 12
|
||||
},
|
||||
"batteryChargePercent": {
|
||||
"batteryChargePercentLSBRaw": {
|
||||
"type": "uint8",
|
||||
"offset": 13
|
||||
"offset": 13,
|
||||
"transform": [["battery_charge_percent", ""]]
|
||||
},
|
||||
"batteryLipoMilliVolts": {
|
||||
"type": "uint16",
|
||||
|
||||
@@ -598,20 +598,20 @@ class LidTimeChanged(BaseEvent):
|
||||
raw: RawEvent
|
||||
timeprior: int # ms
|
||||
timeafter: int # ms
|
||||
rawrtctime: int # ms
|
||||
Rawrtctime: int # ms
|
||||
|
||||
|
||||
@staticmethod
|
||||
def build(raw):
|
||||
timeprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10)
|
||||
timeafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14)
|
||||
rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18)
|
||||
Rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18)
|
||||
|
||||
return LidTimeChanged(
|
||||
raw = RawEvent.build(raw),
|
||||
timeprior = timeprior,
|
||||
timeafter = timeafter,
|
||||
rawrtctime = rawrtctime,
|
||||
Rawrtctime = Rawrtctime,
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -636,20 +636,20 @@ class LidDateChanged(BaseEvent):
|
||||
raw: RawEvent
|
||||
dateprior: int # day
|
||||
dateafter: int # day
|
||||
rawrtctime: int # ms
|
||||
Rawrtctime: int # ms
|
||||
|
||||
|
||||
@staticmethod
|
||||
def build(raw):
|
||||
dateprior, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 10)
|
||||
dateafter, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 14)
|
||||
rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18)
|
||||
Rawrtctime, = struct.unpack_from(UINT32, raw[:EVENT_LEN], 18)
|
||||
|
||||
return LidDateChanged(
|
||||
raw = RawEvent.build(raw),
|
||||
dateprior = dateprior,
|
||||
dateafter = dateafter,
|
||||
rawrtctime = rawrtctime,
|
||||
Rawrtctime = Rawrtctime,
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -4489,18 +4489,21 @@ class LidDailyBasal(BaseEvent):
|
||||
dailytotalbasal: float # units
|
||||
lastbasalrate: float # units/hour
|
||||
iob: float # units
|
||||
finaleventforday: int
|
||||
batterychargepercent: int
|
||||
batterychargepercentmsbRaw: int
|
||||
batterychargepercentlsbRaw: int
|
||||
batterylipomillivolts: int
|
||||
|
||||
@property
|
||||
def batteryChargePercent(self):
|
||||
return (256*(self.batteryChargePercentMSBRaw%2)+self.batteryChargePercentLSBRaw)/512
|
||||
|
||||
@staticmethod
|
||||
def build(raw):
|
||||
dailytotalbasal, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 10)
|
||||
lastbasalrate, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 14)
|
||||
iob, = struct.unpack_from(FLOAT32, raw[:EVENT_LEN], 18)
|
||||
finaleventforday, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 22)
|
||||
batterychargepercent, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23)
|
||||
batterychargepercentmsbRaw, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 22)
|
||||
batterychargepercentlsbRaw, = struct.unpack_from(UINT8, raw[:EVENT_LEN], 23)
|
||||
batterylipomillivolts, = struct.unpack_from(UINT16, raw[:EVENT_LEN], 24)
|
||||
|
||||
return LidDailyBasal(
|
||||
@@ -4508,8 +4511,8 @@ class LidDailyBasal(BaseEvent):
|
||||
dailytotalbasal = dailytotalbasal,
|
||||
lastbasalrate = lastbasalrate,
|
||||
iob = iob,
|
||||
finaleventforday = finaleventforday,
|
||||
batterychargepercent = batterychargepercent,
|
||||
batterychargepercentmsbRaw = batterychargepercentmsbRaw,
|
||||
batterychargepercentlsbRaw = batterychargepercentlsbRaw,
|
||||
batterylipomillivolts = batterylipomillivolts,
|
||||
)
|
||||
|
||||
|
||||
@@ -111,11 +111,22 @@ def transform_ratio(event_def, name, name_fmt, field, tx):
|
||||
|
||||
return out
|
||||
|
||||
def transform_battery_charge_percent(event_def, name, name_fmt, field, tx):
|
||||
out = []
|
||||
out += [
|
||||
'@property',
|
||||
f'def batteryChargePercent(self):',
|
||||
f' return (256*(self.batterychargepercentmsbRaw%2)+self.batterychargepercentlsbRaw)/512',
|
||||
''
|
||||
]
|
||||
|
||||
return out
|
||||
|
||||
|
||||
TRANSFORMS = {
|
||||
'enum': transform_enum,
|
||||
'dictionary': transform_dictionary,
|
||||
'bitmask': transform_bitmask,
|
||||
'ratio': transform_ratio
|
||||
'ratio': transform_ratio,
|
||||
'battery_charge_percent': transform_battery_charge_percent
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class ProcessDeviceStatus:
|
||||
return NightscoutEntry.devicestatus(
|
||||
created_at=event.eventTimestamp.format(),
|
||||
batteryVoltage=(float(event.batterylipomillivolts or 0)/1000),
|
||||
batteryString="%s%s" % (event.batterychargepercent, '%'),
|
||||
batteryString="%s%s" % (event.batteryChargePercent, '%'),
|
||||
pump_event_id = "%s" % event.seqNum
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user