Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ignore): Refactor fromZigbee to TS #6284

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,810 changes: 912 additions & 898 deletions src/converters/fromZigbee.js → src/converters/fromZigbee.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/devices/datek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ const definitions: Definition[] = [
data.data &&
data.data.userid !== undefined &&
// Don't read RF events, we can do this with retrieve_state
// @ts-expect-error
(data.data.programeventsrc === undefined || constants.lockSourceName[data.data.programeventsrc] != 'rf')
) {
await device.endpoints[0].command('closuresDoorLock', 'getPinCode', {userid: data.data.userid}, {});
Expand Down
7 changes: 3 additions & 4 deletions src/devices/develco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const develco = {
if (msg.data.hasOwnProperty('develcoInterfaceMode')) {
result[utils.postfixWithEndpointName('interface_mode', msg, model, meta)] =
constants.develcoInterfaceMode.hasOwnProperty(msg.data['develcoInterfaceMode']) ?
// @ts-expect-error
constants.develcoInterfaceMode[msg.data['develcoInterfaceMode']] :
msg.data['develcoInterfaceMode'];
}
Expand Down Expand Up @@ -169,15 +168,15 @@ const develco = {
voc_battery: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
convert: async (model, msg, publish, options, meta) => {
/*
* Per the technical documentation for AQSZB-110:
* To detect low battery the system can monitor the "BatteryVoltage" by setting up a reporting interval of every 12 hour.
* When a voltage of 2.5V is measured the battery should be replaced.
* Low batt LED indication–RED LED will blink twice every 60 second.
*/
const result = fz.battery.convert(model, msg, publish, options, meta);
result.battery_low = (result.voltage <= 2500);
const result = await fz.battery.convert(model, msg, publish, options, meta);
if (result) result.battery_low = (result.voltage <= 2500);
return result;
},
} as Fz.Converter,
Expand Down
2 changes: 1 addition & 1 deletion src/devices/dresden_elektronik.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Definition} from '../lib/types';
import * as exposes from '../lib/exposes';
import * as fz from '../converters/fromZigbee';
import fz from '../converters/fromZigbee';
import * as ota from '../lib/ota';
import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
Expand Down
2 changes: 0 additions & 2 deletions src/devices/sinope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ const fzLocal = {
result.unoccupied_cooling_setpoint = precisionRound(msg.data['unoccupiedCoolingSetpoint'], 2) / 100;
}
if (msg.data.hasOwnProperty('ctrlSeqeOfOper')) {
// @ts-expect-error
result.control_sequence_of_operation = constants.thermostatControlSequenceOfOperations[msg.data['ctrlSeqeOfOper']];
}
if (msg.data.hasOwnProperty('systemMode')) {
// @ts-expect-error
result.system_mode = constants.thermostatSystemModes[msg.data['systemMode']];
}
if (msg.data.hasOwnProperty('pIHeatingDemand')) {
Expand Down
10 changes: 5 additions & 5 deletions src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ const fzLocal = {
} as Fz.Converter,
TS0222_humidity: {
...fz.humidity,
convert: (model, msg, publish, options, meta) => {
const result = fz.humidity.convert(model, msg, publish, options, meta);
result.humidity *= 10;
convert: async (model, msg, publish, options, meta) => {
const result = await fz.humidity.convert(model, msg, publish, options, meta);
if (result) result.humidity *= 10;
return result;
},
} as Fz.Converter,
Expand Down Expand Up @@ -444,8 +444,8 @@ const fzLocal = {
} as Fz.Converter,
TS011F_electrical_measurement: {
...fz.electrical_measurement,
convert: (model, msg, publish, options, meta) => {
const result: KeyValueAny = fz.electrical_measurement.convert(model, msg, publish, options, meta);
convert: async (model, msg, publish, options, meta) => {
const result = await fz.electrical_measurement.convert(model, msg, publish, options, meta);
const lookup: KeyValueString = {power: 'activePower', current: 'rmsCurrent', voltage: 'rmsVoltage'};

// Wait 5 seconds before reporting a 0 value as this could be an invalid measurement.
Expand Down
2 changes: 0 additions & 2 deletions src/devices/weiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const definitions: Definition[] = [
data.data &&
data.data.userid !== undefined &&
// Don't read RF events, we can do this with retrieve_state
// @ts-expect-error
(data.data.programeventsrc === undefined || constants.lockSourceName[data.data.programeventsrc] != 'rf')
) {
await device.endpoints[0].command('closuresDoorLock', 'getPinCode', {userid: data.data.userid}, {});
Expand Down Expand Up @@ -59,7 +58,6 @@ const definitions: Definition[] = [
data.data &&
data.data.userid !== undefined &&
// Don't read RF events, we can do this with retrieve_state
// @ts-expect-error
(data.data.programeventsrc === undefined || constants.lockSourceName[data.data.programeventsrc] != 'rf')
) {
await device.endpoints[0].command('closuresDoorLock', 'getPinCode', {userid: data.data.userid}, {});
Expand Down
50 changes: 26 additions & 24 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {KeyValueAny, KeyValueNumberString} from './types';

export const OneJanuary2000 = new Date('January 01, 2000 00:00:00 UTC+00:00').getTime();

export const defaultBindGroup = 901;
Expand All @@ -12,7 +14,7 @@ export const repInterval = {
MINUTE: 60,
};

export const thermostatControlSequenceOfOperations = {
export const thermostatControlSequenceOfOperations: KeyValueNumberString = {
0: 'cooling_only',
1: 'cooling_with_reheat',
2: 'heating_only',
Expand All @@ -21,14 +23,14 @@ export const thermostatControlSequenceOfOperations = {
5: 'cooling_and_heating_4-pipes_with_reheat',
};

export const thermostatProgrammingOperationModes = {
export const thermostatProgrammingOperationModes: KeyValueNumberString = {
0: 'setpoint',
1: 'schedule',
3: 'schedule_with_preheat',
4: 'eco',
};

export const thermostatSystemModes = {
export const thermostatSystemModes: KeyValueNumberString = {
0: 'off',
1: 'auto',
3: 'cool',
Expand All @@ -40,13 +42,13 @@ export const thermostatSystemModes = {
9: 'sleep',
};

export const thermostatRunningMode= {
export const thermostatRunningMode: KeyValueNumberString= {
0: 'off',
3: 'cool',
4: 'heat',
};

export const thermostatDayOfWeek = {
export const thermostatDayOfWeek: KeyValueNumberString = {
0: 'sunday',
1: 'monday',
2: 'tuesday',
Expand All @@ -57,7 +59,7 @@ export const thermostatDayOfWeek = {
7: 'away_or_vacation',
};

export const thermostatRunningStates = {
export const thermostatRunningStates: KeyValueAny = {
0: 'idle',
1: 'heat',
2: 'cool',
Expand All @@ -75,7 +77,7 @@ export const thermostatRunningStates = {
22: 'cool',
};

export const thermostatAcLouverPositions = {
export const thermostatAcLouverPositions: KeyValueNumberString = {
0: 'fully_closed',
1: 'fully_closed',
2: 'fully_open',
Expand All @@ -84,7 +86,7 @@ export const thermostatAcLouverPositions = {
5: 'three_quarters_open',
};

export const thermostatScheduleMode = {
export const thermostatScheduleMode: KeyValueNumberString = {
0: 'heat',
1: 'cool',
};
Expand All @@ -99,51 +101,51 @@ export const fanMode = {
'smart': 6,
};

export const temperatureDisplayMode = {
export const temperatureDisplayMode: KeyValueNumberString = {
0: 'celsius',
1: 'fahrenheit',
};

export const danfossAdaptionRunStatus= {
export const danfossAdaptionRunStatus: KeyValueNumberString= {
0: 'none',
1: 'in_progress',
2: 'found',
4: 'lost',
};

export const danfossAdaptionRunControl = {
export const danfossAdaptionRunControl: KeyValueNumberString = {
0: 'none',
1: 'initiate_adaptation',
2: 'cancel_adaptation',
};

export const danfossWindowOpen = {
export const danfossWindowOpen: KeyValueNumberString = {
0: 'quarantine',
1: 'closed',
2: 'hold',
3: 'open',
4: 'external_open',
};

export const danfossRoomStatusCode = {
export const danfossRoomStatusCode: KeyValueNumberString = {
0x0000: 'no_error',
0x0101: 'missing_rt',
0x0201: 'rt_touch_error',
0x0401: 'floor_sensor_short_circuit',
0x0801: 'floor_sensor_disconnected',
};

export const danfossOutputStatus = {
export const danfossOutputStatus: KeyValueNumberString = {
0: 'inactive',
1: 'active',
};

export const danfossSystemStatusWater = {
export const danfossSystemStatusWater: KeyValueNumberString = {
0: 'hot_water_flow_in_pipes',
1: 'cool_water_flow_in_pipes',
};

export const danfossSystemStatusCode = {
export const danfossSystemStatusCode: KeyValueNumberString = {
0x0000: 'no_error',
0x0101: 'missing_expansion_board',
0x0201: 'missing_radio_module',
Expand All @@ -156,14 +158,14 @@ export const danfossSystemStatusCode = {
0x0102: 'error_on_one_or_more_output',
};

export const danfossMultimasterRole = {
export const danfossMultimasterRole: KeyValueNumberString = {
0: 'invalid_unused',
1: 'master',
2: 'slave_1',
3: 'slave_2',
};

export const develcoInterfaceMode = {
export const develcoInterfaceMode: KeyValueAny = {
0: 'electricity',
1: 'gas',
2: 'water',
Expand All @@ -174,7 +176,7 @@ export const develcoInterfaceMode = {
260: 'DSMR-4.0',
};

export const keypadLockoutMode = {
export const keypadLockoutMode: KeyValueAny = {
0: 'unlock',
1: 'lock1',
2: 'lock2',
Expand All @@ -183,15 +185,15 @@ export const keypadLockoutMode = {
5: 'lock5',
};

export const lockSourceName = {
export const lockSourceName: KeyValueNumberString = {
0: 'keypad',
1: 'rf',
2: 'manual',
3: 'rfid',
4: 'fingerprint',
};

export const armMode = {
export const armMode: KeyValueNumberString = {
0: 'disarm',
1: 'arm_day_zones',
2: 'arm_night_zones',
Expand Down Expand Up @@ -231,13 +233,13 @@ export const colorModeLookup = {

export const lockSoundVolume = ['silent_mode', 'low_volume', 'high_volume'];

export const lockUserStatus = {
export const lockUserStatus: KeyValueNumberString = {
0: 'available',
1: 'enabled',
3: 'disabled',
};

export const easyCodeTouchActions = {
export const easyCodeTouchActions: KeyValueNumberString = {
// First byte are source / msg.data[3]
// 0x00 KeyPad: If the user uses the code panel.
// 0x02 Manual: If the user used a key, button or fingerprint.
Expand Down Expand Up @@ -274,7 +276,7 @@ export const easyCodeTouchActions = {
0xFF0E: 'zigbee_unlock',
};

export const wiserDimmerControlMode = {
export const wiserDimmerControlMode: KeyValueNumberString = {
0: 'auto',
1: 'rc',
2: 'rl',
Expand Down
6 changes: 3 additions & 3 deletions src/lib/xiaomi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface TrvScheduleConfig {
}


const buffer2DataObject = (meta: Fz.Meta, model: Definition, buffer: Buffer) => {
export const buffer2DataObject = (meta: Fz.Meta, model: Definition, buffer: Buffer) => {
const dataObject: KeyValue = {};

if (buffer !== null && Buffer.isBuffer(buffer)) {
Expand Down Expand Up @@ -157,7 +157,7 @@ const buffer2DataObject = (meta: Fz.Meta, model: Definition, buffer: Buffer) =>
return dataObject;
};

const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, model: Definition, options: KeyValue, dataObject: KeyValue) => {
export const numericAttributes2Payload = async (msg: Fz.Message, meta: Fz.Meta, model: Definition, options: KeyValue, dataObject: KeyValue) => {
let payload: KeyValue = {};

for (const [key, value] of Object.entries(dataObject)) {
Expand Down Expand Up @@ -750,7 +750,7 @@ export const VOCKQJK11LMDisplayUnit = {
'ppb_fahrenheit': 0x11, // ppb, °F
};

const numericAttributes2Options = (definition: Definition) => {
export const numericAttributes2Options = (definition: Definition) => {
const supported = ['temperature', 'device_temperature', 'illuminance', 'illuminance_lux',
'pressure', 'power', 'current', 'voltage', 'energy', 'power'];
const precisionSupported = ['temperature', 'humidity', 'pressure', 'power', 'current', 'voltage', 'energy', 'power'];
Expand Down