|
1 |
| -import { CreateApplication } from '@digital-alchemy/core' |
| 1 | +import { LIB_AUTOMATION } from '@digital-alchemy/automation' |
| 2 | +import { CreateApplication, StringConfig } from '@digital-alchemy/core' |
2 | 3 | import { LIB_HASS } from '@digital-alchemy/hass'
|
| 4 | +import { LIB_SYNAPSE } from '@digital-alchemy/synapse' |
3 | 5 |
|
4 |
| -import { EntityList } from './entity-list' |
5 |
| -import { HelperFile } from './helper' |
| 6 | +import { RuntimePrecedence } from './core/runtime-precedence' |
| 7 | +import { Setup } from './core/setup' |
| 8 | +import { Helpers } from './helpers' |
| 9 | +import { Office } from './office' |
| 10 | + |
| 11 | +type AutomationEnvironments = 'development' | 'production' | 'test' |
6 | 12 |
|
7 | 13 | const HOME_AUTOMATION = CreateApplication({
|
8 |
| - /** |
9 |
| - * keep your secrets out of the code! |
10 |
| - * these variables will be loaded from your configuration file |
11 |
| - */ |
| 14 | + name: 'homeAutomation', |
12 | 15 | configuration: {
|
13 |
| - EXAMPLE_CONFIGURATION: { |
| 16 | + NODE_ENV: { |
| 17 | + type: 'string', |
| 18 | + default: 'development', |
| 19 | + enum: ['development', 'production', 'test'], |
| 20 | + description: "Code runner addon can set with it's own NODE_ENV", |
| 21 | + } satisfies StringConfig<AutomationEnvironments>, |
| 22 | + |
| 23 | + MY_CONFIG_SETTING: { |
14 | 24 | default: 'foo',
|
15 | 25 | description: 'A configuration defined as an example',
|
16 | 26 | type: 'string',
|
17 | 27 | },
|
18 | 28 | },
|
19 | 29 |
|
20 |
| - /** |
21 |
| - * Adding to this array will provide additional elements in TServiceParams |
22 |
| - * for your code to use |
23 |
| - */ |
24 |
| - libraries: [ |
25 |
| - /** |
26 |
| - * LIB_HASS provides basic interactions for Home Assistant |
27 |
| - * |
28 |
| - * Will automatically start websocket as part of bootstrap |
29 |
| - */ |
30 |
| - LIB_HASS, |
31 |
| - ], |
32 |
| - |
33 |
| - /** |
34 |
| - * must match key used in LoadedModules |
35 |
| - * affects: |
36 |
| - * - import name in TServiceParams |
37 |
| - * - and files used for configuration |
38 |
| - * - log context |
39 |
| - */ |
40 |
| - name: 'home_automation', |
41 |
| - |
42 |
| - /** |
43 |
| - * Need a service to be loaded first? Add to this list |
44 |
| - */ |
45 |
| - priorityInit: ['helper'], |
| 30 | + // Plugins for TSServiceParams |
| 31 | + libraries: [LIB_HASS, LIB_SYNAPSE, LIB_AUTOMATION], |
46 | 32 |
|
47 |
| - /** |
48 |
| - * Add additional services here |
49 |
| - * No guaranteed loading order unless added to priority list |
50 |
| - * |
51 |
| - * context: ServiceFunction |
52 |
| - */ |
| 33 | + // Service initialization order |
| 34 | + priorityInit: ['setup', 'runtimePrecedence', 'helpers'], |
53 | 35 | services: {
|
54 |
| - entity_list: EntityList, |
55 |
| - helper: HelperFile, |
| 36 | + setup: Setup, |
| 37 | + runtimePrecedence: RuntimePrecedence, |
| 38 | + helpers: Helpers, |
| 39 | + office: Office, |
56 | 40 | },
|
57 | 41 | })
|
58 | 42 |
|
59 |
| -// Load the type definitions |
| 43 | +// Do some magic to make all the types work |
60 | 44 | declare module '@digital-alchemy/core' {
|
61 | 45 | export interface LoadedModules {
|
62 |
| - home_automation: typeof HOME_AUTOMATION |
| 46 | + homeAutomation: typeof HOME_AUTOMATION |
63 | 47 | }
|
64 | 48 | }
|
65 | 49 |
|
66 |
| -// Kick off the application! |
| 50 | +// bootstrap application |
67 | 51 | setImmediate(
|
68 | 52 | async () =>
|
69 | 53 | await HOME_AUTOMATION.bootstrap({
|
70 |
| - /** |
71 |
| - * override library defined defaults |
72 |
| - * not a substitute for config files |
73 |
| - */ |
74 | 54 | configuration: {
|
75 |
| - // default value: trace |
76 |
| - boilerplate: { LOG_LEVEL: 'debug' }, |
| 55 | + boilerplate: { LOG_LEVEL: 'info' }, |
77 | 56 | },
|
78 | 57 | }),
|
79 | 58 | )
|
0 commit comments