1111
This commit is contained in:
@@ -81,9 +81,9 @@ 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 }),
|
||||
mattress_left_heating: control('4'), volume: control('on', { volume_level: .56 }), fragrance_auto_light: control('on') })
|
||||
volume: control('on', { volume_level: .56 }), fragrance_auto_light: control('on') })
|
||||
assert.equal(params.lightBrightness, 0); assert.equal(params.lightColorTemp, 5000)
|
||||
assert.equal(params.mattressLeftHeating, 4); assert.equal(params.speakerVolume, 56)
|
||||
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)
|
||||
@@ -105,20 +105,6 @@ test('parameter availability is scoped to the actual device; missing numeric att
|
||||
assert.equal(parameterIsAvailable(controls, 'brightness', lamp), false)
|
||||
})
|
||||
|
||||
test('mattress per-user preferences remain separate from the one physically running side', () => {
|
||||
const env = environment(), params = env.load('devices/parameterRegistry').createDeviceParameterState()
|
||||
const user = env.vue.ref(1), hook = env.load('devices/mattress/useMattressPreferences').useMattressPreferences(params, user, () => 'mattress')
|
||||
hook.syncModes({ mattress_left_mode: control('智能适配'), mattress_right_mode: control('无') })
|
||||
assert.equal(params.mattressLeftMode, '智能适配'); assert.equal(params.mattressRightMode, '智能适配')
|
||||
assert.equal(hook.mattressActiveSide.value, 'left')
|
||||
hook.commitMode('left', '瑜伽助眠'); hook.commitMode('right', '智能腰托')
|
||||
hook.syncModes({ mattress_left_mode: control('无'), mattress_right_mode: control('智能腰托') })
|
||||
assert.equal(params.mattressLeftMode, '瑜伽助眠'); assert.equal(hook.mattressActiveSide.value, 'right')
|
||||
hook.syncModes({ mattress_left_mode: control('智能适配'), mattress_right_mode: control('智能腰托') })
|
||||
assert.equal(hook.mattressActiveSide.value, 'right')
|
||||
user.value = 2; hook.syncModes({})
|
||||
assert.equal(params.mattressLeftMode, '智能适配')
|
||||
})
|
||||
|
||||
test('older transition response cannot replace newer volume; disposal cannot create a late timer', async () => {
|
||||
const first = deferred(), second = deferred(); let reads = 0
|
||||
@@ -223,20 +209,6 @@ test('navigation closes a pending parameter toast and prevents a late result fro
|
||||
assert.equal(env.timeouts.size, 0)
|
||||
})
|
||||
|
||||
test('mattress confirmation cannot act after leaving the page or switching to another mattress', async () => {
|
||||
const confirmation = deferred(), env = environment({ confirmDialog: () => confirmation.promise })
|
||||
const selected = env.vue.ref(device('mattress', 'Sleep', [], { deviceId: 'first' }))
|
||||
let writes = 0
|
||||
const hook = env.load('devices/mattress/useMattressControls').useMattressControls(selected,
|
||||
async () => { writes++; return true }, async () => {}, () => {})
|
||||
const request = hook.setMattressSelect('mattress_massage_right_part', { target: { value: '全身' } })
|
||||
selected.value = undefined; confirmation.resolve(); await request
|
||||
assert.equal(writes, 0)
|
||||
selected.value = device('mattress', 'Sleep', [], { deviceId: 'first' })
|
||||
env.dispose()
|
||||
await hook.setMattressSelect('mattress_massage_right_part', { target: { value: '全身' } })
|
||||
assert.equal(writes, 0)
|
||||
})
|
||||
|
||||
const device = (moduleKey, category, entities = [], extra = {}) => ({
|
||||
deviceId: 'device', name: '测试设备', manufacturer: '', model: '', moduleKey, category,
|
||||
@@ -303,7 +275,10 @@ test('a failed new-light fade is not reported as success merely because the orig
|
||||
{ entityId: 'light.primary', running: true, success: true, brightnessPercent: 1, mode: 'sleep' },
|
||||
{ entityId: 'light.strip', running: true, success: true, brightnessPercent: 2, mode: 'sleep' },
|
||||
] }
|
||||
const env = environment({ lightTransitionStatus: async () => current })
|
||||
const primary = standardLight('light.primary'); primary.moduleKey = 'lighting'
|
||||
const strip = standardLight('light.strip'); strip.moduleKey = 'sleep-light-strip'
|
||||
const env = environment({ lightTransitionStatus: async () => current,
|
||||
homeAssistantStatus: async () => ({ connected: true, devices: [primary, strip] }) })
|
||||
const hook = env.load('composables/useDeviceControl').useDeviceControl(); await hook.loadStatus()
|
||||
current = { ...current, running: false, message: '原灯渐暗完成', lights: [
|
||||
{ entityId: 'light.primary', running: false, success: true, mode: 'sleep', message: '原灯渐暗完成' },
|
||||
@@ -316,6 +291,25 @@ test('a failed new-light fade is not reported as success merely because the orig
|
||||
env.dispose()
|
||||
})
|
||||
|
||||
test('an inventory without configured scene lights clears the previous fade and stops light requests', async () => {
|
||||
const primary = standardLight('light.primary'); primary.moduleKey = 'lighting'
|
||||
let devices = [primary], lightReads = 0
|
||||
const env = environment({
|
||||
homeAssistantStatus: async () => ({ connected: true, devices }),
|
||||
lightTransitionStatus: async () => { lightReads++; return { running: true, brightnessPercent: 50, mode: 'sleep' } },
|
||||
})
|
||||
const hook = env.load('composables/useDeviceControl').useDeviceControl()
|
||||
await hook.loadStatus()
|
||||
assert.equal(lightReads, 1)
|
||||
assert.equal(env.intervals.size, 1)
|
||||
devices = []
|
||||
await hook.loadStatus()
|
||||
assert.equal(lightReads, 1)
|
||||
assert.equal(hook.lightTransition.value, undefined)
|
||||
assert.equal(env.intervals.size, 0)
|
||||
env.dispose()
|
||||
})
|
||||
|
||||
test('standard light capabilities are per entity, not per category or another lamps configured parameters', () => {
|
||||
const { lightCapabilities } = environment().load('devices/lighting/capabilities')
|
||||
const item = standardLight(), capability = lightCapabilities(item)
|
||||
@@ -479,7 +473,7 @@ test('overview distinguishes a known off state from unavailable data and never a
|
||||
assert.equal(deviceSummary(climate).canToggle, false)
|
||||
})
|
||||
|
||||
test('overview separates fragrance from its nightlight and only uses mattress readings belonging to that device', () => {
|
||||
test('overview separates fragrance from its nightlight and does not infer retired mattress controls', () => {
|
||||
const { deviceSummary } = environment().load('devices/deviceSummary')
|
||||
const fragrance = device('fragrance', 'Fragrance', [entity('switch.fragrance', 'switch', 'off'), entity('light.night', 'light', 'on')],
|
||||
{ primaryControlEntityId: 'switch.fragrance' })
|
||||
@@ -488,7 +482,7 @@ test('overview separates fragrance from its nightlight and only uses mattress re
|
||||
const mattress = device('mattress', 'Sleep', [entity('select.massage', 'select', '全身')])
|
||||
assert.equal(deviceSummary(mattress).canToggle, false)
|
||||
assert.equal(deviceSummary(mattress, { controls: { mattress_massage_right_part: { ...control('全身'), entityId: 'foreign' } } }).statusText, '已连接')
|
||||
assert.equal(deviceSummary(mattress, { controls: { mattress_massage_right_part: { ...control('全身'), entityId: 'select.massage' } } }).statusText, '右侧按摩中')
|
||||
assert.equal(deviceSummary(mattress, { controls: { mattress_massage_right_part: { ...control('全身'), entityId: 'select.massage' } } }).statusText, '已连接')
|
||||
assert.equal(deviceSummary(mattress, { controls: { mattress_massage_right_part: { ...control('unknown'), entityId: 'select.massage' } } }).statusText, '已连接')
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user