feat: initialize project with Home Assistant integration

- Added index.ts for connecting to Home Assistant and subscribing to entities.
- Implemented function to calculate sleep time from sensor data.
- Created package.json with dependencies for TypeScript and Home Assistant WebSocket.
- Configured tsconfig.json for TypeScript with strict settings and ESNext features.
This commit is contained in:
Seth 2025-05-13 14:18:56 -04:00
parent 8f79c438b5
commit b73dfc84dd
6 changed files with 3926 additions and 0 deletions

34
.gitignore vendored Normal file
View file

@ -0,0 +1,34 @@
# dependencies (bun install)
node_modules
# output
out
dist
*.tgz
# code coverage
coverage
*.lcov
# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# caches
.eslintcache
.cache
*.tsbuildinfo
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store

30
bun.lock Normal file
View file

@ -0,0 +1,30 @@
{
"lockfileVersion": 1,
"workspaces": {
"": {
"name": "abissinskiy",
"dependencies": {
"home-assistant-js-websocket": "^9.5.0",
},
"devDependencies": {
"@types/bun": "latest",
},
"peerDependencies": {
"typescript": "^5",
},
},
},
"packages": {
"@types/bun": ["@types/bun@1.2.13", "", { "dependencies": { "bun-types": "1.2.13" } }, "sha512-u6vXep/i9VBxoJl3GjZsl/BFIsvML8DfVDO0RYLEwtSZSp981kEO1V5NwRcO1CPJ7AmvpbnDCiMKo3JvbDEjAg=="],
"@types/node": ["@types/node@22.15.17", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-wIX2aSZL5FE+MR0JlvF87BNVrtFWf6AE6rxSE9X7OwnVvoyCQjpzSRJ+M87se/4QCkCiebQAqrJ0y6fwIyi7nw=="],
"bun-types": ["bun-types@1.2.13", "", { "dependencies": { "@types/node": "*" } }, "sha512-rRjA1T6n7wto4gxhAO/ErZEtOXyEZEmnIHQfl0Dt1QQSB4QV0iP6BZ9/YB5fZaHFQ2dwHFrmPaRQ9GGMX01k9Q=="],
"home-assistant-js-websocket": ["home-assistant-js-websocket@9.5.0", "", {}, "sha512-gCBX0ulIPW3o5EhYxyNKgztBwNIs7u4hypZ+rcWir65wjLKL3b5uDx1jzU7RceyuANxvVKwBVLNujBeFohjnUw=="],
"typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
}
}

3794
entities.json Normal file

File diff suppressed because it is too large Load diff

25
index.ts Normal file
View file

@ -0,0 +1,25 @@
import {
Auth,
createConnection,
subscribeEntities,
createLongLivedTokenAuth,
} from "home-assistant-js-websocket";
const auth = createLongLivedTokenAuth(
"http://172.16.206.123:8123",
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5MGYyNDk3MDVkMTQ0ZTNjODQ0MDZlMWFkMjQ5NTgwZSIsImlhdCI6MTc0NzExNzM0NiwiZXhwIjoyMDYyNDc3MzQ2fQ.zbbyX-RsgtNV8TOIboc0Kk1YZvWMi5LQMwrf9rkv_SM",
);
const connection = await createConnection({ auth });
subscribeEntities(connection, (entities) => {
const fatherSleep = getTimeAsleep(parseFloat(entities["sensor.pixel_9_pro_xl_sleep_segment"]?.state || "0"));
});
const getTimeAsleep = (ms: number) => {
const minutes = ((ms / 1000 / 60) % 60);
const hours = ((ms / 1000 / 60 / 60) % 24);
return { minutes, hours };
};

15
package.json Normal file
View file

@ -0,0 +1,15 @@
{
"name": "abissinskiy",
"module": "index.ts",
"type": "module",
"private": true,
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"home-assistant-js-websocket": "^9.5.0"
}
}

28
tsconfig.json Normal file
View file

@ -0,0 +1,28 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}