Skip to content

Commit

Permalink
Implementing smart scenes and basic functionality for v2 api (#684)
Browse files Browse the repository at this point in the history
* working on smart scene and api v2 in general

* fix groups

* delete no longer existing smart scenes

* delete group too if last datapoint deleted

* add axios prod dep
  • Loading branch information
foxriver76 authored Jan 8, 2025
1 parent 983ceff commit 4c3b9d8
Show file tree
Hide file tree
Showing 10 changed files with 996 additions and 5,622 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ In den Adapter-Settings muss die IP der Hue Bridge sowie ein Username konfigurie
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->
### __WORK IN PROGRESS__
* (@foxriver76) added dynamic scenes (Note: new states are added by UUID)

### 3.13.1 (2024-10-16)
* (@foxriver76) correct min color temperature to 2000 (valid for color lights) instead of 2200

Expand Down
233 changes: 233 additions & 0 deletions build/lib/v2/v2-client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
export type ActivationState = 'active' | 'inactive';
export type SceneActivationState = 'activate' | 'deactivate';
export interface HueV2ClientProps {
/** User to authenticate at the API */
user: string;
/** IP address of the bridge */
address: string;
}
export interface HueResponseError {
/** Human-readable description of the error */
description: string;
}
export interface Response<T> {
/** Empty array if no errors present */
errors: HueResponseError[];
data: T[];
}
export interface BaseData {
/** The uuid of the device */
id: string;
/** The device id for Hue API v1 */
id_v1?: string;
/** Type of the data */
type: string;
}
export interface DeviceData extends BaseData {
/** Product data for this device */
product_data: DeviceProductData;
metadata: DeviceMetaData;
identify?: Record<string, unknown>;
usertest?: DeviceUserTest;
services: Resource[];
type: 'device';
}
export interface DeviceUserTest {
status: string;
usertest: boolean;
}
export interface DeviceProductData {
model_id: string;
manufacturer_name: string;
product_name: string;
product_archetype: string;
certified: boolean;
software_version: string;
hardware_platform_type?: string;
}
export interface Resource {
rid: string;
rtype: string;
}
export interface DeviceMetaData {
name: string;
archetype: string;
}
export interface SceneData extends BaseData {
actions: SceneAction[];
palette: ScenePalette;
recall: Record<string, unknown>;
metadata: SceneMetadata;
group: Resource;
speed: number;
auto_dynamic: boolean;
status: SceneStatus;
type: 'scene';
}
export interface SceneStatus {
active: ActivationState;
last_recall?: string;
}
export interface SceneMetadata {
name: string;
image?: Resource;
appdata?: string;
}
export interface ScenePalette {
color: unknown[];
dimming: unknown[];
color_temperature: unknown[];
effects: unknown[];
effects_v2: unknown[];
}
export interface SceneAction {
target: Resource;
action: Command;
}
export interface Command {
on: OnCommand;
dimming?: DimmingCommand;
color?: ColorCommand;
color_temperature?: ColorTemperatureCommand;
}
export interface ColorTemperatureCommand {
mirek: number;
}
export interface OnCommand {
on: boolean;
}
export interface DimmingCommand {
brightness: number;
}
export interface ColorCommand {
xy: XYValue;
}
export interface XYValue {
x: number;
y: number;
}
export interface BehaviorScriptData extends BaseData {
type: 'behavior_script';
description: string;
configuration_schema: BehaviorScriptReference;
trigger_schema: BehaviorScriptReference;
state_schema: BehaviorScriptReference;
version: string;
metadata: BehaviorScriptMetaData;
supported_features: unknown[];
max_number_instances?: number;
}
export interface BehaviorScriptMetaData {
name: string;
category: string;
}
export interface BehaviorScriptReference {
$ref?: string;
}
export interface SmartSceneData extends BaseData {
type: 'smart_scene';
metadata: SmartSceneMetaData;
group: Resource;
week_timeslots: SmartSceneWeekTimeslot[];
transition_duration: number;
active_timeslot: SmartSceneTimeslot;
state: ActivationState;
}
export interface SmartSceneWeekTimeslot {
timeslots: SmartSceneWeekTimeslotEntry[];
recurrence: string[];
}
export interface SmartSceneWeekTimeslotEntry {
start_time: SmartSceneStartTime;
target: Resource;
}
export interface SmartSceneStartTime {
kind: 'time';
time: SmartSceneTime;
}
export interface SmartSceneTime {
hour: number;
minute: number;
second: number;
}
export interface SmartSceneTimeslot {
timeslot_id: number;
weekday: string;
}
export interface SmartSceneMetaData {
name: string;
image: Resource;
}
export interface RoomData extends BaseData {
children: Resource[];
services: Resource[];
metadata: RoomMetaData;
type: 'room';
}
export interface RoomMetaData {
name: string;
archetype: string;
}
export interface ZoneData extends BaseData {
children: Resource[];
services: Resource[];
metadata: ZoneMetaData;
type: 'room';
}
export interface ZoneMetaData {
name: string;
archetype: string;
}
export declare class HueV2Client {
/** The user to authenticate at the API */
private readonly user;
/** Base address of the bridge */
private readonly baseUrl;
/** Axios client */
private restClient;
constructor(props: HueV2ClientProps);
/**
* Get all devices from bridge
*/
getDevices(): Promise<Response<DeviceData>>;
/**
* Get all existing scenes from the bridge
*/
getScenes(): Promise<Response<SceneData>>;
/**
* Get all behavior scripts from the Hue bridge
*/
getBehaviorScripts(): Promise<Response<BehaviorScriptData>>;
/**
* Get all smart scenes
*/
getSmartScenes(): Promise<Response<SmartSceneData>>;
/**
* Activate or deactivate a smart scene
* @param uuid uuid of the smart scene
* @param state the activation state
*/
private setSmartSceneState;
/**
* Start a smart scene
*
* @param uuid the UUID of the smart scene
*/
startSmartScene(uuid: string): Promise<Response<Resource>>;
/**
* Stop a smart scene
*
* @param uuid the UUID of the smart scene
*/
stopSmartScene(uuid: string): Promise<Response<Resource>>;
/**
* Get room for given uuid
* @param uuid uuid of the room
*/
getRoom(uuid: string): Promise<Response<RoomData>>;
/**
* Get zone for given uuid
* @param uuid uuid of the zone
*/
getZone(uuid: string): Promise<Response<ZoneData>>;
}
131 changes: 131 additions & 0 deletions build/lib/v2/v2-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/lib/v2/v2-client.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c3b9d8

Please sign in to comment.