Skip to content

Commit

Permalink
Added Details
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbs96 committed Dec 8, 2021
1 parent 5b22687 commit c200fd6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The following States are available:
| `ledColor` | :heavy_check_mark: | Color of LEDs, HSV/RGB(W)/HEX |
| `ledConfig` | :heavy_check_mark: | Configuration of LEDs |
| `ledEffect` | :heavy_check_mark: | Effects (`Effect`) |
| `ledLayout` | :heavy_check_mark: | Layout of LEDs |
| `ledLayout` | :heavy_check_mark: | Layout of LEDs (disabled for further testing) |
| `ledMode` | :heavy_check_mark: | Mode: On, Color, Effect, Playlist, Off, RealTime (not yet supported), Demo |
| `ledMovie` | :heavy_check_mark: | Active Movie, If multiple Movies are added in the Playlist feature then they can be selected here. (`On`) |
| `ledPlaylist` | :heavy_check_mark: | Active Playlist Entry, Switch between Movies. (`Playlist`) |
Expand All @@ -67,7 +67,7 @@ The following States are available:

## Changelog

### 0.2.5 (2021-12-06)
### 0.2.5 (2021-12-08)
* (patrickbs96) Renamed States with led control. Now starting with "led".
* (patrickbs96) Add new State `ledLayout`/`ledPlaylist`

Expand Down
12 changes: 12 additions & 0 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
"name": "twinkly",
"version": "0.2.5",
"news": {
"0.2.5": {
"en": "Add Playlist Feature. Renamed Datapoints",
"de": "Playlist-Funktion hinzufügen. Umbenannte Datenpunkte",
"ru": "Добавить функцию списка воспроизведения. Переименованные точки данных",
"pt": "Adicionar recurso de lista de reprodução. Pontos de dados renomeados",
"nl": "Voeg afspeellijstfunctie toe. Hernoemde datapunten",
"fr": "Ajouter une fonctionnalité de liste de lecture. Points de données renommés",
"it": "Aggiungi funzione playlist. Punti dati rinominati",
"es": "Agregar función de lista de reproducción. Puntos de datos renombrados",
"pl": "Dodaj funkcję listy odtwarzania. Zmienione nazwy punktów danych",
"zh-cn": "添加播放列表功能。重命名的数据点"
},
"0.2.4": {
"en": "Handle wrong input so it does not cause exceptions",
"de": "Behandeln Sie falsche Eingaben, damit keine Ausnahmen auftreten",
Expand Down
10 changes: 9 additions & 1 deletion lib/twinkly.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,19 @@ class Twinkly {
* @return {Promise<void>}
*/
async interview() {
if (this.firmware === '') {
try {
await this.getFirmwareVersion();
} catch (e) {
this.adapter.log.error(`[${this.name}.interview.fw] ${e}`);
}
}

if (Object.keys(this.details).length === 0) {
try {
await this.getDeviceDetails();
} catch (e) {
this.adapter.log.error(`[${this.name}.interview] ${e}`);
this.adapter.log.error(`[${this.name}.interview.details] ${e}`);
}
}
}
Expand Down
66 changes: 49 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ const stateNames = {
measured_frame_rate : {id: 'measuredFrameRate', name: 'Measured Frame Rate', type: 'number'},
movie_capacity : {id: 'movieCapacity', name: 'Movie Capacity', type: 'number'},
number_of_led : {id: 'numberOfLed', name: 'Number of LED', type: 'number'},
production_site : {id: 'productionSite', name: 'Production site', type: 'number', newSince: '2.8.3'},
production_date : {id: 'productionDate', name: 'Production Date', type: 'number', role: 'value.time', newSince: '2.8.3'},
product_name : {id: 'productName', name: 'Product Name'},
product_version : {id: 'productVersion', name: 'Product Version'},
product_code : {id: 'productCode', name: 'Product Code'},
rssi : {id: 'rssi', name: 'RSSI', type: 'number'},
uptime : {id: 'uptime', name: 'Uptime'},
uuid : {id: 'uuid', name: 'UUID'},
wire_type : {id: 'wireType', name: 'Wire Type', type: 'number'}
wire_type : {id: 'wireType', name: 'Wire Type', type: 'number'},

group : {
parent : {id: 'group', name: 'Group', newSince: '2.8.3'},
subIDs : {
mode : {id: 'mode', name: 'Name'},
compat_mode: {id: 'compatMode', name: 'Compat Mode', type: 'number'}
},
expandJSON: false
}
},
expandJSON: true
},
Expand Down Expand Up @@ -245,7 +256,7 @@ const statesConfig = [
stateNames.ledColor.parent.id,
// stateNames.ledConfig.id,
stateNames.ledEffect.id,
stateNames.ledLayout.parent.id,
// stateNames.ledLayout.parent.id, Prüfen, weshalb es nicht klappt
stateNames.ledMode.parent.id,
stateNames.ledMovie.id,
stateNames.ledSat.id,
Expand Down Expand Up @@ -1059,8 +1070,7 @@ async function prepareObjectsByConfig() {
exclude : []
};

if (states[state].hide === undefined || !states[state].hide) {

if (!states[state].hide) {
if (states[state].parent !== undefined) {
if (states[state].subIDs !== undefined && states[state].expandJSON) {
// Soll der Parent angezeigt werden
Expand All @@ -1082,8 +1092,12 @@ async function prepareObjectsByConfig() {
}
} else {
let canAddState = true;
if (states[state].filter !== undefined && connections[config.device.id.device].connected)
canAddState = await connections[config.device.id.device].twinkly.checkDetailInfo(states[state].filter);
if (connections[config.device.id.device].connected) {
if (canAddState && states[state].filter !== undefined)
canAddState = await connections[config.device.id.device].twinkly.checkDetailInfo(states[state].filter);
if (canAddState && states[state].newSince !== undefined)
canAddState = tools.versionGreaterEqual(states[state].newSince, connections[config.device.id.device].twinkly.firmware);
}

if (canAddState) {
stateObj.id.state = states[state].id;
Expand All @@ -1106,6 +1120,13 @@ async function prepareObjectsByConfig() {
connections[connection].connected = false;
adapter.log.error(`Could not ping ${connection} ${error}`);
}
// Interview
try {
if (connections[connection].connected)
await connections[connection].twinkly.interview();
} catch (error) {
adapter.log.error(`Could not interview ${connection} ${error}`);
}

const config = {
device: {
Expand Down Expand Up @@ -1358,6 +1379,26 @@ async function saveJSONinState(connection, state, json, mapping) {
mapping.logItem = mapping.logItem !== undefined && mapping.logItem === true;
if (mapping.hide) return;

/**
*
* @param {String} id
* @param {{hide?: Boolean; filter?: {name: String, val: any}; role?: String}} stateInfo
* @param {any} value
* @param {Boolean} stringify
*/
async function writeState(id, stateInfo, value, stringify) {
let canSetState = !stateInfo.hide;
if (canSetState && stateInfo.filter !== undefined)
canSetState = await connections[connection].twinkly.checkDetailInfo(stateInfo.filter);
if (canSetState) {
// Unix * 1000
if (!stringify && stateInfo.role === 'value.time')
value = value * 1000;

await adapter.setStateAsync(state + '.' + id, stringify ? JSON.stringify(value) : value, true);
}
}

if (mapping.expandJSON) {
if (!mapping.parent.hide) {
state += '.' + mapping.parent.id;
Expand All @@ -1367,12 +1408,7 @@ async function saveJSONinState(connection, state, json, mapping) {
for (const key of Object.keys(json)) {
if (Object.keys(mapping.subIDs).includes((key))) {
if (typeof json[key] !== 'object' || Array.isArray(json[key])) {
let canSetState = !mapping.subIDs[key].hide;
if (canSetState && mapping.subIDs[key].filter !== undefined)
canSetState = await connections[connection].twinkly.checkDetailInfo(mapping.subIDs[key].filter);
if (canSetState)
await adapter.setStateAsync(state + '.' + mapping.subIDs[key].id, Array.isArray(json[key]) ? JSON.stringify(json[key]) : json[key], true);

await writeState(mapping.subIDs[key].id, mapping.subIDs[key], json[key], Array.isArray(json[key]));
} else {
await saveJSONinState(connection, state, json[key], mapping.subIDs[key]);
}
Expand All @@ -1383,11 +1419,7 @@ async function saveJSONinState(connection, state, json, mapping) {
}
}
} else {
let canSetState = true;
if (mapping.filter !== undefined)
canSetState = await connections[connection].twinkly.checkDetailInfo(mapping.filter);
if (canSetState)
await adapter.setStateAsync(state + '.' + mapping.parent.id, JSON.stringify(json), true);
await writeState(mapping.parent.id, mapping, json, true);
}

if (mapping.logItem) {
Expand Down

0 comments on commit c200fd6

Please sign in to comment.