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

Enable Multiple Endpoints and Device Types in Device Composition Insertion #1489

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

paulr34
Copy link
Collaborator

@paulr34 paulr34 commented Nov 21, 2024

Pull Request Summary
Title: Enable Multiple Endpoints and Device Types in Device Composition Insertion

Description:

This update enhances the insertDeviceComposition function to support multiple endpoints and multiple device types (deviceType) per endpoint. Previously, the code could only insert data for a single endpoint and device type.

Key Changes:

Multiple Endpoints: The function now processes all endpoints in deviceType.composition.endpoint, inserting data for each.
Multiple Device Types per Endpoint: Supports inserting multiple deviceType values per endpoint.
Dynamic Conformance and Constraint: Uses endpoint-specific conformance and constraint values when available, with fallbacks to default deviceType values.
Improved Error Handling: Ensures required data is present and correctly formatted, preventing errors.
Benefits:

Scalability: Handles more complex device compositions with multiple endpoints and device types.
Flexibility: Supports a wider range of device configurations.
Data Integrity: Ensures correct insertion of data for each endpoint and device type.
This update improves flexibility and scalability for device composition handling.

@paulr34 paulr34 changed the title Multiple endpoints composition Enable Multiple Endpoints and Device Types in Device Composition Insertion Nov 21, 2024
Copy link
Collaborator

@dhchandw dhchandw left a comment

Choose a reason for hiding this comment

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

We could add a test for this particular type of composed device type

Copy link
Collaborator

@tecimovic tecimovic left a comment

Choose a reason for hiding this comment

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

Generally ok, but do please clean up some of those syntactic sugar thingies.... We should write modern code.

// Ensure that deviceType and its necessary properties are defined
if (
!deviceType ||
!deviceType.composition ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't you use the ?. operator here?

Like !(devicetype?.composition?.endpoint) ?

// Create insert queries for each deviceType in this endpoint and add them to the insertQueries array
for (let j = 0; j < deviceTypes.length; j++) {
const device = deviceTypes[j]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not:

   for ( let device of deviceTypes) { 
      ...
   }

I don't think you're using the actual index anywhere, and while there is something cozy about the good old fashioned 1960's C-like for loop, it is visually more taxing than modern JS.

@tecimovic
Copy link
Collaborator

Obviously I'm assuming that you tested this well with both Matter and Zigbee, and that you promise you will write unit tests for it!

@paulr34 paulr34 force-pushed the multipleEndpointsComposition branch from 1da59a6 to f71d922 Compare November 22, 2024 03:25
@paulr34 paulr34 merged commit 3879080 into project-chip:master Nov 22, 2024
13 checks passed
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.

4 participants