-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
idea with weekdays programs for tuya-moes thermostats #8009
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -6531,6 +6531,52 @@ const toZigbee2 = { | |
await sendDataPointRaw(entity, dataPoints.moesSchedule, payload); | ||
}, | ||
} satisfies Tz.Converter, | ||
moes_thermostat_program_schedule_v2: { | ||
key: ['program_v2'], | ||
convertSet: async (entity, key, value: any, meta) => { | ||
if (!meta.state.program) { | ||
logger.warning(`Existing program state not set.`, 'zhc:legacy:tz:moes_bht_002'); | ||
return; | ||
} | ||
|
||
/* Merge modified value into existing state and send all over in one go */ | ||
const newProgram = { | ||
// @ts-expect-error ignore | ||
...meta.state.program, | ||
...value, | ||
}; | ||
|
||
const getNumbers = (input: exposes.Text): number[] => { | ||
input.checkPatternMatch(); | ||
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 don't understand what this does, how can 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. aww But maybe you'll suggest where can I make this check? I wanted to try to incapsulate all info inside component but not sure where this information can be used. As I see a lot of this stuff doing in z2m-frontend? 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 would you do a simple regex check here instead of 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 can but main idea was to improve something and provide kind of better incapsulated solution |
||
|
||
const hourTemperature = input.property.split('/'); | ||
const hourMinute = hourTemperature[0].split(':', 2); | ||
const clamp = (value: number, min: number, max: number): number => { | ||
return Math.max(min, Math.min(max, value)); | ||
}; | ||
|
||
return [clamp(parseInt(hourMinute[0]), 0, 23), clamp(parseInt(hourMinute[1]), 0, 59), clamp(parseInt(hourTemperature[1]) * 2, 5, 35)]; | ||
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 here is not needed exception. Clamp is more than enough. |
||
}; | ||
|
||
const payload = getNumbers(newProgram.weekdays_p1) | ||
.concat(getNumbers(newProgram.weekdays_p2)) | ||
.concat(getNumbers(newProgram.weekdays_p2)) | ||
.concat(getNumbers(newProgram.weekdays_p3)) | ||
|
||
.concat(getNumbers(newProgram.weekdays_p4)) | ||
.concat(getNumbers(newProgram.saturday_p1)) | ||
.concat(getNumbers(newProgram.saturday_p2)) | ||
.concat(getNumbers(newProgram.saturday_p3)) | ||
.concat(getNumbers(newProgram.saturday_p4)) | ||
|
||
.concat(getNumbers(newProgram.sunday_p1)) | ||
.concat(getNumbers(newProgram.sunday_p2)) | ||
.concat(getNumbers(newProgram.sunday_p3)) | ||
.concat(getNumbers(newProgram.sunday_p4)); | ||
|
||
await sendDataPointRaw(entity, dataPoints.moesSchedule, payload); | ||
}, | ||
} satisfies Tz.Converter, | ||
moesS_thermostat_system_mode: { | ||
key: ['system_mode'], | ||
convertSet: async (entity, key, value, meta) => { | ||
|
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.
Let's not call it v2 but update the existing one.
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.
It is just draft but if you like the idea I'll change both moes/moesS thermostats for using this one with proper namings
(made pr as draft)