From 72761ceee64299dd88f8060ddbb6c65da883f3f0 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 9 Nov 2022 14:10:50 +0100 Subject: [PATCH] Support "tlv8" and "data" characteristic formats (#8) --- src/boundaries/hap.ts | 8 +++++--- src/metrics.ts | 2 ++ tests/aggregator.test.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/boundaries/hap.ts b/src/boundaries/hap.ts index cd7741c..0265def 100644 --- a/src/boundaries/hap.ts +++ b/src/boundaries/hap.ts @@ -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 +export type NumericTypes = z.infer 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 diff --git a/src/metrics.ts b/src/metrics.ts index e352bae..1764220 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -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': diff --git a/tests/aggregator.test.ts b/tests/aggregator.test.ts index 319ced0..2f44eb0 100644 --- a/tests/aggregator.test.ts +++ b/tests/aggregator.test.ts @@ -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'