Skip to content

Commit

Permalink
chore: release v3.0.1
Browse files Browse the repository at this point in the history
-   (arteck) corr icon download
  • Loading branch information
arteck committed Jan 4, 2025
1 parent 70f527c commit 0fbbccf
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 34 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ This adapter allows to control the data points of the devices of a Zigbee2MQTT i
[Adapter Documentation](https://github.com/arteck/ioBroker.zigbee2mqtt/blob/main/docs/wiki.md)

## Changelog
### 3.0.1 (2025-01-04)
- (arteck) corr icon download

### 3.0.0 (2025-01-04)
- (arteck) adaptation z2m 2.x

Expand Down
15 changes: 14 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"common": {
"name": "zigbee2mqtt",
"version": "3.0.0",
"version": "3.0.1",
"news": {
"3.0.1": {
"en": "corr icon download",
"de": "corr icon herunterladen",
"ru": "скачать значок",
"pt": "corrimento ícone download",
"nl": "corr pictogramdownload",
"fr": "corr icon télécharger",
"it": "icona corr scaricare",
"es": "corr icono descargar",
"pl": "pobierz ikonę corr",
"uk": "cкачати ігру corr",
"zh-cn": "corr 图标下载"
},
"3.0.0": {
"en": "adaptation z2m 2.x",
"de": "anpassung z2m 2.x",
Expand Down
73 changes: 43 additions & 30 deletions lib/imageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,66 @@ class ImageController {
return deviceName ? deviceNameString.replace(/\u0000/g, '') : 'NA';
}

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

getZ2mDeviceImageModelPNG(device) {
if (device && device.definition && device.definition.model) {
const icoString = `https://www.zigbee2mqtt.io/images/devices/${this.sanitizeZ2MDeviceName(device.definition.model)}.png`;
// eslint-disable-next-line no-control-regex
return icoString.replace(/\u0000/g, '');
}
}


getSlsDeviceImage(device) {
if (device && device.model_id) {
const icoString = `https://slsys.github.io/Gateway/devices/png/${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;
const icoString = `https://www.zigbee2mqtt.io/images/devices/${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;
// eslint-disable-next-line no-control-regex
return icoString.replace(/\u0000/g, '');
}
}

async getDeviceIcon(device) {
if (this.adapter.config.useDeviceIcons == false) {
return '';
}
if (!this.adapter.config.useDeviceIcons) return '';

const imageSize = this.adapter.config.deviceIconsSize;
const imageSize = this.adapter.config.deviceIconsSize;

const z2mIconFileName = `${this.sanitizeZ2MDeviceName(device.definition.model)}.jpg`;
const z2mIconFileNameJPG = `${this.sanitizeZ2MDeviceName(device.definition.model)}.jpg`;
const z2mIconFileNamePNG = `${this.sanitizeZ2MDeviceName(device.definition.model)}.png`;
const slsIconFileName = `${this.sanitizeModelIDForImageUrl(device.model_id)}.png`;

let icon;
let iconFileName;
// Check whether an image has already been downloaded from Z2M.
if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileName)) {
iconFileName = z2mIconFileName;
}
// Check whether an image has already been downloaded from SLSys.
else if (await this.adapter.fileExistsAsync(this.adapter.namespace, slsIconFileName)) {
iconFileName = slsIconFileName;
}
// If not donwload image
else {
let iconUrl = this.getSlsDeviceImage(device);

this.adapter.log.info(`Download image for device model: ${device.definition.model}`);
let iconFileName = await this.getExistingIconFileName(z2mIconFileNameJPG, z2mIconFileNamePNG, slsIconFileName);

try {
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
} catch (err) {
iconUrl = this.getZ2mDeviceImage(device);
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
}
if (!iconFileName) {
const iconUrls = [
this.getZ2mDeviceImageModelJPG(device),
this.getZ2mDeviceImageModelPNG(device),
this.getSlsDeviceImage(device)
];

iconFileName = this.getFileNameWithExtension(iconUrl);
for (const iconUrl of iconUrls) {
try {
await this.downloadIcon(this.adapter, iconUrl, this.adapter.namespace);
iconFileName = this.getFileNameWithExtension(iconUrl);
break;
} catch (err) {
this.adapter.log.warn(`Failed to download image from ${iconUrl}`);
}
}
}

if ((await this.adapter.fileExistsAsync(this.adapter.namespace, iconFileName)) == false) {
if (!iconFileName) {
this.adapter.log.warn(`No image for device model: ${device.definition.model} found!`);
return '';
}

let icon;
try {
// Load image from the Meta-Store
icon = await this.adapter.readFileAsync(this.adapter.namespace, iconFileName);
Expand Down Expand Up @@ -122,6 +125,16 @@ class ImageController {
adapter.log.warn(ex);
}
}
async getExistingIconFileName(z2mIconFileNameJPG, z2mIconFileNamePNG, slsIconFileName) {
if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileNameJPG)) {
return z2mIconFileNameJPG;
} else if (await this.adapter.fileExistsAsync(this.adapter.namespace, z2mIconFileNamePNG)) {
return z2mIconFileNamePNG;
} else if (await this.adapter.fileExistsAsync(this.adapter.namespace, slsIconFileName)) {
return slsIconFileName;
}
return null;
}
}
module.exports = {
ImageController,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.zigbee2mqtt",
"version": "3.0.0",
"version": "3.0.1",
"description": "Zigbee2MQTT adapter for ioBroker",
"author": {
"name": "Dennis Rathjen and Arthur Rupp",
Expand Down

0 comments on commit 0fbbccf

Please sign in to comment.