Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

return GUI data for selected endpoint and not just the first one in the list #1520

Merged
merged 9 commits into from
Feb 14, 2025
68 changes: 68 additions & 0 deletions cypress/e2e/attribute_validations/reporting.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/// <reference types="cypress" />

Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from failing the test
return false
})

describe('Add multiple clusters and search', () => {
// This will hold the fixture data and the flag for skipping the tests
let skipTest = false

before(function () {
// Load the fixture data before running any tests
cy.fixture('data').then((data) => {
this.data = data
// If mode is "matter", set skipTest flag to true
if (this.data.mode === 'matter') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better to run it for zigbee than not matter. If a new protocol does not have attribute reporting then this test will fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure good idea

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, thank you

skipTest = true
}
})
})

it('create two endpoints and validate basic information', function () {
// Skip the test if the flag is true (mode is "matter")
if (skipTest) {
cy.log('Skipping test because mode is "matter"')
return // Skip the test if mode is 'matter'
}

// Continue with the test if the mode is not "matter"
cy.fixture('baseurl').then((data) => {
cy.visit(data.baseurl)
})
cy.setZclProperties()

// Create and validate the first endpoint
cy.fixture('data').then((data) => {
cy.addEndpoint(data.endpoint4, data.cluster1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not understand this as I am not familiar with what is happening here. Comment says first endpoint and cy.addEndpoint(data.endpoint4, data.cluster1) says data.endpoint4

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, this is just how cypress is setup for all tests but I agree it should be fixed and cleaned up. I will work on a follow up PR to fix Cypress in general

})
cy.get('.flex > strong').should('contain', '#1')

// Select the "Power Configuration" cluster for the second endpoint
cy.fixture('data').then((data) => {
cy.gotoAttributePage(data.endpoint1, data.cluster1)
cy.contains('.q-item__section .q-item__label', 'General', {
timeout: 10000
})
.should('be.visible')
.click()
})

// Check the "Attribute Reporting" tab for the second endpoint
cy.fixture('data').then((data) => {
cy.contains('.q-tab__content .q-tab__label', 'Attribute Reporting', {
timeout: 10000
})
.should('be.visible')
.click()
})
cy.get(
'.q-virtual-scroll__content > :nth-child(1) > :nth-child(2) > .q-toggle > .q-toggle__inner > .q-toggle__thumb'
).click()
// Check to make sure the button is still visible after clicking
cy.get(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope this test does not just get the next item in the list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm sorry I'm confused what you mean here

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just don't really know how this checks in the UI when an attribute vanishes. If there are 2 attributes in the attribute reporting and one of them vanishes then does the second one just show up in the first one's place and pass this test?
Is it better to test by checking the number of attributes in attribute reporting before and after enablement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, it gets a specific one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't just get the first one in the list but I will triple check

'.q-virtual-scroll__content > :nth-child(1) > :nth-child(2) > .q-toggle > .q-toggle__inner > .q-toggle__thumb'
).should('be.visible')
})
})
7 changes: 3 additions & 4 deletions src-electron/rest/user-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ function httpPostAttributeUpdate(db) {
let {
action,
endpointTypeIdList,
selectedEndpoint,
id,
value,
listType,
Expand All @@ -398,7 +399,6 @@ function httpPostAttributeUpdate(db) {
reportMaxInterval,
reportableChange
} = request.body

if (!Array.isArray(endpointTypeIdList) || !endpointTypeIdList.length) {
return response.status(StatusCodes.BAD_REQUEST).json()
}
Expand Down Expand Up @@ -434,11 +434,10 @@ function httpPostAttributeUpdate(db) {
)
)
)

// send latest value to frontend to update UI
let eptAttr = await queryZcl.selectEndpointTypeAttribute(
db,
endpointTypeIdList[0],
selectedEndpoint,
id,
clusterRef
)
Expand All @@ -448,7 +447,7 @@ function httpPostAttributeUpdate(db) {
// endpointTypeId doesn't matter since all attributes are the seame.
let validationData = await validation.validateAttribute(
db,
endpointTypeIdList[0],
selectedEndpoint,
id,
clusterRef,
request.zapSessionId
Expand Down
9 changes: 6 additions & 3 deletions src/util/editable-attributes-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default {
let editContext = {
action: 'boolean',
endpointTypeIdList: this.endpointTypeIdList,
selectedEndpoint: this.selectedEndpointTypeId,
id: attributeData.id,
value: enable,
listType: listType,
Expand Down Expand Up @@ -181,6 +182,7 @@ export default {
let editContext = {
action: 'text',
endpointTypeIdList: this.endpointTypeIdList,
selectedEndpoint: this.selectedEndpointTypeId,
id: attributeData.id,
value: newValue,
listType: listType,
Expand All @@ -191,7 +193,7 @@ export default {
}
this.$store.dispatch('zap/updateSelectedAttribute', editContext)
},
async toggleAttributeSelection(list, listType, attributeData, clusterId) {
toggleAttributeSelection(list, listType, attributeData, clusterId) {
// We determine the ID that we need to toggle within the list.
// This ID comes from hashing the base ZCL attribute and cluster data.
let indexOfValue = list.indexOf(
Expand All @@ -213,6 +215,7 @@ export default {
let editContext = {
action: 'boolean',
endpointTypeIdList: this.endpointTypeIdList,
selectedEndpoint: this.selectedEndpointTypeId,
id: attributeData.id,
value: addedValue,
listType: listType,
Expand All @@ -222,15 +225,15 @@ export default {
reportMaxInterval: attributeData.reportMaxInterval
}
// Wait for the first dispatch to complete
await this.$store.dispatch('zap/updateSelectedAttribute', editContext)
this.$store.dispatch('zap/updateSelectedAttribute', editContext)

if (
addedValue &&
listType === 'selectedAttributes' &&
attributeData.isReportable
) {
editContext.listType = 'selectedReporting'
await this.$store.dispatch('zap/updateSelectedAttribute', editContext)
this.$store.dispatch('zap/updateSelectedAttribute', editContext)
}
},

Expand Down