import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import nock from 'nock'; import { DaikinBRP069 } from '../src/devices/brp069.js'; const BASE_URL = 'http://192.168.1.100'; describe('DaikinBRP069', () => { let device: DaikinBRP069; beforeEach(() => { nock.disableNetConnect(); device = new DaikinBRP069('192.168.1.100'); }); afterEach(() => { nock.cleanAll(); nock.enableNetConnect(); }); describe('constructor', () => { it('should set deviceIp from constructor', () => { expect(device.deviceIp).toBe('192.168.1.100'); }); it('should set baseUrl correctly', () => { expect(device.baseUrl).toBe('http://192.168.1.100'); }); }); describe('parseResponse', () => { it('should parse basic response', () => { const response = device.parseResponse('ret=OK,pow=1,mode=2'); expect(response.ret).toBe('OK'); expect(response.pow).toBe('1'); expect(response.mode).toBe('2'); }); it('should handle swing direction parsing', () => { const response = device.parseResponse('ret=OK,f_dir_ud=S,f_dir_lr=S'); expect(response.f_dir).toBe('3'); }); }); describe('getResource', () => { it('should fetch and parse resource', async () => { nock(BASE_URL) .get('/common/basic_info') .reply(200, 'ret=OK,pow=1,mode=2,mac=409F38D107AC'); const result = await device.getResource('common/basic_info'); expect(result.ret).toBe('OK'); expect(result.pow).toBe('1'); }); it('should return empty object on 404', async () => { nock(BASE_URL) .get('/notfound') .reply(404); const result = await device.getResource('notfound'); expect(result).toEqual({}); }); }); describe('values', () => { it('should have empty values initially', () => { expect(device.values.size).toBe(0); }); it('should set and get values', () => { device.values.set('mode', '2'); expect(device.values.get('mode')).toBe('2'); }); }); describe('temperature parsing', () => { it('should parse temperature values', () => { device.values.set('stemp', '25.0'); expect(device.targetTemperature).toBe(25.0); }); it('should return null for invalid temperature', () => { device.values.set('stemp', 'invalid'); expect(device.targetTemperature).toBeNull(); }); }); describe('support properties', () => { it('should report support for fan rate when present', () => { device.values.set('f_rate', 'A'); expect(device.supportFanRate).toBe(true); }); it('should report no fan rate support when absent', () => { expect(device.supportFanRate).toBe(false); }); it('should report support for swing mode when present', () => { device.values.set('f_dir', '0'); expect(device.supportSwingMode).toBe(true); }); it('should report no swing mode support when absent', () => { expect(device.supportSwingMode).toBe(false); }); }); });