-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing smart scenes and basic functionality for v2 api (#684)
* 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
1 parent
983ceff
commit 4c3b9d8
Showing
10 changed files
with
996 additions
and
5,622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.