This commit is contained in:
fuenmao
2026-11-13 14:03:38 +08:00
parent db0c578890
commit 09e8bded7e
22 changed files with 1309 additions and 607 deletions
+8 -8
View File
@@ -81,12 +81,12 @@ test('parameter conversion rejects junk and unavailable data; light zero and har
const { createDeviceParameterState, syncDeviceParameters } = env.load('devices/parameterRegistry')
const params = createDeviceParameterState()
syncDeviceParameters(params, { brightness: control('off'), color_temp: control('on', { color_temp_kelvin: 6500 }),
volume: control('on', { volume_level: .56 }), fragrance_auto_light: control('on') })
volume: control('on', { volume_level: .56 }), uv: control('on') })
assert.equal(params.lightBrightness, 0); assert.equal(params.lightColorTemp, 5000)
assert.equal(params.speakerVolume, 56)
assert.equal(params.fragranceAutoLight, true)
syncDeviceParameters(params, { fragrance_auto_light: control('unavailable', {}, false), volume: control('on', { volume_level: 'NaN' }) })
assert.equal(params.fragranceAutoLight, true); assert.equal(params.speakerVolume, 56)
assert.equal(params.dehumidifierUv, true)
syncDeviceParameters(params, { uv: control('unavailable', {}, false), volume: control('on', { volume_level: 'NaN' }) })
assert.equal(params.dehumidifierUv, true); assert.equal(params.speakerVolume, 56)
})
test('parameter availability is scoped to the actual device; missing numeric attributes are not default readings', () => {
@@ -150,13 +150,13 @@ test('all-off can interrupt start; a late start result cannot overwrite off feed
})
test('failed parameter command restores last known reading even if refresh itself fails', async () => {
const env = environment({ homeAssistantStatus: async () => status({ fragrance_auto_light: control('off') }),
const env = environment({ homeAssistantStatus: async () => status({ uv: control('off') }),
setParameter: async () => ({ success: false, message: '失败' }) })
const hook = env.load('composables/useDeviceControl').useDeviceControl()
await hook.loadStatus(); hook.localParams.fragranceAutoLight = true
await hook.loadStatus(); hook.localParams.dehumidifierUv = true
env.healthApi.homeAssistantStatus = async () => { throw new Error('离线') }
assert.equal(await hook.applyParam('fragrance', 'fragrance_auto_light', true), false)
assert.equal(hook.localParams.fragranceAutoLight, false)
assert.equal(await hook.applyParam('dehumidifier', 'uv', true), false)
assert.equal(hook.localParams.dehumidifierUv, false)
assert.equal(hook.actionFeedback.value.message, '失败')
env.dispose(); assert.equal(env.timeouts.size, 0)
})