-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Local update #154
Local update #154
Conversation
* origin/main: Bump openid-client from 5.6.4 to 5.6.5 (Apollon77#133) Bump follow-redirects from 1.15.4 to 1.15.6 (Apollon77#132) Bump jose from 4.15.4 to 4.15.5 (Apollon77#130) Update README.md (Apollon77#129) Bump openid-client from 5.6.2 to 5.6.4 (Apollon77#126) Bump follow-redirects from 1.15.3 to 1.15.4 (Apollon77#125) Bump openid-client from 5.6.1 to 5.6.2 (Apollon77#124) * dep updates Bump @alcalzone/release-script from 3.6.0 to 3.7.0 (Apollon77#122) # Conflicts: # package-lock.json # package.json
* origin/main: Changelog ts no semantic versioning and build Re-indent files Switches to Daikin's Onecta API, ports to Typescript (Apollon77#139)
* origin/main: chore: release v2.0.0-alpha.1 gha Changelog and license year Alpha1 Preparations (Apollon77#140) Bump braces from 3.0.2 to 3.0.3 (Apollon77#135) Bump actions/checkout from 3 to 4 (Apollon77#119) Bump actions/setup-node from 3 to 4 (Apollon77#121)
* origin/main: chore: release v2.0.0-alpha.7 make server data optional chore: release v2.0.0-alpha.6 fix chore: release v2.0.0-alpha.5 readme Throw on non-200 status codes (Apollon77#142) chore: release v2.0.0-alpha.4 readme fixes 'OPError: invalid_request (Refresh Token is missing)' due to a regression introduced by snake_case -> camelCase conversion (Apollon77#141) chore: release v2.0.0-alpha.3 Update all devices together and update event chore: release v2.0.0-alpha.2 retweak readme gha concurrency no tokensaver anymore Optimize types/exports, add content type for set
* origin/main: (21 commits) build(deps-dev): bump @alcalzone/release-script from 3.7.0 to 3.8.0 (Apollon77#153) build(deps-dev): bump typescript from 5.5.3 to 5.5.4 (Apollon77#151) chore: release v2.4.0 Allows to ignore the check if a state is writable on setData chore: release v2.3.0 Block API request maximum for 24h and then check again (Apollon77#149) binds to the port provided by the OS if none is provided via config, defaults to 0.0.0.0 as the bind address if none is provided in the config, constructs the redirectUri based bind address and port if none is provided via config (Apollon77#148) chore: release v2.2.0 Block communication in client class when rate limited (Apollon77#147) enhance docs chore: release v2.1.1 * Expose the Rate limit error retryAfter time in the error object chore: release v2.1.0 * Expose the Rate limit error retryAfter time in the error object chore: release v2.0.0 docs chore: release v2.0.0-alpha.9 minimum nodejs 18.2 chore: release v2.0.0-alpha.8 release ... # Conflicts: # .gitignore
I think this PR bundles together things that should be evaluated, tested and merged separately and independently of one another. The changes in While these are desirable changes, they are also most definitely major ones that need to be thoroughly tested on their own and should not be bundled together with the change that brings in Also: of the 11 commits, some date back all the way to 2023. I don't think this is intentional; perhaps this needs to be rebased on the current |
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.
I would agree that we should split that up.
- Adding the setData method and testing could go together
- Changing transpile target to hybrid would be a second thing
@@ -6,6 +6,7 @@ | |||
"contributors": [], | |||
"homepage": "https://github.com/Apollon77/daikin-controller-cloud", | |||
"license": "MIT", | |||
"type": "module", |
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.
Ok I would not like to switch to ESM only ... I am ok with a EMS/CJS hybrid package and I did that for thers too but moving to ESM only I do not like tdh
* @param {boolean} [ignoreWritableCheck=false] Ignore the writable check | ||
* @returns {Promise<Object|boolean>} should return a true - or if a body is returned teh body object (can this happen?) | ||
*/ | ||
setLocalData(managementPoint: any, dataPoint: any, dataPointPath: any, value: any, ignoreWritableCheck = false) { |
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.
why as a public method? Should - when we do that - it shuld not be an internal action whena "set" action was successful , maybe with a special flag to update the internal data? becaise now anyone can manipulate freely the set data .. makes that sense?
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.
This was the reason for the public method:
We could also add an extra parameter to the current setData: onlyLocal: boolean = false but I'm afraid it would complicate the interface of that method.
But I can also agree with adding an extra parameter to the current setData
.
How would you like to name that parameter? Also, I think it should default to the current behaviour (not editing the local data).
async setData(managementPoint: any, dataPoint: any, dataPointPath: any, value: any, ignoreWritableCheck = false, updateLocalData = false) {}
And a follow-up question I then have would be, do we always do the local data update or only when this.#client.requestResource(setPath, setOptions)
does not fail? So something like this:
async setData(managementPoint: any, dataPoint: any, dataPointPath: any, value: any, ignoreWritableCheck = false, updateLocalData = false) {
if (value === undefined) {
value = dataPointPath;
dataPointPath = undefined;
}
if (!this.managementPoints[managementPoint] || !this.managementPoints[managementPoint][dataPoint] || (dataPointPath && !this.managementPoints[managementPoint][dataPoint][dataPointPath])) {
throw new Error('Please provide a valid datapoint definition that exists in the data structure');
}
const dataPointDef = dataPointPath ? this.managementPoints[managementPoint][dataPoint][dataPointPath] : this.managementPoints[managementPoint][dataPoint];
this.#validateData(dataPointDef, value, ignoreWritableCheck);
const setPath = '/v1/gateway-devices/' + this.getId() + '/management-points/' + managementPoint + '/characteristics/' + dataPoint;
const setBody = {
value,
path: dataPointPath
};
const setOptions = {
method: 'PATCH',
body: JSON.stringify(setBody),
headers: {
'Content-Type': 'application/json'
}
} as const;
try {
const response = await this.#client.requestResource(setPath, setOptions);
dataPointDef.value = value;
return response;
} catch (e) {
throw new Error('Error setting value: ' + e.message);
}
}
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.
xI would propose converting the (former) last parameter (ignoreWritableCheck) into an options object and having
boolean (fallback to old) or {ignoreWritableCheck: boolean, updateLocalData: boolean} ... better on the long run.
and yes code like this
setLocalData(managementPoint: any, dataPoint: any, dataPointPath: any, value: any, ignoreWritableCheck = false) { | ||
if (value === undefined) { | ||
value = dataPointPath; | ||
dataPointPath = undefined; |
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.
In this case also the "ignoreWritableCheck" boolen needs to be considered and the value needs to be remapped
Sorry that it tool that long for me to check ... reviewed and added my comments mow. @jacoscaz I honestly squash and merge by default in the meantime - especially for bigger changes as soon as multiple people work on them. Ideally I also rebase anything, but thats just me. Especially for bigger changes with several commits keeping the commit history mostly do not bring too much benefit afterwards but blows up the commit history in the end. With a Squash commit it is more clear what was changed when by whom |
Referring: JeroenVdb/homebridge-daikin-cloud#77
@Apollon77 I added a method where you update the "local" data only and don't send the change you want to update to Daikin. We could also add an extra parameter to the current setData:
onlyLocal: boolean = false
but I'm afraid it would complicate the interface of that method.I also added some tests + test setup (if you want I can also leave this out for now and move it to a separate PR).
Would this be a good approach to do a local update? I think it can be part of this repo?