daniloc / PicoW_HomeAssistant_Starter

Everything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
MIT License
198 stars 20 forks source link

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

Closed JacobChrist closed 1 year ago

JacobChrist commented 1 year ago

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 commented 1 year ago

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

JacobChrist commented 1 year ago

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 commented 1 year ago

I have opened this issue on the arduino-home-assistant repo: https://github.com/dawidchyrzynski/arduino-home-assistant/issues/168