Enhance Home Assistant application configuration: added required HASS_HOST and HASS_TOKEN parameters, updated application name to 'hass', and refactored bootstrap logic for improved instance management.
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { CreateApplication, TServiceParams, StringConfig } from "@digital-alchemy/core";
|
import { CreateApplication, TServiceParams, StringConfig } from "@digital-alchemy/core";
|
||||||
|
import { LIB_HASS, PICK_ENTITY } from "@digital-alchemy/hass";
|
||||||
|
|
||||||
type Environments = "development" | "production" | "test";
|
type Environments = "development" | "production" | "test";
|
||||||
|
|
||||||
import { LIB_HASS } from "@digital-alchemy/hass";
|
|
||||||
|
|
||||||
// application
|
// application
|
||||||
const MY_APP = CreateApplication({
|
const MY_APP = CreateApplication({
|
||||||
configuration: {
|
configuration: {
|
||||||
@@ -13,15 +12,27 @@ const MY_APP = CreateApplication({
|
|||||||
enum: ["development", "production", "test"],
|
enum: ["development", "production", "test"],
|
||||||
description: "Code runner addon can set with it's own NODE_ENV",
|
description: "Code runner addon can set with it's own NODE_ENV",
|
||||||
} satisfies StringConfig<Environments>,
|
} satisfies StringConfig<Environments>,
|
||||||
|
HASS_HOST: {
|
||||||
|
type: "string",
|
||||||
|
description: "Home Assistant host URL",
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
HASS_TOKEN: {
|
||||||
|
type: "string",
|
||||||
|
description: "Home Assistant long-lived access token",
|
||||||
|
required: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
services: {},
|
services: {},
|
||||||
libraries: [LIB_HASS],
|
libraries: [LIB_HASS],
|
||||||
name: 'boilerplate'
|
name: 'hass' as const
|
||||||
});
|
});
|
||||||
|
|
||||||
const hass = await MY_APP.bootstrap()
|
let hassInstance: Awaited<ReturnType<typeof MY_APP.bootstrap>>;
|
||||||
|
|
||||||
|
|
||||||
export async function get_hass() {
|
export async function get_hass() {
|
||||||
return hass;
|
if (!hassInstance) {
|
||||||
|
hassInstance = await MY_APP.bootstrap();
|
||||||
|
}
|
||||||
|
return hassInstance;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user