-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
015fe5c
commit 690471f
Showing
4 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
/** | ||
* Log a message to the console with proper formatting | ||
*/ | ||
|
||
export async function log(category, severity, ...messages) { | ||
const emojiForCategory = { | ||
'openai': '🧠', | ||
'ha': '🏠', | ||
'app': '🤖', | ||
} | ||
return console.log(emojiForCategory[category], `[${category.toUpperCase()}]`, ...messages); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const { | ||
NODE_ENV = 'development', | ||
} = process.env; | ||
|
||
// Default values depending on the environment | ||
const DEFAULT_HOME_ASSISTANT_HOST = (NODE_ENV === 'production') ? 'http://supervisor/core' : 'http://homeassistant.local'; | ||
const DEFAULT_HOME_ASSISTANT_PORT = (NODE_ENV === 'production') ? 80 : 8123; | ||
const DEFAULT_HOME_ASSISTANT_TOKEN = process.env.SUPERVISOR_TOKEN; | ||
|
||
// ===================================================================================================================== | ||
// Config | ||
// ===================================================================================================================== | ||
// Config — Directly from ENV or reasonable defaults for the environment | ||
|
||
export const { | ||
OPENAI_TOKEN, | ||
HOME_ASSISTANT_HOST = DEFAULT_HOME_ASSISTANT_HOST, | ||
HOME_ASSISTANT_PORT = DEFAULT_HOME_ASSISTANT_PORT, | ||
HOME_ASSISTANT_TOKEN = DEFAULT_HOME_ASSISTANT_TOKEN, | ||
} = process.env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import 'dotenv/config'; | ||
import {init} from './init'; | ||
import {log} from './_helpers/logs'; | ||
|
||
|
||
async function main() { | ||
console.log("Hello, world!"); | ||
console.log('Here are your environnment variables:'); | ||
console.log(process.env); | ||
|
||
// Init | ||
// =================================================================================================================== | ||
log('app','info','Starting up...'); | ||
log('app','info','Here are your environment variables:'); | ||
log('app','info',process.env); | ||
|
||
const {ha, openai } = await init(); | ||
log('app','info','Initialized.'); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dotenv/config' | ||
import homeassistant from 'homeassistant'; | ||
import OpenAI from 'openai'; | ||
import {HOME_ASSISTANT_TOKEN, HOME_ASSISTANT_HOST, OPENAI_TOKEN} from './config' | ||
import {log} from './_helpers/logs' | ||
|
||
|
||
export async function init() { | ||
const ha = new homeassistant({ | ||
host: HOME_ASSISTANT_HOST, | ||
port: 8123, | ||
token: HOME_ASSISTANT_TOKEN, | ||
}); | ||
const haStatus = await ha.status(); | ||
log('ha','debug',haStatus.message); | ||
const openai = new OpenAI({ | ||
apiKey: OPENAI_TOKEN, | ||
}); | ||
log('openai','debug','Initialized.'); | ||
return {ha,openai}; | ||
} |