From 9b791e2ac349edeea02535ee5a022024524a734a Mon Sep 17 00:00:00 2001 From: HomeSpan Date: Wed, 26 Jun 2024 21:00:52 -0500 Subject: [PATCH 1/2] Update Reference.md --- docs/Reference.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/Reference.md b/docs/Reference.md index 4673c7c..94076b3 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -386,11 +386,15 @@ The following methods are supported: * note that Linked Services are only applicable for select HAP Services. See Apple's HAP-R2 documentation for full details * example: `(new Service::Faucet)->addLink(new Service::Valve)->addLink(new Service::Valve);` (links two Valves to a Faucet) -* `vector getLinks()` - * returns a vector of pointers to Services that were added using `addLink()` - * useful for creating loops that iterate over all linked Services - * note that the returned vector points to generic SpanServices, which should be re-cast as needed - * example: `for(auto myValve : faucet->getLinks()) { if((MyValve *)myValve)->active->getVal()) ... }` checks all Valves linked to a Faucet +* `vector getLinks(const char *serviceName=NULL)` + * template function that returns a vector of pointers to Services that were added using `addLink()` + * if template parameter, *T*, is left blank, the elements of the returned vector will be of type *SpanService \** + * if template parameter, *T*, is specified, the elements of the returned vector will be cast into type *T* + * if *serviceName* is specified, only those services matching *serviceName* will be included in the return vector + * *serviceName* must be one of HomeSpan's built-in Services (e.g. "Valve") + * if *serviceName* is left blank or set to NULL, all services will be included in the return vector + * this function is useful for creating loops that iterate over all linked Services + * example: from within a Faucet Service containing linked Valves defined in *MyValveService*, use `for(auto valve : getLinks()) { if(valve->active->getVal()) ... }` to check which Valves are active * `virtual boolean update()` * HomeSpan calls this method upon receiving a request from a HomeKit Controller to update one or more Characteristics associated with the Service. Users should override this method with code that implements that requested updates using one or more of the SpanCharacteristic methods below. Method **must** return *true* if update succeeds, or *false* if not. From 970f4d7ce8bda866cfd940cf9df81b7677dca336 Mon Sep 17 00:00:00 2001 From: HomeSpan Date: Wed, 26 Jun 2024 21:14:23 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6853dd5..eee7595 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,11 @@ HomeSpan is currently NOT compatible with version 3.X of the Arduino-ESP32 Board * a warning message is output on the Serial Monitor if `setVal()` is called to change the value of a Characteristic from within the `update()` method at the same time the Home App is sending an update request for that value * does not apply if `setVal()` is called from within `update()` to change the value of a Characteristic in response to a *write-response* request from the Home App +* **Converted the `getLinks()` SpanService method to a template function** + * allows user to automatically cast the elements of the returned vector into any specific Service type + * also adds an optional parameter to restrict the elements of the returned vector to match a specified HomeSpan Service + * see the [API Reference](docs/Reference.md) for details + * **Refactored client/slot management to save memory and prepare for future integration of Ethernet support** * fixed-array of Client/Socket connections replaced by dynamic linked-list * serial interface now only shows active client connections (rather than a fixed list of client slots)