Skip to content

Commit 0fbbccf

Browse files
committed
chore: release v3.0.1
- (arteck) corr icon download
1 parent 70f527c commit 0fbbccf

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This adapter allows to control the data points of the devices of a Zigbee2MQTT i
2222
[Adapter Documentation](https://github.com/arteck/ioBroker.zigbee2mqtt/blob/main/docs/wiki.md)
2323

2424
## Changelog
25+
### 3.0.1 (2025-01-04)
26+
- (arteck) corr icon download
27+
2528
### 3.0.0 (2025-01-04)
2629
- (arteck) adaptation z2m 2.x
2730

io-package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"common": {
33
"name": "zigbee2mqtt",
4-
"version": "3.0.0",
4+
"version": "3.0.1",
55
"news": {
6+
"3.0.1": {
7+
"en": "corr icon download",
8+
"de": "corr icon herunterladen",
9+
"ru": "скачать значок",
10+
"pt": "corrimento ícone download",
11+
"nl": "corr pictogramdownload",
12+
"fr": "corr icon télécharger",
13+
"it": "icona corr scaricare",
14+
"es": "corr icono descargar",
15+
"pl": "pobierz ikonę corr",
16+
"uk": "cкачати ігру corr",
17+
"zh-cn": "corr 图标下载"
18+
},
619
"3.0.0": {
720
"en": "adaptation z2m 2.x",
821
"de": "anpassung z2m 2.x",

lib/imageController.js

+43-30
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,66 @@ class ImageController {
1818
return deviceName ? deviceNameString.replace(/\u0000/g, '') : 'NA';
1919
}
2020

21-
getZ2mDeviceImage(device) {
21+
getZ2mDeviceImageModelJPG(device) {
2222
if (device && device.definition && device.definition.model) {
2323
const icoString = `https://www.zigbee2mqtt.io/images/devices/${this.sanitizeZ2MDeviceName(device.definition.model)}.jpg`;
2424
// eslint-disable-next-line no-control-regex
2525
return icoString.replace(/\u0000/g, '');
2626
}
2727
}
2828

29+
getZ2mDeviceImageModelPNG(device) {
30+
if (device && device.definition && device.definition.model) {
31+
const icoString = `https://www.zigbee2mqtt.io/images/devices/${this.sanitizeZ2MDeviceName(device.definition.model)}.png`;
32+
// eslint-disable-next-line no-control-regex
33+
return icoString.replace(/\u0000/g, '');
34+
}
35+
}
36+
37+
2938
getSlsDeviceImage(device) {
3039
if (device && device.model_id) {
31-
const icoString = `https://slsys.github.io/Gateway/devices/png/${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;
40+
const icoString = `https://www.zigbee2mqtt.io/images/devices/${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;
3241
// eslint-disable-next-line no-control-regex
3342
return icoString.replace(/\u0000/g, '');
3443
}
3544
}
3645

3746
async getDeviceIcon(device) {
38-
if (this.adapter.config.useDeviceIcons == false) {
39-
return '';
40-
}
47+
if (!this.adapter.config.useDeviceIcons) return '';
4148

42-
const imageSize = this.adapter.config.deviceIconsSize;
49+
const imageSize = this.adapter.config.deviceIconsSize;
4350

44-
const z2mIconFileName = `${this.sanitizeZ2MDeviceName(device.definition.model)}.jpg`;
51+
const z2mIconFileNameJPG = `${this.sanitizeZ2MDeviceName(device.definition.model)}.jpg`;
52+
const z2mIconFileNamePNG = `${this.sanitizeZ2MDeviceName(device.definition.model)}.png`;
4553
const slsIconFileName = `${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;
4654

47-
let icon;
48-
let iconFileName;
49-
// Check whether an image has already been downloaded from Z2M.
50-
if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileName)) {
51-
iconFileName = z2mIconFileName;
52-
}
53-
// Check whether an image has already been downloaded from SLSys.
54-
else if (await this.adapter.fileExistsAsync(this.adapter.namespace, slsIconFileName)) {
55-
iconFileName = slsIconFileName;
56-
}
57-
// If not donwload image
58-
else {
59-
let iconUrl = this.getSlsDeviceImage(device);
60-
61-
this.adapter.log.info(`Download image for device model: ${device.definition.model}`);
55+
let iconFileName = await this.getExistingIconFileName(z2mIconFileNameJPG, z2mIconFileNamePNG, slsIconFileName);
6256

63-
try {
64-
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
65-
} catch (err) {
66-
iconUrl = this.getZ2mDeviceImage(device);
67-
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
68-
}
57+
if (!iconFileName) {
58+
const iconUrls = [
59+
this.getZ2mDeviceImageModelJPG(device),
60+
this.getZ2mDeviceImageModelPNG(device),
61+
this.getSlsDeviceImage(device)
62+
];
6963

70-
iconFileName = this.getFileNameWithExtension(iconUrl);
64+
for (const iconUrl of iconUrls) {
65+
try {
66+
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
67+
iconFileName = this.getFileNameWithExtension(iconUrl);
68+
break;
69+
} catch (err) {
70+
this.adapter.log.warn(`Failed to download image from ${iconUrl}`);
71+
}
72+
}
7173
}
7274

73-
if ((await this.adapter.fileExistsAsync(this.adapter.namespace, iconFileName)) == false) {
75+
if (!iconFileName) {
7476
this.adapter.log.warn(`No image for device model: ${device.definition.model} found!`);
7577
return '';
7678
}
7779

80+
let icon;
7881
try {
7982
// Load image from the Meta-Store
8083
icon = await this.adapter.readFileAsync(this.adapter.namespace, iconFileName);
@@ -122,6 +125,16 @@ class ImageController {
122125
adapter.log.warn(ex);
123126
}
124127
}
128+
async getExistingIconFileName(z2mIconFileNameJPG, z2mIconFileNamePNG, slsIconFileName) {
129+
if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileNameJPG)) {
130+
return z2mIconFileNameJPG;
131+
} else if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileNamePNG)) {
132+
return z2mIconFileNamePNG;
133+
} else if (await this.adapter.fileExistsAsync(this.adapter.namespace, slsIconFileName)) {
134+
return slsIconFileName;
135+
}
136+
return null;
137+
}
125138
}
126139
module.exports = {
127140
ImageController,

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iobroker.zigbee2mqtt",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Zigbee2MQTT adapter for ioBroker",
55
"author": {
66
"name": "Dennis Rathjen and Arthur Rupp",

0 commit comments

Comments
 (0)