Skip to content

Commit

Permalink
fix(config): remove deprecated bridge/config
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 1, 2024
1 parent ab18490 commit 121f835
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 76 deletions.
1 change: 0 additions & 1 deletion src/initialState.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"networkGraphIsLoading": false,
"groups": [],
"bridgeState": "online",
"bridgeConfig": {},
"bridgeDefinitions": {},
"bridgeInfo": {
"configSchema": {
Expand Down
2 changes: 0 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import createStore from 'unistore';
import {
BridgeConfig,
BridgeInfo,
BridgeState,
BridgeDefinitions,
Expand Down Expand Up @@ -65,7 +64,6 @@ export interface GlobalState extends WithDevices, WithDeviceStates, WithGroups,
touchlinkResetInProgress: boolean;
networkGraph: GraphI;
networkGraphIsLoading: boolean;
bridgeConfig: BridgeConfig;
bridgeState: BridgeState;
bridgeDefinitions: BridgeDefinitions;
logs: LogMessage[];
Expand Down
121 changes: 55 additions & 66 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { JSONSchema7 } from 'json-schema';
import {CustomClusters} from './zcl/definition/tstype'
import { CustomClusters } from './zcl/definition/tstype';

export type DeviceType = "EndDevice" | "Router" | "Coordinator";
export type DeviceType = 'EndDevice' | 'Router' | 'Coordinator';
export type FriendlyName = string;
export type IEEEEAddress = string;

export type OTAState = {
state: "available" | "updating";
state: 'available' | 'updating';
progress: number;
remaining: number;
}
};
export type RGBColor = {
r: number;
g: number;
b: number;
}
};
export type HueSaturationColor = {
hue: number;
saturation: number;
}
};

export type XYColor = {
x: number;
y: number;
}
};
export type AnyColor = RGBColor | XYColor | HueSaturationColor;
export type DeviceState = Record<string, unknown>;
export type Cluster = string | number;
Expand Down Expand Up @@ -56,8 +56,8 @@ export interface ClusterDefinition {
}

export interface BridgeDefinitions {
clusters: Readonly<Record<Cluster, Readonly<ClusterDefinition>>>,
custom_clusters: Readonly<Record<IEEEEAddress, Readonly<CustomClusters>>>,
clusters: Readonly<Record<Cluster, Readonly<ClusterDefinition>>>;
custom_clusters: Readonly<Record<IEEEEAddress, Readonly<CustomClusters>>>;
}

export interface Meta {
Expand Down Expand Up @@ -85,7 +85,6 @@ export interface AdvancedConfig {
elapsed: boolean;
last_seen: 'disable' | 'ISO_8601' | 'ISO_8601_local' | 'epoch';
legacy_api: boolean;

}
export interface Z2MConfig {
homeassistant: boolean;
Expand All @@ -94,25 +93,16 @@ export interface Z2MConfig {
device_options: DeviceConfig;
[k: string]: unknown;
}
export interface BridgeConfig {
version: string;
commit: string;
coordinator: Coordinator;
network: Network;
log_level: string;
permit_join: boolean;

}
export type BridgeState = "online" | "offline";
export type BridgeState = 'online' | 'offline';
export interface BridgeInfo {
config: Z2MConfig;
config_schema: JSONSchema7;
permit_join: boolean;
permit_join_timeout: number;
commit?: string;
version?: string;
zigbee_herdsman_converters: {version: string},
zigbee_herdsman: {version: string},
zigbee_herdsman_converters: { version: string };
zigbee_herdsman: { version: string };
coordinator?: {
meta?: {
revision?: string;
Expand All @@ -124,11 +114,10 @@ export interface BridgeInfo {
restart_required: boolean;
}

export type PowerSource = "Battery" | "Mains (single phase)" | "DC Source";

export type GenericFeatureType = "numeric" | "binary" | "enum" | "text" | "list";
export type CompositeFeatureType = "fan" | "light" | "switch" | "cover" | "lock" | "composite" | "climate";
export type PowerSource = 'Battery' | 'Mains (single phase)' | 'DC Source';

export type GenericFeatureType = 'numeric' | 'binary' | 'enum' | 'text' | 'list';
export type CompositeFeatureType = 'fan' | 'light' | 'switch' | 'cover' | 'lock' | 'composite' | 'climate';

export enum FeatureAccessMode {
NONE,
Expand All @@ -140,30 +129,30 @@ export interface GenericExposedFeature {
type: GenericFeatureType;
name: string;
label: string;
unit?: "string";
unit?: 'string';
access: FeatureAccessMode;
endpoint?: Endpoint;
property?: string;
description?: string;
}

export interface BinaryFeature extends GenericExposedFeature {
type: "binary";
type: 'binary';
value_on: unknown;
value_off: unknown;
value_toggle?: unknown;
}

export interface ListFeature extends GenericExposedFeature {
type: "list";
type: 'list';
// bad design decision
item_type: "number" | GenericOrCompositeFeature;
item_type: 'number' | GenericOrCompositeFeature;

length_min?: number;
length_max?: number;
}

export interface CompositeFeature extends Omit<GenericExposedFeature, "type"> {
export interface CompositeFeature extends Omit<GenericExposedFeature, 'type'> {
type: CompositeFeatureType;
features: GenericOrCompositeFeature[];
}
Expand All @@ -176,55 +165,55 @@ export interface NumericFeaturePreset {
description?: string;
}
export interface NumericFeature extends GenericExposedFeature {
type: "numeric";
type: 'numeric';
value_min?: number;
value_max?: number;
value_step?: number;
presets?: NumericFeaturePreset[];
}

export interface TextualFeature extends GenericExposedFeature {
type: "text";
type: 'text';
}

export interface EnumFeature extends GenericExposedFeature {
type: "enum";
type: 'enum';
values: unknown[];
}

export interface GradientFeature extends GenericExposedFeature {
type: "text";
name: "gradient";
type: 'text';
name: 'gradient';
length_min: number;
length_max: number;
}

export interface LightFeature extends CompositeFeature {
type: "light";
type: 'light';
}

export interface SwitchFeature extends CompositeFeature {
type: "switch";
type: 'switch';
}

export interface CoverFeature extends CompositeFeature {
type: "cover";
type: 'cover';
}

export interface LockFeature extends CompositeFeature {
type: "lock";
type: 'lock';
}
export interface FanFeature extends CompositeFeature {
type: "fan";
type: 'fan';
}

export interface ClimateFeature extends CompositeFeature {
type: "climate";
type: 'climate';
}

export interface ColorFeature extends CompositeFeature {
type: "composite";
name: "color_xy" | "color_hs";
type: 'composite';
name: 'color_xy' | 'color_hs';
features: NumericFeature[];
}

Expand Down Expand Up @@ -272,7 +261,7 @@ export type Scene = {
id: number;
name?: string;
endpoint?: Endpoint;
}
};
export interface Group extends WithFriendlyName, WithDescription, WithScenes {
id: number;
members: GroupAddress[];
Expand All @@ -294,42 +283,42 @@ export interface Device extends WithFriendlyName, WithDescription {
endpoints: Record<Endpoint, EndpointDescription>;
}

export type ObjectType = "device" | "group";
export type ObjectType = 'device' | 'group';
export interface BindRule {
cluster: Cluster;
target: {
id?: number;
endpoint?: Endpoint;
ieee_address?: IEEEEAddress;
type: "endpoint" | "group";
type: 'endpoint' | 'group';
};

}

export interface TouchLinkDevice {
ieee_address: IEEEEAddress;
channel: number;
}

export type LastSeenType = "disable" | "ISO_8601" | "ISO_8601_local" | "epoch";

export type KVP = Record<string, unknown>
export type LastSeenType = 'disable' | 'ISO_8601' | 'ISO_8601_local' | 'epoch';

export type KVP = Record<string, unknown>;

export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]]
export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];

export type Join<K, P> = K extends string | number ?
P extends string | number ?
`${K}${"" extends P ? "" : "."}${P}`
: never : never;


export type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ?
{ [K in keyof T]-?: K extends string | number ?
`${K}` | Join<K, Paths<T[K], Prev[D]>>
export type Join<K, P> = K extends string | number
? P extends string | number
? `${K}${'' extends P ? '' : '.'}${P}`
: never
}[keyof T] : ""

export type Leaves<T, D extends number = 10> = [D] extends [never] ? never : T extends object ?
{ [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T] : "";
: never;

export type Paths<T, D extends number = 10> = [D] extends [never]
? never
: T extends object
? { [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K], Prev[D]>> : never }[keyof T]
: '';

export type Leaves<T, D extends number = 10> = [D] extends [never]
? never
: T extends object
? { [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T]
: '';
8 changes: 1 addition & 7 deletions src/ws-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReconnectingWebSocket from 'reconnecting-websocket';
import store, { Base64String, Extension, LogMessage, OnlineOrOffline } from './store';
import { BridgeConfig, BridgeInfo, BridgeState, BridgeDefinitions, Device, DeviceState, Group, TouchLinkDevice } from './types';
import { BridgeInfo, BridgeState, BridgeDefinitions, Device, DeviceState, Group, TouchLinkDevice } from './types';
import {
debounceArgs,
isSecurePage,
Expand Down Expand Up @@ -155,12 +155,6 @@ class Api {

private processBridgeMessage = (data: Message): void => {
switch (data.topic) {
case "bridge/config":
store.setState({
bridgeConfig: data.payload as unknown as BridgeConfig
});
break;

case "bridge/info":
store.setState({
bridgeInfo: data.payload as unknown as BridgeInfo
Expand Down

0 comments on commit 121f835

Please sign in to comment.