UNPKG

@homebridge-plugins/homebridge-resideo

Version:

The Resideo plugin allows you to access your Resideo device(s) from HomeKit.

88 lines 4.05 kB
import { describe, expect, it, vi } from 'vitest'; import { createPlatformProxy, toCelsius, toCelsiusWithOverride } from './utils.js'; describe('toCelsius', () => { it('should return the same value if the unit is 0 (Celsius)', () => { expect(toCelsius(25, 0)).toBe(25); }); it('should convert Fahrenheit to Celsius correctly', () => { expect(toCelsius(32, 1)).toBe(0); // 32°F is 0°C expect(toCelsius(68, 1)).toBe(20); // 68°F is 20°C expect(toCelsius(100, 1)).toBe(38); // 100°F rounds to 38°C }); it('should round to the nearest 0.5 degree', () => { expect(toCelsius(33, 1)).toBe(0.5); // 33°F is 0.5°C expect(toCelsius(34, 1)).toBe(1); // 34°F is 1°C }); }); describe('toCelsiusWithOverride', () => { it('should keep default conversion when no override is set', () => { expect(toCelsiusWithOverride(25, 0)).toBe(25); expect(toCelsiusWithOverride(68, 1)).toBe(20); }); it('should force Fahrenheit conversion when configured', () => { expect(toCelsiusWithOverride(68, 0, 'fahrenheit')).toBe(20); expect(toCelsiusWithOverride(75, 0, 'fahrenheit')).toBe(24); }); it('should force Celsius passthrough when configured', () => { expect(toCelsiusWithOverride(20, 1, 'celsius')).toBe(20); expect(toCelsiusWithOverride(25, 0, 'celsius')).toBe(25); }); }); describe('createPlatformProxy', () => { it('should instantiate HAPPlatform when Matter is not available', () => { const HAPPlatform = vi.fn(); const MatterPlatform = vi.fn(); const api = { isMatterAvailable: vi.fn().mockReturnValue(false), isMatterEnabled: vi.fn().mockReturnValue(false), }; const Proxy = createPlatformProxy(HAPPlatform, MatterPlatform); // eslint-disable-next-line no-new new Proxy({}, {}, api); expect(HAPPlatform).toHaveBeenCalledTimes(1); expect(MatterPlatform).not.toHaveBeenCalled(); }); it('should instantiate MatterPlatform when Matter is available and enabled', () => { const HAPPlatform = vi.fn(); const MatterPlatform = vi.fn(); const api = { isMatterAvailable: vi.fn().mockReturnValue(true), isMatterEnabled: vi.fn().mockReturnValue(true), }; const config = { options: { preferMatter: true, enableMatter: true } }; const Proxy = createPlatformProxy(HAPPlatform, MatterPlatform); // eslint-disable-next-line no-new new Proxy({}, config, api); expect(MatterPlatform).toHaveBeenCalledTimes(1); expect(HAPPlatform).not.toHaveBeenCalled(); }); it('should fall back to HAPPlatform when enableMatter is false', () => { const HAPPlatform = vi.fn(); const MatterPlatform = vi.fn(); const api = { isMatterAvailable: vi.fn().mockReturnValue(true), isMatterEnabled: vi.fn().mockReturnValue(true), }; const config = { options: { preferMatter: true, enableMatter: false } }; const Proxy = createPlatformProxy(HAPPlatform, MatterPlatform); // eslint-disable-next-line no-new new Proxy({}, config, api); expect(HAPPlatform).toHaveBeenCalledTimes(1); expect(MatterPlatform).not.toHaveBeenCalled(); }); it('should fall back to HAPPlatform when preferMatter is false', () => { const HAPPlatform = vi.fn(); const MatterPlatform = vi.fn(); const api = { isMatterAvailable: vi.fn().mockReturnValue(true), isMatterEnabled: vi.fn().mockReturnValue(true), }; const config = { options: { preferMatter: false, enableMatter: true } }; const Proxy = createPlatformProxy(HAPPlatform, MatterPlatform); // eslint-disable-next-line no-new new Proxy({}, config, api); expect(HAPPlatform).toHaveBeenCalledTimes(1); expect(MatterPlatform).not.toHaveBeenCalled(); }); }); //# sourceMappingURL=utils.test.js.map