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

feat!: Refactor calibrate and precision round options #6769

Merged
merged 6 commits into from
Dec 26, 2023

Conversation

Koenkk
Copy link
Owner

@Koenkk Koenkk commented Dec 25, 2023

  • Detect calibrate/precision options from exposes (and remove options from converters)
  • Do calibration/precision round as a post process step instead of in converters

This simplifies the code and improves consistency

TODO:

  • Update Z2M to call postProcessFromZigbeeMessage
  • Run docgen to see if anything was missed

CC: @sjorge @kirovilya

@Koenkk Koenkk marked this pull request as draft December 25, 2023 14:00
@sjorge
Copy link
Contributor

sjorge commented Dec 25, 2023

can we also add a generic 'postProcessing' hook to modernExtends (ideally an list of ones to process in order) ?
Ideally the calibration one is inserted at the end of the list we get from the modernExtend.

That should make things like

SNZB02_temperature: {
cluster: 'msTemperatureMeasurement',
type: ['attributeReport', 'readResponse'],
options: [exposes.options.precision('temperature'), exposes.options.calibration('temperature')],
convert: (model, msg, publish, options, meta) => {
const temperature = parseFloat(msg.data['measuredValue']) / 100.0;
// https://github.com/Koenkk/zigbee2mqtt/issues/13640
// SNZB-02 reports stranges values sometimes
if (temperature > -33 && temperature < 100) {
const property = postfixWithEndpointName('temperature', msg, model, meta);
return {[property]: calibrateAndPrecisionRoundOptions(temperature, options, 'temperature')};
}
},
} satisfies Fz.Converter,
obsolete, as this would then be a simple postProcessing function that rejects those values and be done :)

@Koenkk
Copy link
Owner Author

Koenkk commented Dec 26, 2023

I think for these case we need to be able to pass a custom from/to conversion method to the numeric extend

@Koenkk Koenkk marked this pull request as ready for review December 26, 2023 19:19
@Koenkk Koenkk changed the title fix(ignore): Refactor calibrate and precision round options feat!: Refactor calibrate and precision round options Dec 26, 2023
@Koenkk Koenkk merged commit 204ee90 into master Dec 26, 2023
3 checks passed
@Koenkk Koenkk deleted the feat/refactor_calibration_and_precision_round branch December 26, 2023 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants