import { HACore } from "../src/core"; import util from 'node:util'; import dotenv from 'dotenv'; dotenv.config(); const hacore = new HACore({ token: process.env.HAAS_TOKEN || '', homeassistantURL: process.env.HAAS_URL }); const enti = await hacore.get({ url: '/api/states' }); // console.log(util.inspect(enti, { depth: null })); // const lightEntities = enti.filter((entity: any) => { // const hasLight = entity.entity_id.startsWith('light.'); // const name = entity.attributes?.friendly_name || ''; // return hasLight && name.includes('次卧'); // }); // console.log(util.inspect(lightEntities, { depth: null })); 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.post({ url: '/api/services/light/turn_off', body: { entity_id: 'light.lemesh_cn_1099991426_wy0c14_s_2_light' // 或第二个次卧灯的ID } }); console.log(util.inspect(res, { depth: null }));