941abd98d5
Dynamic MySolem/MyIndygo IoT bridge with MQTT, Home Assistant autodiscovery, and Homebridge EasyMQTT compatibility. - Device discovery via MySolem API on startup (all modules/inputs/outputs) - Configurable poll engine (fast/normal/slow buckets, per-input overrides) - MQTT retained state publishing + HA autodiscovery payloads - Unified manual command routing (linesControl vs sendManualModuleCommand) - Runtime config via MQTT $config/set, persisted to config.json - Expression override system (API-provided > hardcoded > passthrough) - Minimal REST API: /health, /state, /control, /rediscover - Docker deployment (Dockerfile + docker-compose.yml) - 38 unit tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
'use strict';
|
|
const state = require('../src/state');
|
|
|
|
describe('state', () => {
|
|
test('set and get round-trip', () => {
|
|
state.set('input-1', { value: 24.5, unit: '°C', moduleId: 'mod-a', moduleSlug: 'lrpc_abc', metric: 'temperature', timestamp: '2026-01-01T00:00:00Z' });
|
|
const entry = state.get('input-1');
|
|
expect(entry.value).toBe(24.5);
|
|
expect(entry.unit).toBe('°C');
|
|
});
|
|
|
|
test('getAll returns all entries', () => {
|
|
state.set('input-2', { value: 7.2, unit: 'pH', moduleId: 'mod-b', moduleSlug: 'lrps_xyz', metric: 'ph', timestamp: '2026-01-01T00:00:00Z' });
|
|
const all = state.getAll();
|
|
expect(all['input-1']).toBeDefined();
|
|
expect(all['input-2']).toBeDefined();
|
|
});
|
|
|
|
test('getByModule filters by moduleId', () => {
|
|
const byMod = state.getByModule('mod-a');
|
|
expect(Object.keys(byMod)).toContain('input-1');
|
|
expect(Object.keys(byMod)).not.toContain('input-2');
|
|
});
|
|
|
|
test('inputCount returns store size', () => {
|
|
expect(state.inputCount()).toBeGreaterThanOrEqual(2);
|
|
});
|
|
|
|
test('get returns null for unknown inputId', () => {
|
|
expect(state.get('does-not-exist')).toBeNull();
|
|
});
|
|
|
|
test('update event fires on set', done => {
|
|
state.on('update', (id, entry) => {
|
|
if (id === 'input-event-test') {
|
|
expect(entry.value).toBe(999);
|
|
done();
|
|
}
|
|
});
|
|
state.set('input-event-test', { value: 999, moduleId: 'x', moduleSlug: 's', metric: 'm', timestamp: '' });
|
|
});
|
|
});
|