Skip to content

Clean some deps and use native#2423

Open
bertrandda wants to merge 13 commits intoGladysAssistant:masterfrom
bertrandda:deps/use-native
Open

Clean some deps and use native#2423
bertrandda wants to merge 13 commits intoGladysAssistant:masterfrom
bertrandda:deps/use-native

Conversation

@bertrandda
Copy link
Copy Markdown
Contributor

@bertrandda bertrandda commented Jan 28, 2026

Pull Request check-list

To ensure your Pull Request can be accepted as fast as possible, make sure to review and check all of these items:

  • If your changes affect the code, did you write the tests?
  • Are tests passing? (npm test on both front/server)
  • Is the linter passing? (npm run eslint on both front/server)
  • Did you run prettier? (npm run prettier on both front/server)
  • Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to the community (forum) for testing before merging.

NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.

Description of change

Clean some code, remove some dependencies

  • replace uuid by native crypto on server side with randomUUID method to generate uuid v4
  • use optional chaining instead of get-value when it's possible
  • use our own debounce function instead of external package
  • remove not used packages (axios in edf service, form-data in server/package.json)

Summary by CodeRabbit

  • Dependencies

    • Front-end dependency updates: debounce, preact-router, qrcode.
    • Removed several runtime dependencies and replaced with built-in Node/JS APIs.
  • Bug Fixes

    • Fixed a binding issue affecting integration search behavior.
  • Refactor

    • Replaced deep-property helper usage with native optional chaining and switched UUID generation to Node's crypto for leaner, safer code.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.83%. Comparing base (b3cfa5a) to head (3f53b11).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2423      +/-   ##
==========================================
+ Coverage   98.81%   98.83%   +0.02%     
==========================================
  Files        1009     1009              
  Lines       17670    17647      -23     
==========================================
- Hits        17460    17441      -19     
+ Misses        210      206       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@relativeci
Copy link
Copy Markdown

relativeci bot commented Jan 28, 2026

#4132 Bundle Size — 11.43MiB (-0.03%).

3f53b11(current) vs b3cfa5a master#4120(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Improvement 1 improvement
                 Current
#4132
     Baseline
#4120
Improvement  Initial JS 6.41MiB(-0.05%) 6.42MiB
No change  Initial CSS 310.54KiB 310.54KiB
Change  Cache Invalidation 65.69% 0%
No change  Chunks 51 51
No change  Assets 179 179
No change  Modules 1643 1643
No change  Duplicate Modules 21 21
No change  Duplicate Code 0.94% 0.94%
No change  Packages 136 136
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#4132
     Baseline
#4120
Improvement  JS 8.31MiB (-0.04%) 8.32MiB
No change  IMG 2.68MiB 2.68MiB
No change  CSS 328.39KiB 328.39KiB
No change  Fonts 93.55KiB 93.55KiB
No change  Other 18.82KiB 18.82KiB
No change  HTML 13.58KiB 13.58KiB

Bundle analysis reportBranch bertrandda:deps/use-nativeProject dashboard


Generated by RelativeCIDocumentationReport issue

@bertrandda bertrandda changed the title [WIP] Clean some deps and use native Clean some deps and use native Jan 28, 2026
Copy link
Copy Markdown
Contributor

@Pierre-Gilles Pierre-Gilles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR! Great cleanup :)

I have a comment on the debounce change.

* @param {number} wait - The number of milliseconds to delay
* @returns {Function} The debounced function
*/
export default function debounce(func, wait) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the benefit of bundling the code of an external dependency directly into Gladys?

I agree that some dependencies can be heavy or unnecessary, but in this case, it’s a perfect example of a small, reliable, and well-maintained dependency 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main benefits of native instead of third party package is supply chain security (we see that a lot here or more recently axios) and time to install for CI, dev environment...
Because it does not contain any sub-dependency ans with debounce size + npm cache, it's maybe not relevant in this case. I rollback this part

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df626688-7a60-4502-b624-cf17402206b3

📥 Commits

Reviewing files that changed from the base of the PR and between ec89420 and 3f53b11.

📒 Files selected for processing (1)
  • front/src/routes/settings/settings-system/SettingsSystemBatteryLevelWarning.jsx
✅ Files skipped from review due to trivial changes (1)
  • front/src/routes/settings/settings-system/SettingsSystemBatteryLevelWarning.jsx

📝 Walkthrough

Walkthrough

Removed usages of get-value and uuid across the codebase; replaced deep property reads with optional chaining and switched UUID generation to Node's crypto.randomUUID(). Updated several package manifests to drop dependencies, bumped a few frontend deps, and bound two debounced frontend handlers to preserve this.

Changes

Cohort / File(s) Summary
Package manifests
front/package.json, server/package.json, server/services/alexa/package.json, server/services/edf-tempo/package.json, server/services/enedis/package.json, server/services/energy-monitoring/package.json, server/services/homekit/package.json, server/services/melcloud/package.json, server/services/nextcloud-talk/package.json, server/services/tasmota/package.json, server/services/telegram/package.json
Removed get-value and/or uuid from many service manifests; bumped frontend deps (debounce, preact-router, qrcode) in front/package.json.
Gateway & message handlers (optional chaining)
server/lib/gateway/..., server/lib/gateway/enedis/..., server/services/alexa/lib/..., server/services/melcloud/lib/..., server/services/nextcloud-talk/lib/...
Replaced get(...) deep reads and error-status extractions with optional chaining (e.g., e?.response?.status, body?.directive?.header) without altering control flow.
Device & system libs (optional chaining)
server/lib/device/device.notify.js, server/lib/device/device.poll.js, server/lib/device/device.setValue.js, server/lib/system/system.getContainers.js, server/lib/system/system.getNetworkMode.js, server/utils/device.js
Replaced get(...) lookups with ?. access for nested device/system properties and existence checks.
UUID → crypto.randomUUID() replacements
server/lib/scene/scene.addScene.js, server/lib/user/user.create.js, server/services/energy-monitoring/utils/addEnergyFeatures.js, server/services/homekit/lib/createBridge.js, server/services/nextcloud-talk/lib/message/message.new.js, server/services/nextcloud-talk/lib/message/message.send.js, server/services/telegram/lib/message.new.js, server/services/alexa/..., server/test/...
Replaced uuid.v4() usages with crypto.randomUUID() and updated imports/usages across services and tests.
Alexa forwarding & tests
server/lib/gateway/gateway.forwardDeviceStateToAlexa.js, server/test/lib/gateway/gateway.forwardDeviceStateToAlexa.test.js
Replaced dynamic get(...) path resolution with optional chaining for func/mapping/message fields; switched messageId generation to crypto.randomUUID() and updated tests accordingly.
Frontend: debounced handlers
front/src/routes/integration/index.js, front/src/routes/settings/settings-system/SettingsSystemBatteryLevelWarning.jsx
Bound debounced functions with .bind(this) so component methods run with the correct this when invoked after the debounce delay.
Tests
server/test/lib/..., server/test/services/alexa/lib/...
Updated tests to use optional chaining in assertions and crypto.randomUUID() for generated IDs; added a gateway.getUsersKeys error-path test.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Pierre-Gilles

Poem

🐰 I hopped through code with nimble feet,
Replaced deep gets with chains so neat.
Crypto seeds now grow IDs anew,
Debounced binds keep handlers true.
A tiny hop — the code feels fleet. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Clean some deps and use native' directly and accurately summarizes the main objective of the PR: removing external dependencies and replacing them with native alternatives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
server/lib/gateway/gateway.forwardDeviceStateToAlexa.js (1)

44-44: Optional chaining may silently produce undefined for a required field.

At line 44, mapping?.properties?.supported?.[0]?.name could evaluate to undefined if the mapping structure is incomplete, resulting in an invalid Alexa payload with name: undefined. Since mapping has already passed the null check on line 34, and the deviceMappings.js structure guarantees properties.supported[0].name exists for all valid mappings, this optional chaining is technically safe but could mask future configuration errors.

Consider whether a direct access (mapping.properties.supported[0].name) with an explicit validation would be preferable for catching misconfigured mappings early.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/lib/gateway/gateway.forwardDeviceStateToAlexa.js` at line 44, The
current use of optional chaining on mapping?.properties?.supported?.[0]?.name
can silently yield undefined; change to direct access
mapping.properties.supported[0].name and add an explicit validation in the
function that builds the Alexa payload (referencing mapping, properties,
supported, and name) to throw or log a clear error when any of
mapping.properties, mapping.properties.supported,
mapping.properties.supported[0], or mapping.properties.supported[0].name is
missing so misconfigured mappings fail fast instead of producing an invalid
Alexa payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@front/package.json`:
- Line 72: Upgrading preact-router to v4 breaks use of the removed
activeClassName prop and may change route() behavior; search for all usages of
the activeClassName prop (e.g., in SettingsLayout, IntegrationMenu, header and
other Link components) and replace them by either: (a) using the :local-link CSS
pseudo-class to style active links, (b) creating a small wrapper Link/NavLink
component that computes active state and applies the previous class name, or (c)
managing active state manually where needed; for programmatic navigation, audit
every call to the global route() function and either adapt calls to the new v4
API or implement a thin compatibility wrapper function named route(path,
replace?) that delegates to the new router/history API while preserving the
boolean second-parameter “replace” behavior so existing call sites continue to
work.
- Line 59: In SettingsSystemBatteryLevelWarning.jsx the debounced method
debouncedUpdateBatteryLevelUnderWarningThreshold is created without binding so
its this is incorrect; update the declaration to call .bind(this) on the
debounced function (i.e., wrap
debounce(this.updateBatteryLevelUnderWarningThreshold, 200).bind(this)) so the
instance context is preserved when debouncing
updateBatteryLevelUnderWarningThreshold, matching the pattern used elsewhere.

---

Nitpick comments:
In `@server/lib/gateway/gateway.forwardDeviceStateToAlexa.js`:
- Line 44: The current use of optional chaining on
mapping?.properties?.supported?.[0]?.name can silently yield undefined; change
to direct access mapping.properties.supported[0].name and add an explicit
validation in the function that builds the Alexa payload (referencing mapping,
properties, supported, and name) to throw or log a clear error when any of
mapping.properties, mapping.properties.supported,
mapping.properties.supported[0], or mapping.properties.supported[0].name is
missing so misconfigured mappings fail fast instead of producing an invalid
Alexa payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb5219d2-2aa5-4dd0-aba9-6c4f868d0250

📥 Commits

Reviewing files that changed from the base of the PR and between b3cfa5a and 2dad783.

⛔ Files ignored due to path filters (11)
  • front/package-lock.json is excluded by !**/package-lock.json
  • server/package-lock.json is excluded by !**/package-lock.json
  • server/services/alexa/package-lock.json is excluded by !**/package-lock.json
  • server/services/edf-tempo/package-lock.json is excluded by !**/package-lock.json
  • server/services/enedis/package-lock.json is excluded by !**/package-lock.json
  • server/services/energy-monitoring/package-lock.json is excluded by !**/package-lock.json
  • server/services/homekit/package-lock.json is excluded by !**/package-lock.json
  • server/services/melcloud/package-lock.json is excluded by !**/package-lock.json
  • server/services/nextcloud-talk/package-lock.json is excluded by !**/package-lock.json
  • server/services/tasmota/package-lock.json is excluded by !**/package-lock.json
  • server/services/telegram/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (51)
  • front/package.json
  • front/src/routes/integration/index.js
  • server/lib/device/device.notify.js
  • server/lib/device/device.poll.js
  • server/lib/device/device.setValue.js
  • server/lib/gateway/enedis/gateway.enedisGetConsumptionLoadCurve.js
  • server/lib/gateway/enedis/gateway.enedisGetDailyConsumption.js
  • server/lib/gateway/enedis/gateway.enedisGetDailyConsumptionMaxPower.js
  • server/lib/gateway/gateway.forwardDeviceStateToAlexa.js
  • server/lib/gateway/gateway.getBackups.js
  • server/lib/gateway/gateway.getTTSApiUrl.js
  • server/lib/gateway/gateway.getUsersKeys.js
  • server/lib/gateway/gateway.handleAlexaMessage.js
  • server/lib/gateway/gateway.handleGoogleHomeMessage.js
  • server/lib/gateway/gateway.handleNewMessage.js
  • server/lib/gateway/gateway.login.js
  • server/lib/gateway/gateway.openAIAsk.js
  • server/lib/scene/scene.addScene.js
  • server/lib/system/system.getContainers.js
  • server/lib/system/system.getNetworkMode.js
  • server/lib/user/user.create.js
  • server/package.json
  • server/services/alexa/lib/alexa.onDiscovery.js
  • server/services/alexa/lib/alexa.onExecute.js
  • server/services/alexa/lib/alexa.onReportState.js
  • server/services/alexa/lib/syncDeviceConverter.js
  • server/services/alexa/package.json
  • server/services/edf-tempo/package.json
  • server/services/enedis/package.json
  • server/services/energy-monitoring/package.json
  • server/services/energy-monitoring/utils/addEnergyFeatures.js
  • server/services/homekit/lib/createBridge.js
  • server/services/homekit/package.json
  • server/services/melcloud/lib/device/melcloud.convertDevice.js
  • server/services/melcloud/package.json
  • server/services/nextcloud-talk/lib/bot/bot.poll.js
  • server/services/nextcloud-talk/lib/message/message.new.js
  • server/services/nextcloud-talk/lib/message/message.send.js
  • server/services/nextcloud-talk/package.json
  • server/services/tasmota/package.json
  • server/services/telegram/lib/message.new.js
  • server/services/telegram/package.json
  • server/test/lib/device/device.migrateFromSQLiteToDuckDb.test.js
  • server/test/lib/device/device.purgeAllSqliteStates.test.js
  • server/test/lib/device/device.purgeStatesByFeatureId.test.js
  • server/test/lib/gateway/gateway.forwardDeviceStateToAlexa.test.js
  • server/test/lib/gateway/gateway.getUsersKeys.test.js
  • server/test/services/alexa/lib/alexa.onDiscovery.test.js
  • server/test/services/alexa/lib/alexa.onExecute.test.js
  • server/test/services/alexa/lib/alexa.onReportState.test.js
  • server/utils/device.js
💤 Files with no reviewable changes (3)
  • server/services/edf-tempo/package.json
  • server/services/enedis/package.json
  • server/package.json

@bertrandda bertrandda requested a review from Pierre-Gilles April 5, 2026 22:21
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