Add Jest configuration files and enhance README with features and usage instructions

- Introduced `jest.config.cjs` and `jest.config.js` for Jest testing configuration.
- Expanded README.md to include detailed features, installation, configuration, and troubleshooting sections.
- Updated TypeScript configuration to target ES2022 and allow JavaScript files.
- Enhanced command handling in `src/index.ts` to support additional parameters for lights, covers, and climate entities.
- Added unit tests for command execution and Home Assistant connection validation.
- Updated schemas to include new entity types and parameters for better validation.
This commit is contained in:
jango-blockchained
2024-12-16 13:30:20 +01:00
parent 8bcc8c2b03
commit b55a75df54
9 changed files with 701 additions and 76 deletions

View File

@@ -1,8 +1,21 @@
import { CreateApplication, TServiceParams, StringConfig } from "@digital-alchemy/core";
import { LIB_HASS, PICK_ENTITY } from "@digital-alchemy/hass";
import { DomainSchema } from "../schemas.js";
type Environments = "development" | "production" | "test";
// Define the type for Home Assistant services
type HassServices = {
[K in keyof typeof DomainSchema.Values]: {
[service: string]: (data: Record<string, any>) => Promise<void>;
};
};
// Define the type for Home Assistant instance
interface HassInstance extends TServiceParams {
services: HassServices;
}
// application
const MY_APP = CreateApplication({
configuration: {
@@ -28,11 +41,12 @@ const MY_APP = CreateApplication({
name: 'hass' as const
});
let hassInstance: Awaited<ReturnType<typeof MY_APP.bootstrap>>;
let hassInstance: HassInstance;
export async function get_hass() {
export async function get_hass(): Promise<HassInstance> {
if (!hassInstance) {
hassInstance = await MY_APP.bootstrap();
const instance = await MY_APP.bootstrap();
hassInstance = instance as unknown as HassInstance;
}
return hassInstance;
}