Skip to content

Commit

Permalink
feat(ignore): Refactor all devices to TS (#6166)
Browse files Browse the repository at this point in the history
* feat(ignore): Refactor all devices to TS

* fix

* fix
  • Loading branch information
Koenkk committed Sep 16, 2023
1 parent 1979178 commit beddf3b
Show file tree
Hide file tree
Showing 26 changed files with 1,408 additions and 1,371 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ If any of those commands finish with an error your PR won't pass the tests and w
- `battery`:
- `{dontDividePercentage: true}`: prevents batteryPercentageRemainig from being divided (ZCL 200=100%, but some report 100=100%) (default: false)
- `{voltageToPercentage: '3V_2100'}`: convert voltage to percentage using specified option. See utils.batteryVoltageToPercentage() (default: null, no voltage to percentage conversion)
- `fanStateOn`: value used for fan_mode when using fan_state="ON", the default is "on"


43 changes: 0 additions & 43 deletions scripts/devicesTSrefactor.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,9 +1460,6 @@ const converters = {
fan_mode: {
key: ['fan_mode', 'fan_state'],
convertSet: async (entity, key, value, meta) => {
if (key == 'fan_state' && value.toLowerCase() == 'on') {
value = utils.getMetaValue(entity, meta.mapped, 'fanStateOn', 'allEqual', 'on');
}
const fanMode = constants.fanMode[value.toLowerCase()];
await entity.write('hvacFanCtrl', {fanMode});
return {state: {fan_mode: value.toLowerCase(), fan_state: value.toLowerCase() === 'off' ? 'OFF' : 'ON'}};
Expand Down
35 changes: 19 additions & 16 deletions src/devices/gledopto.js → src/devices/gledopto.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
const exposes = require('../lib/exposes');
const globalStore = require('../lib/store');
const ota = require('../lib/ota');
const extend = require('../lib/extend');
const reporting = require('../lib/reporting');
const utils = require('../lib/utils');
const tz = require('../converters/toZigbee');
import {Configure, Definition, KeyValue, OnEventType, Zh, Extend} from '../lib/types';
import * as exposes from '../lib/exposes';
import * as globalStore from '../lib/store';
import * as ota from '../lib/ota';
import extend from '../lib/extend';
import * as reporting from '../lib/reporting';
import * as utils from '../lib/utils';
import tz from '../converters/toZigbee';
const e = exposes.presets;

const gledoptoExtend = {
light_onoff_brightness: (options={}) => ({
light_onoff_brightness: (options: Extend.options_light_onoff_brightness={}) => ({
...extend.light_onoff_brightness({disablePowerOnBehavior: true, ...options}),
toZigbee: utils.replaceInArray(
extend.light_onoff_brightness(options).toZigbee,
[tz.light_onoff_brightness],
[tz.gledopto_light_onoff_brightness],
),
}),
light_onoff_brightness_colortemp: (options={}) => ({
light_onoff_brightness_colortemp: (options: Extend.options_light_onoff_brightness_colortemp={}) => ({
...extend.light_onoff_brightness_colortemp({disablePowerOnBehavior: true, ...options}),
toZigbee: utils.replaceInArray(
extend.light_onoff_brightness_colortemp(options).toZigbee,
[tz.light_onoff_brightness, tz.light_colortemp],
[tz.gledopto_light_onoff_brightness, tz.gledopto_light_colortemp],
),
}),
light_onoff_brightness_color: (options={}) => ({
light_onoff_brightness_color: (options: Extend.options_light_onoff_brightness_color={}) => ({
...extend.light_onoff_brightness_color({disablePowerOnBehavior: true, supportsHueAndSaturation: true, ...options}),
toZigbee: utils.replaceInArray(
extend.light_onoff_brightness_color(options).toZigbee,
[tz.light_onoff_brightness, tz.light_color],
[tz.gledopto_light_onoff_brightness, tz.gledopto_light_color],
),
}),
light_onoff_brightness_colortemp_color: (options={}) => ({
light_onoff_brightness_colortemp_color: (options: Extend.options_light_onoff_brightness_colortemp_color={}) => ({
...extend.light_onoff_brightness_colortemp_color({disablePowerOnBehavior: true, supportsHueAndSaturation: true, ...options}),
toZigbee: utils.replaceInArray(
extend.light_onoff_brightness_colortemp_color(options).toZigbee,
[tz.light_onoff_brightness, tz.light_color_colortemp],
[tz.gledopto_light_onoff_brightness, tz.gledopto_light_color_colortemp],
),
}),
switch: (options={}) => ({
switch: (options: Extend.options_switch={}) => ({
...extend.switch({disablePowerOnBehavior: true, ...options}),
onEvent: async (type, data, device) => {
onEvent: async (type: OnEventType, data: KeyValue, device: Zh.Device) => {
// This device doesn't support reporting.
// Therefore we read the on/off state every 5 seconds.
// This is the same way as the Hue bridge does it.
Expand All @@ -63,7 +64,7 @@ const gledoptoExtend = {
}),
};

const configureReadModelID = async (device, coordinatorEndpoint, logger) => {
const configureReadModelID: Configure = async (device, coordinatorEndpoint, logger) => {
// https://github.com/Koenkk/zigbee-herdsman-converters/issues/3016#issuecomment-1027726604
const endpoint = device.endpoints[0];
const oldModel = device.modelID;
Expand All @@ -73,7 +74,7 @@ const configureReadModelID = async (device, coordinatorEndpoint, logger) => {
}
};

module.exports = [
const definitions: Definition[] = [
{
zigbeeModel: ['GL-SD-003P'],
model: 'GL-SD-003P',
Expand Down Expand Up @@ -239,7 +240,7 @@ module.exports = [
vendor: 'Gledopto',
description: 'Zigbee LED Controller RGB+CCT (2 ID)',
extend: gledoptoExtend.light_onoff_brightness_colortemp_color(),
exposes: [e.light_brightness_colorxy().withEndpoint('rgb'), e.light_brightness_colortemp().withEndpoint('cct')],
exposes: [e.light_brightness_colorxy().withEndpoint('rgb'), e.light_brightness_colortemp([158, 495]).withEndpoint('cct')],
// Only enable disableDefaultResponse for the second fingerprint:
// https://github.com/Koenkk/zigbee-herdsman-converters/issues/1315#issuecomment-645331185
meta: {disableDefaultResponse: (entity) => !!entity.getDevice().getEndpoint(12)},
Expand Down Expand Up @@ -804,3 +805,5 @@ module.exports = [
extend: gledoptoExtend.light_onoff_brightness_colortemp({colorTempRange: [158, 495]}),
},
];

module.exports = definitions;
Loading

0 comments on commit beddf3b

Please sign in to comment.