Fix some todos

This commit is contained in:
Koen Kanters
2021-10-06 21:27:23 +02:00
parent 7ea29eadf4
commit 42497f3176
10 changed files with 18 additions and 36 deletions
-1
View File
@@ -86,7 +86,6 @@ class Controller {
async start(): Promise<void> {
this.state.start();
// @ts-ignore
logger.logOutput();
const info = await utils.getZigbee2MQTTVersion();
+2 -5
View File
@@ -52,7 +52,7 @@ export default class Bridge extends Extension {
callback();
}
}
// @ts-ignore TODO fix typing
logger.addTransport(new EventTransport());
this.zigbee2mqttVersion = await utils.getZigbee2MQTTVersion();
@@ -174,7 +174,6 @@ export default class Bridge extends Extension {
}
if (newSettings.hasOwnProperty('advanced') && newSettings.advanced.hasOwnProperty('log_level')) {
// @ts-ignore fix type
logger.setLevel(newSettings.advanced.log_level);
}
@@ -300,12 +299,11 @@ export default class Bridge extends Extension {
// Deprecated
@bind async configLogLevel(message: KeyValue | string): Promise<MQTTResponse> {
const allowed = ['error', 'warn', 'info', 'debug'];
const value = this.getValue(message);
const value = this.getValue(message) as 'error' | 'warn' | 'info' | 'debug';
if (typeof value !== 'string' || !allowed.includes(value)) {
throw new Error(`'${value}' is not an allowed value, allowed: ${allowed}`);
}
// @ts-ignore TODO fix type
logger.setLevel(value);
this.publishInfo();
return utils.getResponse(message, {value}, null);
@@ -558,7 +556,6 @@ export default class Bridge extends Extension {
commit: this.zigbee2mqttVersion.commitHash,
coordinator: this.coordinatorVersion,
network: utils.toSnakeCase(await this.zigbee.getNetworkParameters()),
// @ts-ignore TODO fix type
log_level: logger.getLevel(),
permit_join: this.zigbee.getPermitJoin(),
permit_join_timeout: this.zigbee.getPermitJoinTimeout(),
-1
View File
@@ -2,7 +2,6 @@ import http from 'http';
import serveStatic from 'serve-static';
import finalhandler from 'finalhandler';
import logger from '../util/logger';
// @ts-ignore
import frontend from 'zigbee2mqtt-frontend';
import WebSocket from 'ws';
import net from 'net';
+6 -9
View File
@@ -69,13 +69,10 @@ export default class HomeAssistant extends Extension {
this.eventBus.onDeviceRenamed(this, this.onDeviceRenamed);
this.eventBus.onPublishEntityState(this, this.onPublishEntityState);
this.eventBus.onGroupMembersChanged(this, this.onGroupMembersChanged);
/* istanbul ignore next TODO */
this.eventBus.onDeviceAnnounce(this, (data: eventdata.DeviceAnnounce) => this.onZigbeeEvent(data.device));
/* istanbul ignore next TODO */
this.eventBus.onDeviceJoined(this, (data: eventdata.DeviceAnnounce) => this.onZigbeeEvent(data.device));
/* istanbul ignore next TODO */
this.eventBus.onDeviceInterview(this, (data: eventdata.DeviceAnnounce) => this.onZigbeeEvent(data.device));
this.eventBus.onDeviceMessage(this, (data: eventdata.DeviceAnnounce) => this.onZigbeeEvent(data.device));
this.eventBus.onDeviceAnnounce(this, this.onZigbeeEvent);
this.eventBus.onDeviceJoined(this, this.onZigbeeEvent);
this.eventBus.onDeviceInterview(this, this.onZigbeeEvent);
this.eventBus.onDeviceMessage(this, this.onZigbeeEvent);
this.mqtt.subscribe(this.statusTopic);
this.mqtt.subscribe(defaultStatusTopic);
@@ -1110,8 +1107,8 @@ export default class HomeAssistant extends Extension {
}
}
@bind onZigbeeEvent(device: Device): void {
this.discover(device);
@bind onZigbeeEvent(data: {device: Device}): void {
this.discover(data.device);
}
private getDevicePayload(entity: Device | Group): KeyValue {
+1 -3
View File
@@ -119,10 +119,9 @@ export default class BridgeLegacy extends Extension {
}
@bind logLevel(topic: string, message: string): void {
const level = message.toLowerCase();
const level = message.toLowerCase() as 'error' | 'warn' | 'info' | 'debug';
if (allowedLogLevels.includes(level)) {
logger.info(`Switching log level to '${level}'`);
// @ts-ignore
logger.setLevel(level);
} else {
logger.error(`Could not set log level to '${level}'. Allowed level: '${allowedLogLevels.join(',')}'`);
@@ -367,7 +366,6 @@ export default class BridgeLegacy extends Extension {
commit: info.commitHash,
coordinator,
network: await this.zigbee.getNetworkParameters(),
// @ts-ignore
log_level: logger.getLevel(),
permit_join: this.zigbee.getPermitJoin(),
};
-1
View File
@@ -2,7 +2,6 @@ import * as settings from '../util/settings';
import logger from '../util/logger';
import stringify from 'json-stable-stringify-without-jsonify';
import utils from '../util/utils';
// @ts-ignore
import tradfriOTA from 'zigbee-herdsman-converters/lib/ota/tradfri';
import Extension from './extension';
import bind from 'bind-decorator';
+1 -2
View File
@@ -190,8 +190,7 @@ export default class Publish extends Extension {
for (let [key, value] of entries) {
let endpointName = parsedTopic.endpoint;
let localTarget = target;
// @ts-ignore TODO fix
let endpointOrGroupID = target.constructor.name === 'Endpoint' ? target.ID : target.groupID;
let endpointOrGroupID = utils.isEndpoint(target) ? target.ID : target.groupID;
// When the key has a endpointName included (e.g. state_right), this will override the target.
const propertyEndpointMatch = key.match(propertyEndpointRegex);
+5
View File
@@ -6,3 +6,8 @@ declare module 'zigbee-herdsman-converters' {
export function addDeviceDefinition(definition: zhc.Definition): Promise<void>;
export function onEvent(type: string, data: KeyValue, device: zh.Device): Promise<void>;
}
declare module 'zigbee-herdsman-converters/lib/ota/tradfri' {
export function useTestURL(): void;
}
+3
View File
@@ -0,0 +1,3 @@
declare module 'zigbee2mqtt-frontend' {
export function getPath(): string;
}
-14
View File
@@ -330,20 +330,6 @@ describe('Receive', () => {
expect(MQTT.publish).toHaveBeenCalledTimes(0);
});
// TODO
// it('Should publish last_seen for unhandled messages', async () => {
// const device = zigbeeHerdsman.devices.WXKG02LM_rev1;
// settings.set(['advanced', 'last_seen'], 'epoch');
// const data = {onOff: 1};
// const payload = {data, cluster: 'genRssiLocation', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10};
// await zigbeeHerdsman.events.message(payload);
// await flushPromises();
// expect(MQTT.publish).toHaveBeenCalledTimes(1);
// expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/button_double_key');
// expect(typeof JSON.parse(MQTT.publish.mock.calls[0][1]).last_seen).toBe('number')
// expect(MQTT.publish.mock.calls[0][2]).toStrictEqual({"qos": 0, "retain": false});
// });
it('Should publish last_seen epoch', async () => {
const device = zigbeeHerdsman.devices.WXKG02LM_rev1;
settings.set(['advanced', 'last_seen'], 'epoch');