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

Clearing deactivated options #33

Open
pulpman52 opened this issue Dec 9, 2024 · 0 comments
Open

Clearing deactivated options #33

pulpman52 opened this issue Dec 9, 2024 · 0 comments

Comments

@pulpman52
Copy link

I am sorry if this is not the correct use of Issues. I have seen other drivers in Hubitat clear the unused attributes periodically. I think your app can do the same thing but i am not familiar enough with Groovy to confidently update anything. I think something like this could work but will defer to you.

// Method to clear and remove optional attributes from "Current States"
// This ensures that unused attributes do not clutter the dashboard or remain visible when settingEnable is turned off.
def clearOptionalAttributes(attributeList) {
attributeList.each { attributeName ->
// Set the attribute value to null to indicate it's no longer active
sendEvent(name: attributeName, value: null, displayed: false)

    // Remove the attribute from the device's current state if it exists
    if (device.hasAttribute(attributeName)) {
        device.removeCurrentState(attributeName)
    }
}
// Log the cleared attributes for debugging and confirmation
log.info "Cleared optional attributes: ${attributeList.join(', ')}"

}

// Method that runs whenever preferences are updated (e.g., toggling settingEnable)
// This handles cleanup of optional attributes and reinitializes active ones.
def updated() {
// Log that preferences have been updated to track when this method runs
log.info "Preferences updated. Checking optional attributes..."

// If the toggle for displaying all optional attributes is turned OFF
if (!settingEnable) {
    // Retrieve the list of all optional attributes from the attributesMap keys
    def optionalAttributes = attributesMap.keySet().toList()
    
    // Clear all optional attributes to ensure they are no longer visible or active
    clearOptionalAttributes(optionalAttributes)
}

// Reinitialize active attributes (if any) based on current preferences
// This is optional but useful for restoring visible attributes when toggling settingEnable ON
initializeAttributes()

}

// Example method to initialize optional attributes when settingEnable is ON
// This ensures that attributes are re-added with default or placeholder values as needed.
def initializeAttributes() {
// Only proceed if settingEnable is ON
if (settingEnable) {
// Iterate through all attributes in attributesMap
attributesMap.each { keyname, attribute ->
// Example initialization: Send a placeholder value for each attribute
// Replace "Example Value" with actual logic for populating the attribute
sendEvent(name: keyname, value: "Example Value")
}
}
}

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

No branches or pull requests

1 participant