Skip to content

Commit

Permalink
improve scene trigger types
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgera committed Feb 2, 2024
1 parent d21a97b commit 5555e3e
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 45 deletions.
10 changes: 5 additions & 5 deletions src/types/Music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export interface Music {
}

export interface MusicPlayItem {
id: string
id?: string
title: string
artist: string
album: string
imageURL: string
duration: number
artist?: string
album?: string
imageURL?: string
duration?: number
}
138 changes: 98 additions & 40 deletions src/types/Scene.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
import type { Device } from './device/Device'

interface CommonSceneTriggerProperties {
id?: string
type:
| 'time'
| 'sunriseSunset'
| 'motionSensor'
| 'controller'
| 'app'
| 'duration'
| 'event'
| 'other'
triggeredAt?: string
disabled: boolean
endTrigger?: SceneEndTrigger
endTriggerEvent?: SceneEndTrigger
}

type SceneEndTrigger =
| {
type: 'duration'
trigger: {
duration: number
}
}
| {
type: 'time'
trigger: {
time: string
}
}
| {
type: 'sunriseSunset'
trigger: {
type: 'sunrise' | 'sunset'
offset: number
}
nextTriggerAt?: string | null
}

type TimeSceneTrigger = CommonSceneTriggerProperties & {
type: 'time'
trigger: {
days: string[]
time: string
}
nextTriggerAt: string
}

type SunriseSunsetSceneTrigger = CommonSceneTriggerProperties & {
type: 'sunriseSunset'
trigger: {
days: string[]
type: 'sunrise' | 'sunset'
offset: number
}
nextTriggerAt: string
}

type ControllerSceneTrigger = CommonSceneTriggerProperties & {
type: 'controller'
trigger: {
days: string[]
controllerType: 'shortcutController'
clickPattern: 'singlePress' | 'doublePress' | 'longPress'
buttonIndex: 0
deviceId: string
}
}

type AppSceneTrigger = CommonSceneTriggerProperties & {
type: 'app'
}

type EventSceneTrigger = CommonSceneTriggerProperties & {
type: 'event'
trigger: {
days: string[]
deviceId: string
undo?: boolean
filter: {
attribute: Partial<Device['attributes']>
}
notifications?: {
type: 'opened' | 'closed'
}[]
}
}

type SceneTrigger =
| TimeSceneTrigger
| SunriseSunsetSceneTrigger
| ControllerSceneTrigger
| AppSceneTrigger
| EventSceneTrigger

export interface Scene {
id: string
info: {
Expand Down Expand Up @@ -42,52 +137,15 @@ export interface Scene {
| 'scenes_yoga'
}
type: 'userScene' | 'customScene' | 'playlistScene'
triggers: {
id: string
type:
| 'time'
| 'sunriseSunset'
| 'motionSensor'
| 'controller'
| 'app'
| 'duration'
| 'event'
| 'other'
triggeredAt?: string
disabled: boolean
trigger?:
| {
days: string[]
controllerType: 'shortcutController'
clickPattern: 'singlePress' | 'doublePress' | 'longPress'
buttonIndex: 0
deviceId: string
}
| {
days: string[]
deviceId: string
undo?: boolean
filter: {
attribute: Partial<Device['attributes']>
}
notifications?: {
type: 'opened' | 'closed'
}[]
} // TODO app, event, other, sunriseSunset, motionSensor, remote, time
}[]
triggers: SceneTrigger[]
actions: {
id?: string
type: 'device' | 'deviceSet'
enabled?: boolean
deviceId?: string
attributes: Record<string, any> // TODO
}[]
commands: {
id: string
type: 'device' | 'deviceSet'
enabled?: boolean
commands: any[] // TODO
attributes: Partial<Device['attributes']>
}[]
commands: any[]
createdAt: string
lastCompleted?: string
lastTriggered?: string
Expand Down
47 changes: 47 additions & 0 deletions test/responses/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ export const scene: Scene = {
buttonIndex: 0,
deviceId: '00000000-0000-0000-0000-000000000000',
},
endTriggerEvent: {
type: 'time',
trigger: {
time: '00:00',
},
},
},
{
id: '00000000-0000-0000-0000-000000000000',
type: 'time',
disabled: false,
trigger: {
days: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
time: '00:00',
},
endTrigger: {
type: 'duration',
trigger: {
duration: 1800,
},
},
endTriggerEvent: {
type: 'duration',
trigger: {
duration: 1800,
},
},
nextTriggerAt: '2000-01-01T00:00:00.000Z',
},
{
id: '00000000-0000-0000-0000-000000000000',
type: 'sunriseSunset',
disabled: false,
trigger: {
days: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
type: 'sunrise',
offset: 15,
},
nextTriggerAt: '2000-01-01T00:00:00.000Z',
endTriggerEvent: {
type: 'sunriseSunset',
trigger: {
type: 'sunrise',
offset: 0,
},
nextTriggerAt: null,
},
},
],
actions: [
Expand Down

0 comments on commit 5555e3e

Please sign in to comment.