.
.
Yet another library I created to simplify HS plugin development HSPI_AKTemplate. [Edit - moved to bitbucket.org]
I created this library while developing AK Smart Device plugin after spending many days (and nights) trying to make sense of example code available. The code was based on famous Moskus sample plugin (and C# ports) and great work of alexdresko . And many any other publicly available source examples I could find in Google.
The main part is the HSPI library, and there's also an example plugin using this lib. Noticeable improvements/extensions and some description:
1. Included base classes in the library which should be extended in the plugin project to provide your plugin specific functionality:
.
.
2. Improved HS connection logic (in HspiBase.cs) - especially important for remote plugins, it doesn't just silently die if there's some connection issue, it will try to reconnect. But it still dies gracefully when HS is shutdown (ShutdownIO)
3. DeviceBase class provides cleaner object oriented (OO) interface for HS Scheduler.Classes.DeviceClass for setting/getting usual properties (i.e. Name, Value, Address, Type, Location/Location2, etc.). Also provided functions for managing Plugin Extra Data (PED) i.e. SavePED<T>, GetPED<T>, DeletePED, etc.
4. Also a lot of code dedicated to using VSPairs and CAPIControl - in StatusPairsDict and DeviceBase class
5. Class TableBuilder - separates all HTML functionality required to build tables from plugin logic. I really dislike (to be polite) the way HTML code is mixed up with plugin logic and C# code, and this bad practice was copied from one plugin to another. With the TableBuilder class developer doesn't need to be concerned about html required to build the table. He (or she) can concentrate on creating plugin logic. Lots of tables in AK Smart Device plugin are built using this class with just a few lines of code.
Useful features:
a. Creating tables in collapse-able slider control
b. Making tables sort-able by clicking on the column header (see My Devices Device List page in my plugin)
c. Two ways to use the class (two examples provided below)
- using TableBuilder directly provides most flexible control over building the table
- using TableData class to create data list for the table and then passing it to static TableBuilder.BuildTable
6. Class PageBuilder - extension of popular class provides some enhancements, i.e.
a. RegisterWebPage - now when building the config page it registers itself with HS and then GetPagePlugin (see example code) uses PageBuilder.findRegisteredPage(page)
b. Some useful helper functions i.e. RadioButtonEnum to Generate jqRadioButton for given Enum type (see post #60, #61 for example code)
c. Sets UsesJqAll = false to avoid importing JS code for all clsJQuery controls by default and then enabling JS only for each used control.
7. Class VariableMap - mapping controls to variable names for ProcessPostUI - for config pages and Triggers/Actions. This mapping links UI controls to corresponding variables to automatically update the variable when control value changes. This mostly eliminates the need for ProcessPostUI functions. See post #35, #36 and #60, #61
8. Some other helper classes, i.e. StopwatchEx, DeviceIdList, MyPairT, etc.
.
Yet another library I created to simplify HS plugin development HSPI_AKTemplate. [Edit - moved to bitbucket.org]
I created this library while developing AK Smart Device plugin after spending many days (and nights) trying to make sense of example code available. The code was based on famous Moskus sample plugin (and C# ports) and great work of alexdresko . And many any other publicly available source examples I could find in Google.
The main part is the HSPI library, and there's also an example plugin using this lib. Noticeable improvements/extensions and some description:
1. Included base classes in the library which should be extended in the plugin project to provide your plugin specific functionality:
.
Derived plugin class | Library base class | Comments |
HSPI | HSPIBase2 | Main class responsible for communication between HS and the plugin |
Your device class | DeviceBase | Base device class wrapper provides cleaner implementation (OO) of Scheduler.Classes.DeviceClass |
Your controller class | ControllerBase | Plugin control code - usually included in HSPI class itself - to keep HSPI class cleaner |
Your config pages | PageBuilder | Extends PageBuilderAndMenu.clsPageBuilder to simplify creating config pages (see notes below) |
2. Improved HS connection logic (in HspiBase.cs) - especially important for remote plugins, it doesn't just silently die if there's some connection issue, it will try to reconnect. But it still dies gracefully when HS is shutdown (ShutdownIO)
3. DeviceBase class provides cleaner object oriented (OO) interface for HS Scheduler.Classes.DeviceClass for setting/getting usual properties (i.e. Name, Value, Address, Type, Location/Location2, etc.). Also provided functions for managing Plugin Extra Data (PED) i.e. SavePED<T>, GetPED<T>, DeletePED, etc.
4. Also a lot of code dedicated to using VSPairs and CAPIControl - in StatusPairsDict and DeviceBase class
5. Class TableBuilder - separates all HTML functionality required to build tables from plugin logic. I really dislike (to be polite) the way HTML code is mixed up with plugin logic and C# code, and this bad practice was copied from one plugin to another. With the TableBuilder class developer doesn't need to be concerned about html required to build the table. He (or she) can concentrate on creating plugin logic. Lots of tables in AK Smart Device plugin are built using this class with just a few lines of code.
Useful features:
a. Creating tables in collapse-able slider control
b. Making tables sort-able by clicking on the column header (see My Devices Device List page in my plugin)
c. Two ways to use the class (two examples provided below)
- using TableBuilder directly provides most flexible control over building the table
- using TableData class to create data list for the table and then passing it to static TableBuilder.BuildTable
6. Class PageBuilder - extension of popular class provides some enhancements, i.e.
a. RegisterWebPage - now when building the config page it registers itself with HS and then GetPagePlugin (see example code) uses PageBuilder.findRegisteredPage(page)
b. Some useful helper functions i.e. RadioButtonEnum to Generate jqRadioButton for given Enum type (see post #60, #61 for example code)
c. Sets UsesJqAll = false to avoid importing JS code for all clsJQuery controls by default and then enabling JS only for each used control.
7. Class VariableMap - mapping controls to variable names for ProcessPostUI - for config pages and Triggers/Actions. This mapping links UI controls to corresponding variables to automatically update the variable when control value changes. This mostly eliminates the need for ProcessPostUI functions. See post #35, #36 and #60, #61
8. Some other helper classes, i.e. StopwatchEx, DeviceIdList, MyPairT, etc.
Comment