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

Feature Request: Add pointer in HABaseDeviceType to a generic struct (or class) #10

Closed
JacobChrist opened this issue May 21, 2023 · 3 comments

Comments

@JacobChrist
Copy link

I would be nice if the HABaseDeviceType class had a pointer to a struct (or class) that could be used to hold arbitrary data per users need. This would allow adding information that could be retrieved by a generic handler. This would allow you to do things like this:

class ZoneData {
    public:
        uint8_t led_pin;
        uint8_t ssr_pin;
};

void HAIntegration::switchHandler(bool state, HASwitch* sender) {
    digitalWrite(((ZoneData)sender->data).led_pin, (state ? HIGH : LOW));
    digitalWrite(((ZoneData)sender->data).ssr_pin, (state ? HIGH : LOW));
    sender->setState(state);  // report state back to Home Assistant
}
@daniloc
Copy link
Owner

daniloc commented May 21, 2023

Thanks for checking in! I believe this would be more productively addressed by Arduino Home Assistant, the library responsible for that class:

https://github.com/dawidchyrzynski/arduino-home-assistant
https://github.com/dawidchyrzynski/arduino-home-assistant/blob/main/src/device-types/HABaseDeviceType.h

@daniloc daniloc closed this as completed May 21, 2023
@JacobChrist
Copy link
Author

I agree, I'm only now realizing that your project is dependent on that library. I've never used VS Code for embedded development so I'm learning a few things right now.

@JacobChrist
Copy link
Author

I have opened this issue on the arduino-home-assistant repo: dawidchyrzynski/arduino-home-assistant#168

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

2 participants