Support "tlv8" and "data" characteristic formats (#8)
This commit is contained in:
parent
bbc19b935d
commit
72761ceee6
3 changed files with 8 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
import z from 'zod'
|
||||
|
||||
const NumberAlikeTypesTypesBoundary = z.union([
|
||||
const NumericTypesBoundary = z.union([
|
||||
z.literal('bool'),
|
||||
z.literal('float'),
|
||||
z.literal('int'),
|
||||
|
@ -9,17 +9,19 @@ const NumberAlikeTypesTypesBoundary = z.union([
|
|||
z.literal('uint32'),
|
||||
z.literal('uint64'),
|
||||
])
|
||||
export type NumberAlikeTypes = z.infer<typeof NumberAlikeTypesTypesBoundary>
|
||||
export type NumericTypes = z.infer<typeof NumericTypesBoundary>
|
||||
|
||||
export const CharacteristicBoundary = z.intersection(
|
||||
z.object({ type: z.string(), description: z.string() }),
|
||||
z.union([
|
||||
z.object({
|
||||
format: NumberAlikeTypesTypesBoundary,
|
||||
format: NumericTypesBoundary,
|
||||
value: z.optional(z.number()),
|
||||
unit: z.optional(z.string()),
|
||||
}),
|
||||
z.object({ format: z.literal('string'), value: z.string() }),
|
||||
z.object({ format: z.literal('data'), value: z.optional(z.string()) }),
|
||||
z.object({ format: z.literal('tlv8'), value: z.string(z.string()) }),
|
||||
]),
|
||||
)
|
||||
export type Characteristic = z.infer<typeof CharacteristicBoundary>
|
||||
|
|
|
@ -32,6 +32,8 @@ export function aggregate(devices: Device[], timestamp: Date): Metric[] {
|
|||
const format = characteristic.format
|
||||
switch (format) {
|
||||
case 'string':
|
||||
case 'tlv8':
|
||||
case 'data':
|
||||
break
|
||||
|
||||
case 'bool':
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, test } from '@jest/globals'
|
||||
import { DeviceBoundary } from '../src/boundaries/hap'
|
||||
import { DeviceBoundary } from '../src/boundaries'
|
||||
import { Metric, aggregate } from '../src/metrics'
|
||||
import dysonData from './fixtures/dyson.json'
|
||||
import emptyData from './fixtures/empty.json'
|
||||
|
|
Loading…
Reference in a new issue