Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Jan 20, 2025
1 parent 41b8e2e commit aafea2c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 91 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,22 @@ TBD
* (@Apollon77) Only exposes remaining battery percentage attribute when value is present
* (@Apollon77) Corrected error display and pushing to UI in case of initialization errors of bridged devices
* (@Apollon77) Added RSSI value also for Thread devices
* (@Apollon77) Optimized an fixed multiple things
* (@Apollon77) Optimized and fixed multiple things

### 0.3.7 (2025-01-15)
* (@GermanBluefox) Showed the device name in paring dialog
* (@GermanBluefox/Apollon77) Adjusts connection type icons
* (@Apollon77) Optimized the discovery dialog handling
* (@Apollon77) Fixed Thermostat for Controller to update temperatures
* (@Apollon77) Gives Energy sensors a dedicated icon
* (@Apollon77) Optimized an fixed multiple things
* (@Apollon77) Optimized and fixed multiple things

### 0.3.6 (2025-01-13)
* (@GermanBluefox) Fixed GUI errors
* (@GermanBluefox/@Apollon77) Added possibility to enable/disable controlled nodes
* (@Apollon77) Added Information on battery and rssi for DM tile
* (@Apollon77) Added controller support for Color Lights, Speaker, Thermostats and Window coverings
* (@Apollon77) Optimized an fixed multiple things
* (@Apollon77) Optimized and fixed multiple things

### 0.3.5 (2025-01-09)
* (@GermanBluefox) Fixed GUI errors
Expand Down
189 changes: 101 additions & 88 deletions test/devices.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ChannelDetectorImport = require('@iobroker/type-detector');
const Types = ChannelDetectorImport.Types;
const SubscribeManager = require('../build/lib/SubscribeManager');
const { SubscribeManager } = require('../build/lib/SubscribeManager');
const { StateAccessType } = require('../build/lib/devices/GenericDevice');
const ValueType = {
String: 'string',
Expand All @@ -21,31 +21,31 @@ const excludedTypes = [
// create a maximal set of states
const detectedDevices = {
states: [
{ name: 'SET', id: '0_userdata.0.set' },
{ name: 'ACTUAL', id: '0_userdata.0.actual' },
{ name: 'SET', id: '0_userdata.0.set', type: 'mixed' },
{ name: 'ACTUAL', id: '0_userdata.0.actual', type: 'mixed' },
{ name: 'POWER', id: '0_userdata.0.power', type: 'boolean' },
{ name: 'HUMIDITY', id: '0_userdata.0.humidity' },
{ name: 'SPEED', id: '0_userdata.0.speed' },
{ name: 'HUMIDITY', id: '0_userdata.0.humidity', type: 'number' },
{ name: 'SPEED', id: '0_userdata.0.speed', type: 'enum' },
{ name: 'BOOST', id: '0_userdata.0.boost', type: 'boolean' },
{ name: 'MODE', id: '0_userdata.0.mode' },
{ name: 'MODE', id: '0_userdata.0.mode', type: 'enum' },

{ name: 'SWING', id: '0_userdata.0.swing', type: 'boolean' },
{ name: 'STOP', id: '0_userdata.0.stop', type: 'boolean' },
{ name: 'OPEN', id: '0_userdata.0.open', type: 'boolean' },
{ name: 'CLOSE', id: '0_userdata.0.close', type: 'boolean' },
{ name: 'TILT_SET', id: '0_userdata.0.tilt_set' },
{ name: 'TILT_ACTUAL', id: '0_userdata.0.tilt_actual' },
{ name: 'TILT_SET', id: '0_userdata.0.tilt_set', type: 'number' },
{ name: 'TILT_ACTUAL', id: '0_userdata.0.tilt_actual', type: 'number' },
{ name: 'TILT_STOP', id: '0_userdata.0.tilt_stop', type: 'boolean' },
{ name: 'TILT_OPEN', id: '0_userdata.0.tilt_open', type: 'boolean' },
{ name: 'TILT_CLOSE', id: '0_userdata.0.tilt_close', type: 'boolean' },

{ name: 'PRESS', id: '0_userdata.0.press', type: 'boolean' },
{ name: 'PRESS_LONG', id: '0_userdata.0.press_long', type: 'boolean' },

{ name: 'FILE', id: '0_userdata.0.file' },
{ name: 'FILE', id: '0_userdata.0.file', type: 'string' },
{ name: 'AUTOFOCUS', id: '0_userdata.0.autofocus', type: 'boolean' },
{ name: 'AUTOWHITEBALANCE', id: '0_userdata.0.autowhiteballance', type: 'boolean' },
{ name: 'BRIGHTNESS', id: '0_userdata.0.brightness' },
{ name: 'BRIGHTNESS', id: '0_userdata.0.brightness', type: 'number' },
{ name: 'NIGHTMODE', id: '0_userdata.0.nightmode', type: 'boolean' },
{ name: 'PTZ', id: '0_userdata.0.ptz', type: 'boolean' },

Expand All @@ -55,19 +55,19 @@ const detectedDevices = {
{ name: 'ON', id: '0_userdata.0.on', type: 'boolean' },
{ name: 'ON_ACTUAL', id: '0_userdata.0.on_actual', type: 'boolean' },

{ name: 'ELECTRIC_POWER', id: '0_userdata.0.electric_power' },
{ name: 'CURRENT', id: '0_userdata.0.current' },
{ name: 'VOLTAGE', id: '0_userdata.0.voltage' },
{ name: 'CONSUMPTION', id: '0_userdata.0.consumption' },
{ name: 'FREQUENCY', id: '0_userdata.0.frequency' },
{ name: 'ELECTRIC_POWER', id: '0_userdata.0.electric_power', type: 'number' },
{ name: 'CURRENT', id: '0_userdata.0.current', type: 'number' },
{ name: 'VOLTAGE', id: '0_userdata.0.voltage', type: 'number' },
{ name: 'CONSUMPTION', id: '0_userdata.0.consumption', type: 'number' },
{ name: 'FREQUENCY', id: '0_userdata.0.frequency', type: 'number' },

{ name: 'LONGITUDE', id: '0_userdata.0.LONGITUDE' },
{ name: 'LATITUDE', id: '0_userdata.0.LATITUDE' },
{ name: 'ELEVATION', id: '0_userdata.0.ELEVATION' },
{ name: 'RADIUS', id: '0_userdata.0.RADIUS' },
{ name: 'ACCURACY', id: '0_userdata.0.ACCURACY' },
{ name: 'LONGITUDE', id: '0_userdata.0.LONGITUDE', type: 'number' },
{ name: 'LATITUDE', id: '0_userdata.0.LATITUDE', type: 'number' },
{ name: 'ELEVATION', id: '0_userdata.0.ELEVATION', type: 'number' },
{ name: 'RADIUS', id: '0_userdata.0.RADIUS', type: 'number' },
{ name: 'ACCURACY', id: '0_userdata.0.ACCURACY', type: 'number' },

{ name: 'STATE', id: '0_userdata.0.STATE.state' },
{ name: 'STATE', id: '0_userdata.0.STATE.state', type: 'enum' },
{ name: 'PLAY', id: '0_userdata.0.PLAY.play', type: 'boolean' },
{ name: 'PAUSE', id: '0_userdata.0.PAUSE', type: 'boolean' },
{ name: 'STOP', id: '0_userdata.0.STOP', type: 'boolean' },
Expand All @@ -79,23 +79,23 @@ const detectedDevices = {
{ name: 'ALBUM', id: '0_userdata.0.ALBUM' },
{ name: 'TITLE', id: '0_userdata.0.TITLE' },
{ name: 'COVER', id: '0_userdata.0.COVER' },
{ name: 'DURATION', id: '0_userdata.0.DURATION' },
{ name: 'DURATION', id: '0_userdata.0.DURATION', type: 'number' },
{ name: 'ELAPSED', id: '0_userdata.0.ELAPSED' },
{ name: 'SEEK', id: '0_userdata.0.SEEK' },
{ name: 'TRACK', id: '0_userdata.0.TRACK' },
{ name: 'EPISODE', id: '0_userdata.0.EPISODE' },
{ name: 'SEASON', id: '0_userdata.0.SEASON' },
{ name: 'VOLUME', id: '0_userdata.0.VOLUME' },
{ name: 'VOLUME_ACTUAL', id: '0_userdata.0.VOLUME_ACTUAL' },
{ name: 'VOLUME', id: '0_userdata.0.VOLUME', type: 'number' },
{ name: 'VOLUME_ACTUAL', id: '0_userdata.0.VOLUME_ACTUAL', type: 'number' },
{ name: 'MUTE', id: '0_userdata.0.MUTE' },
{ name: 'CONNECTED', id: '0_userdata.0.CONNECTED' },

{ name: 'MAP_BASE64', id: '0_userdata.0.MAP_BASE64' },
{ name: 'MAP_URL', id: '0_userdata.0.MAP_URL' },
{ name: 'WORK_MODE', id: '0_userdata.0.WORK_MODE' },
{ name: 'WORK_MODE', id: '0_userdata.0.WORK_MODE', type: 'enum' },
{ name: 'WATER', id: '0_userdata.0.WATER' },
{ name: 'WASTE', id: '0_userdata.0.WASTE' },
{ name: 'BATTERY', id: '0_userdata.0.BATTERY' },
{ name: 'BATTERY', id: '0_userdata.0.BATTERY', type:'number' },
{ name: 'STATE', id: '0_userdata.0.STATE' },
{ name: 'PAUSE', id: '0_userdata.0.PAUSE' },
{ name: 'WASTE_ALARM', id: '0_userdata.0.WASTE_ALARM' },
Expand All @@ -113,65 +113,64 @@ const detectedDevices = {
{ name: 'DESC', id: '0_userdata.0.DESC' },

{ name: 'ICON', id: '0_userdata.0.ICON' },
{ name: 'PRECIPITATION_CHANCE', id: '0_userdata.0.PRECIPITATION_CHANCE' },
{ name: 'PRECIPITATION_CHANCE', id: '0_userdata.0.PRECIPITATION_CHANCE', type: 'number' },
{ name: 'PRECIPITATION_TYPE', id: '0_userdata.0.PRECIPITATION_TYPE' },
{ name: 'PRESSURE', id: '0_userdata.0.PRESSURE' },
{ name: 'PRESSURE_TENDENCY', id: '0_userdata.0.PRESSURE_TENDENCY' },
{ name: 'REAL_FEEL_TEMPERATURE', id: '0_userdata.0.REAL_FEEL_TEMPERATURE' },
{ name: 'HUMIDITY', id: '0_userdata.0.HUMIDITY' },
{ name: 'UV', id: '0_userdata.0.UV' },
{ name: 'PRESSURE', id: '0_userdata.0.PRESSURE', type: 'number' },
{ name: 'PRESSURE_TENDENCY', id: '0_userdata.0.PRESSURE_TENDENCY', type: 'number' },
{ name: 'REAL_FEEL_TEMPERATURE', id: '0_userdata.0.REAL_FEEL_TEMPERATURE', type: 'number' },
{ name: 'HUMIDITY', id: '0_userdata.0.HUMIDITY', type: 'number' },
{ name: 'UV', id: '0_userdata.0.UV', type: 'number' },
{ name: 'WEATHER', id: '0_userdata.0.WEATHER' },
{ name: 'WIND_DIRECTION', id: '0_userdata.0.WIND_DIRECTION' },
{ name: 'WIND_GUST', id: '0_userdata.0.WIND_GUST' },
{ name: 'WIND_SPEED', id: '0_userdata.0.WIND_SPEED' },
{ name: 'WIND_DIRECTION', id: '0_userdata.0.WIND_DIRECTION', type: 'number' },
{ name: 'WIND_GUST', id: '0_userdata.0.WIND_GUST', type: 'number' },
{ name: 'WIND_SPEED', id: '0_userdata.0.WIND_SPEED', type: 'number' },

{ name: 'TEMP_MIN', id: '0_userdata.0.TEMP_MIN' },
{ name: 'TEMP_MAX', id: '0_userdata.0.TEMP_MAX' },
{ name: 'TEMP_MIN', id: '0_userdata.0.TEMP_MIN', type: 'number' },
{ name: 'TEMP_MAX', id: '0_userdata.0.TEMP_MAX', type: 'number' },
{ name: 'DATE', id: '0_userdata.0.DATE' },
{ name: 'DOW', id: '0_userdata.0.DOW' },
{ name: 'TEMP', id: '0_userdata.0.TEMP' },
{ name: 'PRESSURE', id: '0_userdata.0.PRESSURE' },
{ name: 'HUMIDITY', id: '0_userdata.0.HUMIDITY' },
{ name: 'DOW', id: '0_userdata.0.DOW', type: 'number' },
{ name: 'TEMP', id: '0_userdata.0.TEMP', type: 'number' },
{ name: 'PRESSURE', id: '0_userdata.0.PRESSURE', type: 'number' },
{ name: 'HUMIDITY', id: '0_userdata.0.HUMIDITY', type: 'number' },
{ name: 'TIME_SUNRISE', id: '0_userdata.0.TIME_SUNRISE' },
{ name: 'TIME_SUNSET', id: '0_userdata.0.TIME_SUNSET' },
{ name: 'WIND_CHILL', id: '0_userdata.0.WIND_CHILL' },
{ name: 'FEELS_LIKE', id: '0_userdata.0.FEELS_LIKE' },
{ name: 'WIND_SPEED', id: '0_userdata.0.WIND_SPEED' },
{ name: 'WIND_DIRECTION', id: '0_userdata.0.WIND_DIRECTION' },
{ name: 'WIND_DIRECTION_STR', id: '0_userdata.0.WIND_DIRECTION_STR' },
{ name: 'WIND_ICON', id: '0_userdata.0.WIND_ICON' },
{ name: 'WIND_CHILL', id: '0_userdata.0.WIND_CHILL', type: 'number' },
{ name: 'FEELS_LIKE', id: '0_userdata.0.FEELS_LIKE', type: 'number' },
{ name: 'WIND_SPEED', id: '0_userdata.0.WIND_SPEED', type: 'number' },
{ name: 'WIND_DIRECTION', id: '0_userdata.0.WIND_DIRECTION', type: 'number' },
{ name: 'WIND_DIRECTION_STR', id: '0_userdata.0.WIND_DIRECTION_STR', type: 'string' },
{ name: 'WIND_ICON', id: '0_userdata.0.WIND_ICON', type: 'string' },
{ name: 'HISTORY_CHART', id: '0_userdata.0.HISTORY_CHART' },
{ name: 'FORECAST_CHART', id: '0_userdata.0.FORECAST_CHART' },
{ name: 'PRECIPITATION', id: '0_userdata.0.PRECIPITATION' },
{ name: 'PRECIPITATION', id: '0_userdata.0.PRECIPITATION' },

{ name: 'SECOND', id: '0_userdata.0.secondary' },

{ name: 'PARTY', id: '0_userdata.0.party' },

{ name: 'RED', id: '0_userdata.0.RED' },
{ name: 'GREEN', id: '0_userdata.0.GREEN' },
{ name: 'BLUE', id: '0_userdata.0.BLUE' },
{ name: 'WHITE', id: '0_userdata.0.WHITE' },
{ name: 'RGB', id: '0_userdata.0.RGB' },
{ name: 'RGBW', id: '0_userdata.0.RGBW' },
{ name: 'HUE', id: '0_userdata.0.HUE' },
{ name: 'CIE', id: '0_userdata.0.CIE' },

{ name: 'DIMMER', id: '0_userdata.0.dimmer' },
{ name: 'BRIGHTNESS', id: '0_userdata.0.brightness' },
{ name: 'SATURATION', id: '0_userdata.0.saturation' },
{ name: 'TEMPERATURE', id: '0_userdata.0.temperature' },
{ name: 'TRANSITION_TIME', id: '0_userdata.0.TRANSITIONTIME' },

{ name: 'LEVEL', id: '0_userdata.0.level' },

{ name: 'ERROR', id: '0_userdata.0.error' },
{ name: 'MAINTAIN', id: '0_userdata.0.maintain' },
{ name: 'UNREACH', id: '0_userdata.0.unreach' },
{ name: 'LOWBAT', id: '0_userdata.0.lowbat' },
{ name: 'WORKING', id: '0_userdata.0.working' },
{ name: 'DIRECTION', id: '0_userdata.0.direction' },
{ name: 'RED', id: '0_userdata.0.RED', type: 'number' },
{ name: 'GREEN', id: '0_userdata.0.GREEN', type: 'number' },
{ name: 'BLUE', id: '0_userdata.0.BLUE', type: 'number' },
{ name: 'WHITE', id: '0_userdata.0.WHITE', type: 'number' },
{ name: 'RGB', id: '0_userdata.0.RGB', type: 'string' },
{ name: 'RGBW', id: '0_userdata.0.RGBW', type: 'string' },
{ name: 'HUE', id: '0_userdata.0.HUE', type: 'number' },
{ name: 'CIE', id: '0_userdata.0.CIE', type: 'string' },

{ name: 'DIMMER', id: '0_userdata.0.dimmer', type: 'number' },
{ name: 'BRIGHTNESS', id: '0_userdata.0.brightness', type: 'number' },
{ name: 'SATURATION', id: '0_userdata.0.saturation', type: 'number' },
{ name: 'TEMPERATURE', id: '0_userdata.0.temperature', type: 'number' },
{ name: 'TRANSITION_TIME', id: '0_userdata.0.TRANSITIONTIME', type: 'number' },

{ name: 'LEVEL', id: '0_userdata.0.level', type: 'number' },

{ name: 'ERROR', id: '0_userdata.0.error', type: 'boolean' },
{ name: 'MAINTAIN', id: '0_userdata.0.maintain', type: 'boolean' },
{ name: 'UNREACH', id: '0_userdata.0.unreach', type: 'boolean' },
{ name: 'LOWBAT', id: '0_userdata.0.lowbat', type: 'boolean' },
{ name: 'WORKING', id: '0_userdata.0.working', type: 'boolean' },
{ name: 'DIRECTION', id: '0_userdata.0.direction', type: 'boolean' },
],
type: 'abstract',
};
Expand Down Expand Up @@ -211,6 +210,7 @@ class Adapter {
max: 200,
unit: '°C',
type: 'number',
states: entry.type === 'enum' ? { 0: 'Dummy' } : entry.type === 'mixed' ? { null: 'Dummy' } : undefined,
},
type: 'state',
};
Expand All @@ -235,6 +235,14 @@ class Adapter {
const entry = detectedDevices.states.find(state => state.id === id);
if (entry && entry.val !== undefined) {
this.states[id] = { ts: Date.now(), val: entry.val, ack: true };
} else if (entry.type === 'enum') {
this.states[id] = { ts: Date.now(), val: 0, ack: true };
} else if (entry.type === 'number') {
this.states[id] = { ts: Date.now(), val: 1, ack: true };
} else if (entry.type === 'boolean') {
this.states[id] = { ts: Date.now(), val: true, ack: true };
} else if (entry.type === 'string') {
this.states[id] = { ts: Date.now(), val: 'test', ack: true };
} else {
this.states[id] = { ts: Date.now(), val: null, ack: true };
}
Expand Down Expand Up @@ -278,14 +286,15 @@ describe('Test Devices', function () {
for (const type of types) {
// detect that only read values are subscribed
console.log(`------------------------\nCreated device for ${type}`);
const Device = require(`../build/lib/devices/${type[0].toUpperCase() + type.substring(1)}`);
const className = type[0].toUpperCase() + type.substring(1);
const Device = require(`../build/lib/devices/${className}`)[className];
const adapter = new Adapter();
SubscribeManager.default.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager.default);
SubscribeManager.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager);
detectedDevices.type = type;
detectedDevices.isIoBrokerDevice = true;

const deviceObj = new Device.default(detectedDevices, adapter, { enabled: true });
const deviceObj = new Device(detectedDevices, adapter, { enabled: true });
await deviceObj.init();

const properties = deviceObj.getProperties();
Expand Down Expand Up @@ -336,7 +345,11 @@ describe('Test Devices', function () {
) {
// Try to read value
if (deviceObj.getPropertyValue(prop) === undefined) {
throw new Error(`Property "${prop}" of "${type}" has no value`);
throw new Error(`Property "${prop}" (${properties[prop].valueType}) of "${type}" has no value`);
} else if (properties[prop].valueType === ValueType.Enum) {
if (deviceObj.getPropertyValue(prop) !== 'Dummy') {
throw new Error(`Property "${prop}" (Enum) of "${type}" has wrong value`);
}
}
}
if (properties[prop].accessType === StateAccessType.Write) {
Expand Down Expand Up @@ -404,13 +417,13 @@ describe('Test Devices', function () {
}).timeout(50000);

it('Test min/max - negative', async function () {
const Device = require(`../build/lib/devices/Thermostat`);
const Device = require(`../build/lib/devices/Thermostat`).Thermostat;
const adapter = new Adapter();
SubscribeManager.default.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager.default);
SubscribeManager.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager);
detectedDevices.type = 'thermostat';

const deviceObj = new Device.default(detectedDevices, adapter, { enabled: true });
const deviceObj = new Device(detectedDevices, adapter, { enabled: true });
await deviceObj.init();

const properties = deviceObj.getProperties();
Expand All @@ -433,17 +446,17 @@ describe('Test Devices', function () {
}).timeout(2000);

it('Test min/max - positive, readId=writeId', async function () {
const Device = require(`../build/lib/devices/Slider`);
const Device = require(`../build/lib/devices/Slider`).Slider;
const adapter = new Adapter();
SubscribeManager.default.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager.default);
SubscribeManager.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager);
const _detectedDevices = {
states: [{ name: 'SET', id: '0_userdata.0.set' }],
type: 'slider',
isIoBrokerDevice: true,
};

const deviceObj = new Device.default(_detectedDevices, adapter, { enabled: true });
const deviceObj = new Device(_detectedDevices, adapter, { enabled: true });
await deviceObj.init();

const properties = deviceObj.getProperties();
Expand All @@ -468,10 +481,10 @@ describe('Test Devices', function () {
}).timeout(2000);

it('Test min/max - positive, readId!=writeId', async function () {
const Device = require(`../build/lib/devices/Slider`);
const Device = require(`../build/lib/devices/Slider`).Slider;
const adapter = new Adapter();
SubscribeManager.default.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager.default);
SubscribeManager.setAdapter(adapter);
adapter.setSubscribeManager(SubscribeManager);
const _detectedDevices = {
states: [
{ name: 'SET', id: '0_userdata.0.set' },
Expand All @@ -481,7 +494,7 @@ describe('Test Devices', function () {
isIoBrokerDevice: true,
};

const deviceObj = new Device.default(_detectedDevices, adapter, { enabled: true });
const deviceObj = new Device(_detectedDevices, adapter, { enabled: true });
await deviceObj.init();

const properties = deviceObj.getProperties();
Expand Down

0 comments on commit aafea2c

Please sign in to comment.