-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add two private attributes for SR-ZG9040A/ZG9041A-D. #8210
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,13 +25,150 @@ import { | |||||
} from '../lib/modernExtend'; | ||||||
import * as reporting from '../lib/reporting'; | ||||||
import * as globalStore from '../lib/store'; | ||||||
import {DefinitionWithExtend, Fz, Zh} from '../lib/types'; | ||||||
import {DefinitionWithExtend, Expose, Fz, ModernExtend, OnEvent, OnEventData, OnEventType, Tz, Zh} from '../lib/types'; | ||||||
import * as utils from '../lib/utils'; | ||||||
|
||||||
const NS = 'zhc:sunricher'; | ||||||
const e = exposes.presets; | ||||||
const ea = exposes.access; | ||||||
|
||||||
const sunricherManufacturerCode = 0x1224; | ||||||
|
||||||
async function readAttributeIfOnline(type: OnEventType, data: OnEventData, device: Zh.Device, attribute: number) { | ||||||
let isReading = false; | ||||||
if (type === 'deviceInterview') { | ||||||
const interviewData = data as {status: string}; | ||||||
if (interviewData.status === 'successful') { | ||||||
isReading = true; | ||||||
} | ||||||
} else if (type === 'deviceAnnounce') { | ||||||
isReading = true; | ||||||
} | ||||||
if (isReading) { | ||||||
const endpoint = device.getEndpoint(1); | ||||||
await endpoint.read('genBasic', [attribute], {manufacturerCode: sunricherManufacturerCode}); | ||||||
} | ||||||
} | ||||||
|
||||||
function sunricherExternalSwitchType(): ModernExtend { | ||||||
const attribute = 0x8803; | ||||||
const dataType = 0x20; | ||||||
const valueMap: {[key: number]: string} = { | ||||||
0: 'Push button', | ||||||
1: 'Normal on/off', | ||||||
2: 'Three way', | ||||||
}; | ||||||
const valueLookup: {[key: string]: number} = { | ||||||
'Push button': 0, | ||||||
'Normal on/off': 1, | ||||||
'Three way': 2, | ||||||
}; | ||||||
|
||||||
const fromZigbee: Fz.Converter[] = [ | ||||||
{ | ||||||
cluster: 'genBasic', | ||||||
type: ['attributeReport', 'readResponse'], | ||||||
convert: (model, msg, publish, options, meta) => { | ||||||
if (Object.prototype.hasOwnProperty.call(msg.data, attribute)) { | ||||||
const value = msg.data[attribute]; | ||||||
return { | ||||||
externalSwitchType: valueMap[value] || 'unknown', | ||||||
externalSwitchTypeNumeric: value, | ||||||
}; | ||||||
} | ||||||
return undefined; | ||||||
}, | ||||||
} satisfies Fz.Converter, | ||||||
]; | ||||||
|
||||||
const toZigbee: Tz.Converter[] = [ | ||||||
{ | ||||||
key: ['externalSwitchType'], | ||||||
convertSet: async (entity, key, value: string, meta) => { | ||||||
const numericValue = valueLookup[value] ?? parseInt(value, 10); | ||||||
await entity.write('genBasic', {[attribute]: {value: numericValue, type: dataType}}, {manufacturerCode: sunricherManufacturerCode}); | ||||||
return {state: {externalSwitchType: value}}; | ||||||
}, | ||||||
convertGet: async (entity, key, meta) => { | ||||||
await entity.read('genBasic', [attribute], {manufacturerCode: sunricherManufacturerCode}); | ||||||
}, | ||||||
} satisfies Tz.Converter, | ||||||
]; | ||||||
|
||||||
const exposes: Expose[] = [e.enum('externalSwitchType', ea.ALL, ['Push button', 'Normal on/off', 'Three way']).withLabel('External Switch Type')]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const onEvent: OnEvent = async (type, data, device) => { | ||||||
await readAttributeIfOnline(type, data, device, attribute); | ||||||
}; | ||||||
return { | ||||||
fromZigbee, | ||||||
toZigbee, | ||||||
exposes, | ||||||
onEvent, | ||||||
isModernExtend: true, | ||||||
}; | ||||||
} | ||||||
|
||||||
function sunricherMinimumPWM(): ModernExtend { | ||||||
const attribute = 0x7809; | ||||||
const dataType = 0x20; | ||||||
|
||||||
const fromZigbee: Fz.Converter[] = [ | ||||||
{ | ||||||
cluster: 'genBasic', | ||||||
type: ['attributeReport', 'readResponse'], | ||||||
convert: (model, msg, publish, options, meta) => { | ||||||
if (Object.prototype.hasOwnProperty.call(msg.data, attribute)) { | ||||||
console.log(`from `, msg.data[attribute]); | ||||||
const value = Math.round(msg.data[attribute] / 5.1); | ||||||
return { | ||||||
minimumPWM: value, | ||||||
}; | ||||||
} | ||||||
return undefined; | ||||||
}, | ||||||
}, | ||||||
]; | ||||||
|
||||||
const toZigbee: Tz.Converter[] = [ | ||||||
{ | ||||||
key: ['minimumPWM'], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
convertSet: async (entity: Zh.Endpoint, key: string, value: number | string, meta) => { | ||||||
console.log(`to `, value); | ||||||
const numValue = typeof value === 'string' ? parseInt(value) : value; | ||||||
const zgValue = Math.round(numValue * 5.1); | ||||||
await entity.write('genBasic', {[attribute]: {value: zgValue, type: dataType}}, {manufacturerCode: sunricherManufacturerCode}); | ||||||
return {state: {minimumPWM: numValue}}; | ||||||
}, | ||||||
convertGet: async (entity: Zh.Endpoint, key: string, meta) => { | ||||||
await entity.read('genBasic', [attribute], {manufacturerCode: sunricherManufacturerCode}); | ||||||
}, | ||||||
}, | ||||||
]; | ||||||
|
||||||
const exposes: Expose[] = [ | ||||||
e | ||||||
.numeric('minimumPWM', ea.ALL) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.withLabel('Minimum PWM') | ||||||
.withDescription('Power off the device and wait for 3 seconds before reconnecting to apply the settings.') | ||||||
.withValueMin(0) | ||||||
.withValueMax(50) | ||||||
.withUnit('%') | ||||||
.withValueStep(1), | ||||||
]; | ||||||
|
||||||
const onEvent: OnEvent = async (type, data, device) => { | ||||||
await readAttributeIfOnline(type, data, device, attribute); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these only need to be read one time after the device has joined? If yes, put them in a |
||||||
}; | ||||||
|
||||||
return { | ||||||
fromZigbee, | ||||||
toZigbee, | ||||||
exposes, | ||||||
onEvent, | ||||||
isModernExtend: true, | ||||||
}; | ||||||
} | ||||||
|
||||||
const fzLocal = { | ||||||
sunricher_SRZGP2801K45C: { | ||||||
cluster: 'greenPower', | ||||||
|
@@ -378,7 +515,7 @@ const definitions: DefinitionWithExtend[] = [ | |||||
model: 'SR-ZG9040A/ZG9041A-D', | ||||||
vendor: 'Sunricher', | ||||||
description: 'Zigbee micro smart dimmer', | ||||||
extend: [light({configureReporting: true}), electricityMeter()], | ||||||
extend: [light({configureReporting: true}), electricityMeter(), sunricherExternalSwitchType(), sunricherMinimumPWM()], | ||||||
}, | ||||||
{ | ||||||
zigbeeModel: ['HK-ZD-DIM-A'], | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make all
snake_case
, alsovalueLookup
below