The library definition provides the Hubitat Elevation hub with information about the library, which can be added to Libraries Code in the hub Developer Tools. Libraries provide a way to share code among multiple apps or drivers by defining a library with variables, methods, etc. just as they would appear in app/driver:
library ( author: "myName", category: "samples", description: "Some description", name: "SampleLibrary1", namespace: "myNamespace", documentationLink: "http://www.example.com/" ) // put methods, etc. here
namespace can include only letters (upper or lower case), numbers, dots, dashes, and underscores. It is recommended the namespace be unique to you as a developer. All name plus namespace combinations must be unique for each library on a given hub. The
description parameters are the only required parameters at this time, thoguh the additional parameters may be used in the future.
To use a library in an app or driver, begin a line with
#include (no spaces are allowed before the
# symbol), followed by a space, the library namesapce, a period, and the library name. For example, to include the above library, write the following line in app or driver code:
When the app or driver is saved, the “included” code will be inserted behind the scenes automatically. You can select the download icon (downward arrow) next to Import button in the Apps Code or Drivers Code editor to see exactly how the included code appears in the final the source code. You can also use this feature to download a full version for distribution to others if you do not want to share the app/driver and library code separately. The full code may also be helpful for troubleshooting errors in logs that refer to specific line numbers, etc.
All apps/drivers using a library are recompiled when the library is changed.