Skip to content

Commit

Permalink
fix: Improve support of Sunricher ZG2858A (#7637)
Browse files Browse the repository at this point in the history
* Updated the ZG2858A of sunricher

1. Updated the ZG2858A definition to the latest version.
2. Added move_to_hue_and_saturation for ColorCtrlCommand.
3. Added commandsScenes.

* fixed eslint issues

* Update sunricher.ts

* Update modernExtend.ts

---------

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
  • Loading branch information
maginawin and Koenkk authored Jun 15, 2024
1 parent d21ed6a commit 6fbad86
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/devices/sunricher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
temperature,
humidity,
illuminance,
commandsOnOff,
commandsLevelCtrl,
commandsColorCtrl,
commandsScenes,
} from '../lib/modernExtend';
import {logger} from '../lib/logger';

Expand Down Expand Up @@ -67,6 +71,21 @@ async function syncTime(endpoint: Zh.Endpoint) {
}

const definitions: Definition[] = [
{
zigbeeModel: ['ZG2858A'],
model: 'ZG2858A',
vendor: 'Sunricher',
description: 'Zigbee handheld remote RGBCCT 3 channels',
extend: [
deviceEndpoints({endpoints: {'1': 1, '2': 2, '3': 3}}),
battery(),
identify(),
commandsOnOff(),
commandsLevelCtrl(),
commandsColorCtrl(),
commandsScenes(),
],
},
{
zigbeeModel: ['HK-SL-DIM-US-A'],
model: 'HK-SL-DIM-US-A',
Expand Down Expand Up @@ -313,24 +332,6 @@ const definitions: Definition[] = [
return {ep1: 1, ep2: 2, ep3: 3, ep4: 4};
},
},
{
zigbeeModel: ['ZG2858A'],
model: 'ZG2858A',
vendor: 'Sunricher',
description: 'Zigbee handheld remote RGBCCT 3 channels',
fromZigbee: [fz.battery, fz.command_move_to_color, fz.command_move_to_color_temp, fz.command_move_hue,
fz.command_step, fz.command_recall, fz.command_on, fz.command_off, fz.command_toggle, fz.command_stop,
fz.command_move, fz.command_color_loop_set, fz.command_ehanced_move_to_hue_and_saturation, fz.command_move_to_hue_and_saturation],
exposes: [e.battery(), e.action([
'color_move', 'color_temperature_move', 'hue_move', 'brightness_step_up', 'brightness_step_down',
'recall_*', 'on', 'off', 'toggle', 'brightness_stop', 'brightness_move_up', 'brightness_move_down',
'color_loop_set', 'enhanced_move_to_hue_and_saturation', 'hue_stop'])],
toZigbee: [],
meta: {multiEndpoint: true},
endpoint: (device) => {
return {ep1: 1, ep2: 2, ep3: 3};
},
},
{
zigbeeModel: ['HK-ZCC-A'],
model: 'SR-ZG9080A',
Expand Down
51 changes: 51 additions & 0 deletions src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ export type ColorCtrlCommand = 'color_temperature_move_stop' |
'color_temperature_step_up' |
'color_temperature_step_down' |
'enhanced_move_to_hue_and_saturation' |
'move_to_hue_and_saturation' |
'color_hue_step_up' |
'color_hue_step_down' |
'color_saturation_step_up' |
Expand All @@ -1038,6 +1039,7 @@ export function commandsColorCtrl(args?: CommandsColorCtrl): ModernExtend {
'color_temperature_step_up',
'color_temperature_step_down',
'enhanced_move_to_hue_and_saturation',
'move_to_hue_and_saturation',
'color_hue_step_up',
'color_hue_step_down',
'color_saturation_step_up',
Expand Down Expand Up @@ -1508,6 +1510,55 @@ export function ota(definition?: DefinitionOta): ModernExtend {

// #region Other extends

export interface CommandsScenesArgs {
commands?: string[];
bind?: boolean;
endpointNames?: string[];
}
export function commandsScenes(args?: CommandsScenesArgs) {
args = {commands: ['recall', 'store', 'add', 'remove', 'remove_all'], bind: true, ...args};
let actions = args.commands!;
if (args.endpointNames) {
actions = args.commands.map((c) => args.endpointNames.map((e) => `${c}_${e}`)).flat();
}
const exposesArray = [
e.enum('action', ea.STATE, actions).withDescription('Triggered scene action (e.g. recall a scene)'),
];

const actionPayloadLookup: { [key: string]: string } = {
'commandRecall': 'recall',
'commandStore': 'store',
'commandAdd': 'add',
'commandRemove': 'remove',
'commandRemoveAll': 'remove_all',
};

const fromZigbee: Fz.Converter[] = [
{
cluster: 'genScenes',
type: ['commandRecall', 'commandStore', 'commandAdd', 'commandRemove', 'commandRemoveAll'],
convert: (model, msg, publish, options, meta) => {
if (hasAlreadyProcessedMessage(msg, model)) return;
let trailing = '';
if (msg.type === 'commandRecall' || msg.type === 'commandStore') {
trailing = `_${msg.data.sceneid}`;
}
const payload = {
action: postfixWithEndpointName(actionPayloadLookup[msg.type] + trailing, msg, model, meta),
};
addActionGroup(payload, msg, model);
return payload;
},
},
];

const result: ModernExtend = {exposes: exposesArray, fromZigbee, isModernExtend: true};

if (args.bind) result.configure = [setupConfigureForBinding('genScenes', 'output', args.endpointNames)];

return result;
}

export interface EnumLookupArgs {
name: string, lookup: KeyValue, cluster: string | number, attribute: string | {ID: number, type: number}, description: string,
zigbeeCommandOptions?: {manufacturerCode?: number, disableDefaultResponse?: boolean}, access?: 'STATE' | 'STATE_GET' | 'ALL',
Expand Down

0 comments on commit 6fbad86

Please sign in to comment.