feat: initial zigbee control implementation
Some checks failed
Build and Publish Docker Image / build-and-push (push) Failing after 27s

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2025-10-28 01:11:57 +00:00
parent 2e63609129
commit b55d99dd9e
30 changed files with 901 additions and 70 deletions

34
packages/jrpc/.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

15
packages/jrpc/README.md Normal file
View File

@@ -0,0 +1,15 @@
# @eva/jrpc
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v1.3.1. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

49
packages/jrpc/index.ts Normal file
View File

@@ -0,0 +1,49 @@
import type { ZigbeeDeviceName, ZigbeeDeviceStates } from "@eva/zigbee"
export type JrpcSchema = {
subscribeToDevice: {
Params: {
deviceName: ZigbeeDeviceName
}
Response: true
}
setDeviceState: {
Params: {
deviceName: ZigbeeDeviceName
state: unknown
}
Response: true
}
showDeviceState: {
Params: {
[key in ZigbeeDeviceName]: {
deviceName: key
state: ZigbeeDeviceStates[key]
}
}[ZigbeeDeviceName]
Response: true
}
}
export type JrpcRequest<Method extends keyof JrpcSchema = keyof JrpcSchema> = {
[M in keyof JrpcSchema]: {
id: string
jsonrpc: "2.0"
method: M
params: JrpcSchema[M]["Params"]
}
}[Method]
export type JrpcResponse<Method extends keyof JrpcSchema = keyof JrpcSchema> = {
[M in keyof JrpcSchema]:
| {
id: string
jsonrpc: "2.0"
result: JrpcSchema[M]["Response"]
}
| {
id: string
jsonrpc: "2.0"
error: string
}
}[Method]

View File

@@ -0,0 +1,14 @@
{
"name": "@eva/jrpc",
"module": "index.ts",
"type": "module",
"dependencies": {
"@eva/zigbee": "workspace:*"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
}
}

View File

@@ -0,0 +1,29 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"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,
"noImplicitOverride": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}

34
packages/zigbee/.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

15
packages/zigbee/README.md Normal file
View File

@@ -0,0 +1,15 @@
# @eva/zigbee
To install dependencies:
```bash
bun install
```
To run:
```bash
bun run index.ts
```
This project was created using `bun init` in bun v1.3.1. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

31
packages/zigbee/index.ts Normal file
View File

@@ -0,0 +1,31 @@
export const ZIGBEE_BASE_TOPIC = "nexus"
export const ZIGBEE_DEVICE = {
deskLamp: "desk_lamp",
livingRoomFloorLamp: "living_room_floor_lamp",
} as const
export type ZigbeeDeviceName = (typeof ZIGBEE_DEVICE)[keyof typeof ZIGBEE_DEVICE]
export type ZigbeeDeviceStates = {
[ZIGBEE_DEVICE.deskLamp]: {
state: "ON" | "OFF"
brightness: number
}
[ZIGBEE_DEVICE.livingRoomFloorLamp]: {
brightness: number
level_config: {
on_level: "previous"
}
linkquality: number
state: "ON" | "OFF"
update: {
installed_version: number
latest_version: number
state: "available" | "idle"
}
}
}
export const ALL_ZIGBEE_DEVICE_NAMES: ZigbeeDeviceName[] = Object.values(ZIGBEE_DEVICE)
export type ZigbeeDeviceState = ZigbeeDeviceStates[keyof ZigbeeDeviceStates]

View File

@@ -0,0 +1,11 @@
{
"name": "@eva/zigbee",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5"
}
}

View File

@@ -0,0 +1,29 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "Preserve",
"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,
"noImplicitOverride": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}