Skip to content

Commit

Permalink
Fix types package not working because i didn't understand typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
amberstarlight committed May 23, 2024
1 parent 0ae3d05 commit f81ee81
Show file tree
Hide file tree
Showing 9 changed files with 635 additions and 628 deletions.
1,016 changes: 508 additions & 508 deletions .pnp.cjs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
Expand All @@ -27,3 +28,8 @@ repos:
hooks:
- id: prettier
files: '\.(c?js.?|ts.?)$'

- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
hooks:
- id: gitleaks
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/api/routes/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express, { Request, Response, Router } from "express";
import { Zigbee2MqttService } from "../zigbee2mqttService";
import { ApiError } from "./api";
import { range } from "../utils";
import { Scene } from "../../types/zigbee_types";
import { Scene } from "@starlight/types";

const router = express.Router();

Expand Down
9 changes: 7 additions & 2 deletions packages/api/zigbee2mqttService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

import mqtt, { MqttClient, IClientOptions } from "mqtt";
import { logger } from "./logger";
import { BridgeResponse, Device, Group, Scene } from "../types/zigbee_types";
import {
type BridgeResponse,
type Device,
type Group,
type Scene,
type Feature,
} from "@starlight/types";
import { elementDiff, getByPath, quoteList } from "./utils";
import { Feature } from "../types/zigbee_features";

const SUCCESS: OperationStatus = { success: true };

Expand Down
111 changes: 106 additions & 5 deletions packages/types/zigbee_types.ts → packages/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// SPDX-FileCopyrightText: © 2023 Amber Cronin <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later

import { Feature } from "./zigbee_features";

export interface Device {
[index: string]: any;
ieee_address: string;
Expand Down Expand Up @@ -113,3 +108,109 @@ export interface BridgeResponse {
error?: string;
data: any;
}

export type Feature =
| BinaryFeature
| EnumFeature
| NumericFeature
| CompositeFeature
| ListFeature
| TextFeature
| LockStateEnumFeature
| LockFeature
| FanFeature
| CoverFeature
| SwitchFeature
| ClimateFeature;

interface BaseFeature {
access?: 1 | 2 | 5 | 7;
description?: string;
name: string;
type: string;
property?: string;
}

interface FeaturePreset {
description: string;
name: string;
value: number; // check this
}

/**
* Generic Features
*/

interface BinaryFeature extends BaseFeature {
type: "binary";
value_on: string | boolean;
value_off: string | boolean;
value_toggle?: string | boolean;
}

interface NumericFeature extends BaseFeature {
type: "numeric";
value_max?: number;
value_min?: number;
value_step?: number;
unit?: string;
presets?: FeaturePreset[];
}

interface EnumFeature extends BaseFeature {
type: "enum";
values: any[];
}

interface ListFeature extends BaseFeature {
type: "list";
length_min?: number;
length_max?: number;
item_type: Feature[];
}

interface TextFeature extends BaseFeature {
type: "text";
property: string;
}

interface CompositeFeature extends BaseFeature {
type: "composite";
property: string;
features: BinaryFeature[] | NumericFeature[] | EnumFeature[];
}

/**
* Specific Features
*/

interface LockFeature extends BaseFeature {
type: "lock";
features: LockStateEnumFeature[] | BinaryFeature[];
}

interface LockStateEnumFeature extends EnumFeature {
name: "lock_state";
property: "lock_state";
values: string[];
}

interface FanFeature extends BaseFeature {
type: "fan";
features: BinaryFeature[] | EnumFeature[];
}

interface CoverFeature extends BaseFeature {
type: "cover";
features: BinaryFeature[] | NumericFeature[];
}

interface SwitchFeature extends BaseFeature {
type: "switch";
features: BinaryFeature[];
}

interface ClimateFeature extends BaseFeature {
type: "climate";
features: Feature[]; // TODO https://www.zigbee2mqtt.io/guide/usage/exposes.html#climate
}
5 changes: 1 addition & 4 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "@starlight/types",
"packageManager": "[email protected]",
"private": true,
"workspaces": [
"packages/*"
]
"private": true
}
6 changes: 6 additions & 0 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"module": "node16"
},
"files": ["index.d.ts"]
}
108 changes: 0 additions & 108 deletions packages/types/zigbee_features.ts

This file was deleted.

0 comments on commit f81ee81

Please sign in to comment.