Gracefully handle unknown service UUIDs (#10)
This commit is contained in:
parent
8130292d2b
commit
eead518f95
3 changed files with 103 additions and 1 deletions
|
@ -137,5 +137,5 @@ function uuidToServerName(uuid: string): string {
|
|||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`Could not resolve UUID ${uuid} to service`)
|
||||
return 'custom'
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import dysonData from './fixtures/dyson.json'
|
|||
import emptyData from './fixtures/empty.json'
|
||||
import tpLinkData from './fixtures/tp-link.json'
|
||||
import harmonyData from './fixtures/harmony.json'
|
||||
import unknownUuidData from './fixtures/issues/gh-9-unknown-uuid.json'
|
||||
|
||||
describe('Metrics aggregator', () => {
|
||||
const timestamp = new Date('2000-01-01 00:00:00 UTC')
|
||||
|
@ -154,4 +155,20 @@ describe('Metrics aggregator', () => {
|
|||
new Metric('speaker_volume_percentage', 50, timestamp, expectedLabels4),
|
||||
])
|
||||
})
|
||||
|
||||
test('Aggregates metrics with unknown service UUID as "custom"', () => {
|
||||
const expectedLabels = {
|
||||
bridge: 'Test bridge',
|
||||
device_id: 'AA:AA:AA:AA:AA:AA',
|
||||
name: 'Phoscon-GW',
|
||||
}
|
||||
|
||||
const unknowmnUuid = DeviceBoundary.parse(unknownUuidData)
|
||||
|
||||
expect(aggregate([unknowmnUuid], timestamp)).toEqual([
|
||||
new Metric('custom_heartrate_seconds', 5, timestamp, expectedLabels),
|
||||
new Metric('custom_transition_time_seconds', 0.4, timestamp, expectedLabels),
|
||||
new Metric('custom_restart', 0, timestamp, expectedLabels),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
|
85
tests/fixtures/issues/gh-9-unknown-uuid.json
vendored
Normal file
85
tests/fixtures/issues/gh-9-unknown-uuid.json
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
{
|
||||
"ipAddress": "192.168.0.1",
|
||||
"instance": {
|
||||
"host": "192.168.0.1",
|
||||
"port": 51826,
|
||||
"url": "http://192.168.0.1:51826",
|
||||
"deviceID": "AA:AA:AA:AA:AA:AA",
|
||||
"txt": {
|
||||
"c#": "5",
|
||||
"ff": "0",
|
||||
"id": "AA:AA:AA:AA:AA:AA",
|
||||
"md": "homebridge",
|
||||
"pv": "1.1",
|
||||
"s#": "1",
|
||||
"sf": "0",
|
||||
"ci": "2",
|
||||
"sh": "Hv0v9A=="
|
||||
},
|
||||
"name": "Test bridge"
|
||||
},
|
||||
"accessories": {
|
||||
"accessories": [
|
||||
{
|
||||
"aid": 3,
|
||||
"services": [
|
||||
{
|
||||
"type": "00000012-0000-1000-8000-656261617577",
|
||||
"iid": 8,
|
||||
"characteristics": [
|
||||
{
|
||||
"type": "23",
|
||||
"iid": 9,
|
||||
"value": "Phoscon-GW",
|
||||
"perms": ["pr"],
|
||||
"description": "Name",
|
||||
"format": "string",
|
||||
"maxLen": 64
|
||||
},
|
||||
{
|
||||
"type": "00000024-0000-1000-8000-656261617577",
|
||||
"iid": 10,
|
||||
"value": 5,
|
||||
"perms": ["pr", "ev", "pw"],
|
||||
"description": "Heartrate",
|
||||
"format": "uint16",
|
||||
"unit": "seconds",
|
||||
"minValue": 1,
|
||||
"maxValue": 30,
|
||||
"minStep": 1
|
||||
},
|
||||
{
|
||||
"type": "00000023-0000-1000-8000-656261617577",
|
||||
"iid": 11,
|
||||
"value": "Thu Mar 04 2021 22:57:10",
|
||||
"perms": ["pr", "ev"],
|
||||
"description": "Last Updated",
|
||||
"format": "string"
|
||||
},
|
||||
{
|
||||
"type": "0000002F-0000-1000-8000-656261617577",
|
||||
"iid": 12,
|
||||
"value": 0.4,
|
||||
"perms": ["pr", "ev", "pw"],
|
||||
"description": "Transition Time",
|
||||
"format": "float",
|
||||
"unit": "seconds",
|
||||
"minValue": 0,
|
||||
"maxValue": 3600,
|
||||
"minStep": 0.1
|
||||
},
|
||||
{
|
||||
"type": "00000058-0000-1000-8000-656261617577",
|
||||
"iid": 13,
|
||||
"value": 0,
|
||||
"perms": ["pr", "ev", "pw"],
|
||||
"description": "Restart",
|
||||
"format": "bool"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue