Difference between revisions of "Library Definition"

From Hubitat Documentation
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
=Overview=
 
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:
 
<code>library (
 
  author: "myName",
 
  category: "samples",
 
  description: "Some description",
 
  name: "SampleLibrary1",
 
  namespace: "myNamespace",
 
  documentationLink: "<nowiki>http://www.example.com/</nowiki>"
 
)</code>
 
 
<code>// put methods, etc. here</code>
 
The <code>name</code> and <code>namespace</code> 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.
 
  
A typical use for a library is to define methods, fields, etc. that you may wish to share among multiple apps or drivers.
+
<big>'''We're moving!''' Please visit http://docs2.hubitat.com for the latest documentation.</big>
  
==Using Libraries in Apps or Drivers==
+
<big>
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:
+
This document is available at: http://docs2.hubitat.com/en/developer/library-definition
 
+
</big>
<code>#include myNamespace.SampleLibrary1</code>
 
 
 
When the app or driver is saved, the “included” code will be substituted behind the scenes. All apps/drivers using a library are recompiled when the library is changed. You can select the download icon next to '''Import''' button to see ''exactly'' how the include gets into the source code (or to download a full version for distribution if you do not want to share the app/driver and library code separately).
 

Latest revision as of 19:42, 25 September 2022

We're moving! Please visit http://docs2.hubitat.com for the latest documentation.

This document is available at: http://docs2.hubitat.com/en/developer/library-definition