129 lines
4.4 KiB
TypeScript
129 lines
4.4 KiB
TypeScript
import { LightHA, AutoHA, EventHA, ScriptHA, ButtonHA, HACore, SpeakerHA, TextHA } from "../src/index.ts";
|
|
|
|
import util from 'node:util';
|
|
import dotenv from 'dotenv';
|
|
dotenv.config();
|
|
export const showMore = (obj: any) => {
|
|
return util.inspect(obj, { depth: null, colors: true });
|
|
}
|
|
|
|
export const hacore = new HACore({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const light = new LightHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
|
|
export const auto = new AutoHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const event = new EventHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const script = new ScriptHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const button = new ButtonHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const speaker = new SpeakerHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
export const text = new TextHA({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL });
|
|
// const enti = await hacore.getEntities((item) => item.attributes?.friendly_name?.includes?.('电视'));
|
|
// console.log(showMore(enti), enti.length);
|
|
|
|
// const lightEntities = await hacore.getInfoList();
|
|
|
|
// console.log(showMore(lightEntities));
|
|
|
|
// const infoList = await hacore.getInfoList();
|
|
// console.log(showMore(infoList));
|
|
|
|
// const lights = [
|
|
// {
|
|
// entity_id: 'light.lemesh_wy0c14_f18d_light',
|
|
// state: 'off',
|
|
// attributes: {
|
|
// min_color_temp_kelvin: 2700,
|
|
// max_color_temp_kelvin: 6500,
|
|
// min_mireds: 153,
|
|
// max_mireds: 370,
|
|
// effect_list: [
|
|
// 'WY', 'Day',
|
|
// 'Night', 'Warmth',
|
|
// 'Tv', 'Reading',
|
|
// 'Computer', 'Hospitality',
|
|
// 'Entertainment', 'Wakeup',
|
|
// 'Dusk', 'Sleep'
|
|
// ],
|
|
// supported_color_modes: ['color_temp'],
|
|
// effect: null,
|
|
// color_mode: null,
|
|
// brightness: null,
|
|
// color_temp_kelvin: null,
|
|
// color_temp: null,
|
|
// hs_color: null,
|
|
// rgb_color: null,
|
|
// xy_color: null,
|
|
// 'light.mode': 0,
|
|
// 'light.on': false,
|
|
// 'light.color_temperature': 6500,
|
|
// 'light.brightness': 1,
|
|
// friendly_name: '次卧灯 灯光',
|
|
// supported_features: 4
|
|
// },
|
|
// last_changed: '2025-12-02T16:35:00.229216+00:00',
|
|
// last_reported: '2025-12-02T16:36:00.314622+00:00',
|
|
// last_updated: '2025-12-02T16:35:00.229216+00:00',
|
|
// context: {
|
|
// id: '01KBFYNN05ZYWZHTGC1W7N66Z5',
|
|
// parent_id: null,
|
|
// user_id: null
|
|
// }
|
|
// },
|
|
// {
|
|
// entity_id: 'light.lemesh_cn_1099991426_wy0c14_s_2_light',
|
|
// state: 'off',
|
|
// attributes: {
|
|
// min_color_temp_kelvin: 2700,
|
|
// max_color_temp_kelvin: 6500,
|
|
// min_mireds: 153,
|
|
// max_mireds: 370,
|
|
// effect_list: [
|
|
// '色温模式',
|
|
// '日光',
|
|
// '月光(夜间)模式',
|
|
// '温馨',
|
|
// '电视模式(影院模式)',
|
|
// '阅读模式',
|
|
// '电脑模式',
|
|
// '会客模式',
|
|
// '娱乐模式',
|
|
// '清晨唤醒',
|
|
// '黄昏明亮',
|
|
// '夜晚助眠'
|
|
// ],
|
|
// supported_color_modes: ['color_temp'],
|
|
// effect: null,
|
|
// color_mode: null,
|
|
// brightness: null,
|
|
// color_temp_kelvin: null,
|
|
// color_temp: null,
|
|
// hs_color: null,
|
|
// rgb_color: null,
|
|
// xy_color: null,
|
|
// friendly_name: '次卧灯 灯光',
|
|
// supported_features: 4
|
|
// },
|
|
// last_changed: '2025-12-04T13:28:05.284635+00:00',
|
|
// last_reported: '2025-12-04T13:28:09.331178+00:00',
|
|
// last_updated: '2025-12-04T13:28:05.284635+00:00',
|
|
// context: {
|
|
// id: '01KBMRRTX4ZE10MGHTVVNC1K7Y',
|
|
// parent_id: null,
|
|
// user_id: null
|
|
// }
|
|
// }
|
|
// ]
|
|
|
|
// const res = await hacore.runService({
|
|
// // name: '次卧灯',
|
|
// // service: 'turn_off'
|
|
// name: '阳台灯'
|
|
// });
|
|
// console.log(util.inspect(res, { depth: null }));
|
|
|
|
// const entityType = await hacore.getEntityTypes();
|
|
// console.log(showMore(entityType));
|
|
|
|
|
|
// const yinxiang = await hacore.getEntities((item) => item.attributes?.friendly_name?.includes?.('音箱'));
|
|
|
|
// console.log(showMore(yinxiang));
|