Skip to content

Commit

Permalink
fix(ignore): Use zhc types (#20006)
Browse files Browse the repository at this point in the history
* fix(ignore): Use zhc TS types

* updates
  • Loading branch information
Koenkk committed Dec 4, 2023
1 parent 2fa8afe commit dd1e0db
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 166 deletions.
10 changes: 8 additions & 2 deletions lib/extension/availability.ts
Expand Up @@ -4,6 +4,7 @@ import utils from '../util/utils';
import * as settings from '../util/settings';
import debounce from 'debounce';
import bind from 'bind-decorator';
import * as zhc from 'zigbee-herdsman-converters';

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / ci

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 7 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

const retrieveOnReconnect = [
{keys: ['state']},
Expand Down Expand Up @@ -199,8 +200,13 @@ export default class Availability extends Extension {
for (const item of retrieveOnReconnect) {
if (item.condition && this.state.get(device) && !item.condition(this.state.get(device))) continue;
const converter = device.definition.toZigbee.find((c) => c.key.find((k) => item.keys.includes(k)));

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / ci

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / ci

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Parameter 'k' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Parameter 'c' implicitly has an 'any' type.

Check failure on line 202 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Parameter 'k' implicitly has an 'any' type.
await converter?.convertGet?.(device.endpoint(), item.keys[0],
{message: this.state.get(device), mapped: device.definition})
const options: KeyValue = device.options;
const state = this.state.get(device);
const meta: zhc.Tz.Meta = {
message: this.state.get(device), mapped: device.definition, logger, endpoint_name: null,
options, state, device: device.zh,
};
await converter?.convertGet?.(device.endpoint(), item.keys[0], meta)
.catch((e) => {

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / ci

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Parameter 'e' implicitly has an 'any' type.

Check failure on line 210 in lib/extension/availability.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Parameter 'e' implicitly has an 'any' type.
logger.error(`Failed to read state of '${device.name}' after reconnect (${e.message})`);
});
Expand Down
9 changes: 6 additions & 3 deletions lib/extension/bridge.ts
Expand Up @@ -12,12 +12,13 @@ import Group from '../model/group';
import data from '../util/data';
import JSZip from 'jszip';
import fs from 'fs';
import type * as zhc from 'zigbee-herdsman-converters';

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / ci

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 15 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

const requestRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/request/(.*)`);

type DefinitionPayload = {
model: string, vendor: string, description: string, exposes: zhc.DefinitionExpose[], supports_ota:
boolean, icon: string, options: zhc.DefinitionExpose[],
model: string, vendor: string, description: string, exposes: zhc.Expose[], supports_ota:
boolean, icon: string, options: zhc.Expose[],
};

export default class Bridge extends Extension {
Expand Down Expand Up @@ -687,7 +688,9 @@ export default class Bridge extends Extension {

getDefinitionPayload(device: Device): DefinitionPayload {
if (!device.definition) return null;
let icon = device.options.icon ? device.options.icon : device.definition.icon;
// @ts-expect-error icon is valid for external definitions

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / ci

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Unused '@ts-expect-error' directive.

Check failure on line 691 in lib/extension/bridge.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Unused '@ts-expect-error' directive.
const definitionIcon = device.definition.icon;
let icon = device.options.icon ?? definitionIcon;
if (icon) {
icon = icon.replace('${zigbeeModel}', utils.sanitizeImageParameter(device.zh.modelID));
icon = icon.replace('${model}', utils.sanitizeImageParameter(device.definition.model));
Expand Down
5 changes: 2 additions & 3 deletions lib/extension/configure.ts
Expand Up @@ -2,7 +2,7 @@ import * as settings from '../util/settings';
import utils from '../util/utils';
import logger from '../util/logger';
import stringify from 'json-stable-stringify-without-jsonify';
import zhc from 'zigbee-herdsman-converters';
import * as zhc from 'zigbee-herdsman-converters';

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / ci

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 5 in lib/extension/configure.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.
import Extension from './extension';
import bind from 'bind-decorator';
import Device from '../model/device';
Expand Down Expand Up @@ -114,8 +114,7 @@ export default class Configure extends Extension {

logger.info(`Configuring '${device.name}'`);
try {
await device.definition.configure(device.zh, this.zigbee.firstCoordinatorEndpoint(), logger,
device.options);
await device.definition.configure(device.zh, this.zigbee.firstCoordinatorEndpoint(), logger);
logger.info(`Successfully configured '${device.name}'`);
device.zh.meta.configured = zhc.getConfigureKey(device.definition);
device.zh.save();
Expand Down
4 changes: 2 additions & 2 deletions lib/extension/externalConverters.ts
@@ -1,4 +1,4 @@
import zhc from 'zigbee-herdsman-converters';
import * as zhc from 'zigbee-herdsman-converters';

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / ci

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 1 in lib/extension/externalConverters.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.
import * as settings from '../util/settings';
import utils from '../util/utils';
import Extension from './extension';
Expand All @@ -12,7 +12,7 @@ export default class ExternalConverters extends Extension {
for (const definition of utils.getExternalConvertersDefinitions(settings.get())) {
const toAdd = {...definition};
delete toAdd['homeassistant'];
zhc.addDeviceDefinition(toAdd);
zhc.addDefinition(toAdd);
}
}
}
3 changes: 2 additions & 1 deletion lib/extension/groups.ts
Expand Up @@ -7,13 +7,14 @@ import bind from 'bind-decorator';
import Extension from './extension';
import Device from '../model/device';
import Group from '../model/group';
import * as zhc from 'zigbee-herdsman-converters';

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / ci

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Could not find a declaration file for module 'zigbee-herdsman-converters'. '/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

Check failure on line 10 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Could not find a declaration file for module 'zigbee-herdsman-converters'. 'D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/zigbee-herdsman-converters/index.js' implicitly has an 'any' type.

const topicRegex =
new RegExp(`^${settings.get().mqtt.base_topic}/bridge/request/group/members/(remove|add|remove_all)$`);
const legacyTopicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/group/(.+)/(remove|add|remove_all)$`);
const legacyTopicRegexRemoveAll = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/group/remove_all$`);

const stateProperties: {[s: string]: (value: string, exposes: zhc.DefinitionExpose[]) => boolean} = {
const stateProperties: {[s: string]: (value: string, exposes: zhc.Expose[]) => boolean} = {
'state': () => true,
'brightness': (value, exposes) =>
!!exposes.find((e) => e.type === 'light' && e.features.find((f) => f.name === 'brightness')),

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 16)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / ci

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 16)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 16)

Parameter 'f' implicitly has an 'any' type.

Check failure on line 20 in lib/extension/groups.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Parameter 'f' implicitly has an 'any' type.
Expand Down
64 changes: 35 additions & 29 deletions lib/extension/homeassistant.ts
@@ -1,10 +1,11 @@
import * as settings from '../util/settings';
import logger from '../util/logger';
import utils from '../util/utils';
import utils, {isNumericExposeFeature, isBinaryExposeFeature, isEnumExposeFeature} from '../util/utils';
import stringify from 'json-stable-stringify-without-jsonify';
import assert from 'assert';
import Extension from './extension';
import bind from 'bind-decorator';
import * as zhc from 'zigbee-herdsman-converters';

interface MockProperty {property: string, value: KeyValue | string}

Expand Down Expand Up @@ -52,7 +53,7 @@ const legacyMapping = [
},
];

const featurePropertyWithoutEndpoint = (feature: zhc.DefinitionExposeFeature): string => {
const featurePropertyWithoutEndpoint = (feature: zhc.Feature): string => {
if (feature.endpoint) {
return feature.property.slice(0, -1 + -1 * feature.endpoint.length);
} else {
Expand Down Expand Up @@ -115,8 +116,8 @@ export default class HomeAssistant extends Extension {
this.eventBus.emitPublishAvailability();
}

private exposeToConfig(exposes: zhc.DefinitionExpose[], entityType: 'device' | 'group',
allExposes: zhc.DefinitionExpose[], definition?: zhc.Definition): DiscoveryEntry[] {
private exposeToConfig(exposes: zhc.Expose[], entityType: 'device' | 'group',
allExposes: zhc.Expose[], definition?: zhc.Definition): DiscoveryEntry[] {
// For groups an array of exposes (of the same type) is passed, this is to determine e.g. what features
// to use for a bulb (e.g. color_xy/color_temp)
assert(entityType === 'group' || exposes.length === 1, 'Multiple exposes for device not allowed');
Expand All @@ -126,7 +127,7 @@ export default class HomeAssistant extends Extension {

const discoveryEntries: DiscoveryEntry[] = [];
const endpoint = entityType === 'device' ? exposes[0].endpoint : undefined;
const getProperty = (feature: zhc.DefinitionExposeFeature): string => entityType === 'group' ?
const getProperty = (feature: zhc.Feature): string => entityType === 'group' ?
featurePropertyWithoutEndpoint(feature) : feature.property;

/* istanbul ignore else */
Expand Down Expand Up @@ -169,24 +170,24 @@ export default class HomeAssistant extends Extension {
}

if (hasColorTemp) {
const colorTemps = exposes.map((expose) => expose.features.find((e) => e.name === 'color_temp'))
.filter((e) => e);
const colorTemps = exposes.map((expose) => expose.features
.filter(isNumericExposeFeature).find((e) => e.name === 'color_temp'));
const max = Math.min(...colorTemps.map((e) => e.value_max));
const min = Math.max(...colorTemps.map((e) => e.value_min));
discoveryEntry.discovery_payload.max_mireds = max;
discoveryEntry.discovery_payload.min_mireds = min;
}

const effects = utils.arrayUnique(utils.flatten(
allExposes.filter((e) => e.type === 'enum' && e.name === 'effect').map((e) => e.values)));
allExposes.filter(isEnumExposeFeature).filter((e) => e.name === 'effect').map((e) => e.values)));
if (effects.length) {
discoveryEntry.discovery_payload.effect = true;
discoveryEntry.discovery_payload.effect_list = effects;
}

discoveryEntries.push(discoveryEntry);
} else if (firstExpose.type === 'switch') {
const state = firstExpose.features.find((f) => f.name === 'state');
const state = firstExpose.features.filter(isBinaryExposeFeature).find((f) => f.name === 'state');
const property = getProperty(state);
const discoveryEntry: DiscoveryEntry = {
type: 'switch',
Expand Down Expand Up @@ -218,7 +219,8 @@ export default class HomeAssistant extends Extension {
discoveryEntries.push(discoveryEntry);
} else if (firstExpose.type === 'climate') {
const setpointProperties = ['occupied_heating_setpoint', 'current_heating_setpoint'];
const setpoint = firstExpose.features.find((f) => setpointProperties.includes(f.name));
const setpoint = firstExpose.features.filter(isNumericExposeFeature)
.find((f) => setpointProperties.includes(f.name));
assert(setpoint, 'No setpoint found');
const temperature = firstExpose.features.find((f) => f.name === 'local_temperature');
assert(temperature, 'No temperature found');
Expand All @@ -243,7 +245,7 @@ export default class HomeAssistant extends Extension {
},
};

const mode = firstExpose.features.find((f) => f.name === 'system_mode');
const mode = firstExpose.features.filter(isEnumExposeFeature).find((f) => f.name === 'system_mode');
if (mode) {
if (mode.values.includes('sleep')) {
// 'sleep' is not supported by Home Assistant, but is valid according to ZCL
Expand Down Expand Up @@ -283,7 +285,8 @@ export default class HomeAssistant extends Extension {
discoveryEntry.discovery_payload.temperature_state_topic = true;
}

const fanMode = firstExpose.features.find((f) => f.name === 'fan_mode');
const fanMode = firstExpose.features.filter(isEnumExposeFeature)
.find((f) => f.name === 'fan_mode');
if (fanMode) {
discoveryEntry.discovery_payload.fan_modes = fanMode.values;
discoveryEntry.discovery_payload.fan_mode_command_topic = true;
Expand All @@ -292,7 +295,8 @@ export default class HomeAssistant extends Extension {
discoveryEntry.discovery_payload.fan_mode_state_topic = true;
}

const swingMode = firstExpose.features.find((f) => f.name === 'swing_mode');
const swingMode = firstExpose.features.filter(isEnumExposeFeature)
.find((f) => f.name === 'swing_mode');
if (swingMode) {
discoveryEntry.discovery_payload.swing_modes = swingMode.values;
discoveryEntry.discovery_payload.swing_mode_command_topic = true;
Expand All @@ -301,7 +305,7 @@ export default class HomeAssistant extends Extension {
discoveryEntry.discovery_payload.swing_mode_state_topic = true;
}

const preset = firstExpose.features.find((f) => f.name === 'preset');
const preset = firstExpose.features.filter(isEnumExposeFeature).find((f) => f.name === 'preset');
if (preset) {
discoveryEntry.discovery_payload.preset_modes = preset.values;
discoveryEntry.discovery_payload.preset_mode_command_topic = 'preset';
Expand All @@ -310,7 +314,8 @@ export default class HomeAssistant extends Extension {
discoveryEntry.discovery_payload.preset_mode_state_topic = true;
}

const tempCalibration = firstExpose.features.find((f) => f.name === 'local_temperature_calibration');
const tempCalibration = firstExpose.features.filter(isNumericExposeFeature)
.find((f) => f.name === 'local_temperature_calibration');
if (tempCalibration) {
const discoveryEntry: DiscoveryEntry = {
type: 'number',
Expand All @@ -337,7 +342,8 @@ export default class HomeAssistant extends Extension {
discoveryEntries.push(discoveryEntry);
}

const piHeatingDemand = firstExpose.features.find((f) => f.name === 'pi_heating_demand');
const piHeatingDemand = firstExpose.features.filter(isNumericExposeFeature)
.find((f) => f.name === 'pi_heating_demand');
if (piHeatingDemand) {
const discoveryEntry: DiscoveryEntry = {
type: 'sensor',
Expand All @@ -358,7 +364,7 @@ export default class HomeAssistant extends Extension {
discoveryEntries.push(discoveryEntry);
} else if (firstExpose.type === 'lock') {
assert(!endpoint, `Endpoint not supported for lock type`);
const state = firstExpose.features.find((f) => f.name === 'state');
const state = firstExpose.features.filter(isBinaryExposeFeature).find((f) => f.name === 'state');
assert(state, 'No state found');
const discoveryEntry: DiscoveryEntry = {
type: 'lock',
Expand Down Expand Up @@ -404,8 +410,8 @@ export default class HomeAssistant extends Extension {
?.features.find((f) => f.name === 'position');
const tilt = exposes.find((expose) => expose.features.find((e) => e.name === 'tilt'))
?.features.find((f) => f.name === 'tilt');
const motorState = allExposes?.find((e) => e.type === 'enum' &&
['motor_state', 'moving'].includes(e.name) && e.access === ACCESS_STATE);
const motorState = allExposes?.filter(isEnumExposeFeature)
.find((e) => ['motor_state', 'moving'].includes(e.name) && e.access === ACCESS_STATE);
const running = allExposes?.find((e) => e.type === 'binary' && e.name === 'running');

const discoveryEntry: DiscoveryEntry = {
Expand Down Expand Up @@ -436,9 +442,9 @@ export default class HomeAssistant extends Extension {
const closingLookup = ['closing', 'close', 'backward', 'back', 'reverse', 'down', 'declining'];
const stoppedLookup = ['stopped', 'stop', 'pause', 'paused'];

const openingState = motorState.values.find((s) => openingLookup.includes(s.toLowerCase()));
const closingState = motorState.values.find((s) => closingLookup.includes(s.toLowerCase()));
const stoppedState = motorState.values.find((s) => stoppedLookup.includes(s.toLowerCase()));
const openingState = motorState.values.find((s) => openingLookup.includes(s.toString().toLowerCase()));
const closingState = motorState.values.find((s) => closingLookup.includes(s.toString().toLowerCase()));
const stoppedState = motorState.values.find((s) => stoppedLookup.includes(s.toString().toLowerCase()));

if (openingState && closingState && stoppedState) {
discoveryEntry.discovery_payload.state_opening = openingState;
Expand Down Expand Up @@ -496,7 +502,7 @@ export default class HomeAssistant extends Extension {
},
};

const speed = firstExpose.features.find((e) => e.name === 'mode');
const speed = firstExpose.features.filter(isEnumExposeFeature).find((e) => e.name === 'mode');
if (speed) {
// A fan entity in Home Assistant 2021.3 and above may have a speed,
// controlled by a percentage from 1 to 100, and/or non-speed presets.
Expand Down Expand Up @@ -524,7 +530,7 @@ export default class HomeAssistant extends Extension {
}

const allowed = [...speeds, ...presets];
speed.values.forEach((s) => assert(allowed.includes(s)));
speed.values.forEach((s) => assert(allowed.includes(s.toString())));
const percentValues = speeds.map((s, i) => `'${s}':${i}`).join(', ');
const percentCommands = speeds.map((s, i) => `${i}:'${s}'`).join(', ');
const presetList = presets.map((s) => `'${s}'`).join(', ');
Expand All @@ -547,7 +553,7 @@ export default class HomeAssistant extends Extension {
}

discoveryEntries.push(discoveryEntry);
} else if (firstExpose.type === 'binary') {
} else if (isBinaryExposeFeature(firstExpose)) {
const lookup: {[s: string]: KeyValue}= {
battery_low: {entity_category: 'diagnostic', device_class: 'battery'},
button_lock: {entity_category: 'config', icon: 'mdi:lock'},
Expand Down Expand Up @@ -636,7 +642,7 @@ export default class HomeAssistant extends Extension {

discoveryEntries.push(discoveryEntry);
}
} else if (firstExpose.type === 'numeric') {
} else if (isNumericExposeFeature(firstExpose)) {
const lookup: {[s: string]: KeyValue} = {
ac_frequency: {device_class: 'frequency', enabled_by_default: false, entity_category: 'diagnostic',
state_class: 'measurement'},
Expand Down Expand Up @@ -847,7 +853,7 @@ export default class HomeAssistant extends Extension {

discoveryEntries.push(discoveryEntry);
}
} else if (firstExpose.type === 'enum') {
} else if (isEnumExposeFeature(firstExpose)) {
const lookup: {[s: string]: KeyValue} = {
action: {icon: 'mdi:gesture-double-tap'},
alarm_humidity: {entity_category: 'config', icon: 'mdi:water-percent-alert'},
Expand Down Expand Up @@ -1107,8 +1113,8 @@ export default class HomeAssistant extends Extension {
configs.push(entity.definition.homeassistant);
}
} else { // group
const exposesByType: {[s: string]: zhc.DefinitionExpose[]} = {};
const allExposes: zhc.DefinitionExpose[] = [];
const exposesByType: {[s: string]: zhc.Expose[]} = {};
const allExposes: zhc.Expose[] = [];

entity.zh.members.map((e) => this.zigbee.resolveEntity(e.getDevice()) as Device)
.filter((d) => d.definition).forEach((device) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/extension/legacy/bridgeLegacy.ts
@@ -1,6 +1,6 @@
import * as settings from '../../util/settings';
import logger from '../../util/logger';
import zigbeeHerdsmanConverters from 'zigbee-herdsman-converters';
import * as zhc from 'zigbee-herdsman-converters';
import utils from '../../util/utils';
import assert from 'assert';
import Extension from '../extension';
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class BridgeLegacy extends Extension {
};

if (device.zh.type !== 'Coordinator') {
const definition = zigbeeHerdsmanConverters.findByDevice(device.zh);
const definition = zhc.findByDevice(device.zh);
payload.model = definition ? definition.model : device.zh.modelID;
payload.vendor = definition ? definition.vendor : '-';
payload.description = definition ? definition.description : '-';
Expand Down

0 comments on commit dd1e0db

Please sign in to comment.