[APP][Pro] Better Logic Library - For developers

BLL is Live!

If you are a User and want to know more about how to use the new BLL coding, goto the [APP][Pro] Better Logic Library - For Users Forum Topic.

Part of: Better Logic Library - Just some better logic, variable and library management

Homey’s first real Library: Better Logic Library!

The Better Logic App has a new addition: A library and library management for other apps to consume.

The new Decoder

BLL now has new expression cards, but also a new coding for text arguments within flowcards.
For instance, when you place this within a textargument: Hello, today is {[date("dddd")]}, BLL will automaticly find those expressions within the texts and decode/execute them.

Users currently have access to lodash, mathjs and basic javascript commands.
But also the custom DateTime and Number module.
A user can for instance use this within the Save Image Token flowcard from the FTP Client App.
image
This image will be saved with the custom timestamp the user writes himself.

Users can also add there own custom functions within the Better Logic App Settings, which they then can use in all Apps, yours too!

NPM modules can be loaded from BLL, which reduces the installation time and size of your App.

Currenty you can load the next NPM’s

  • math.js 11.3.3
  • lodash 4.17.21.

Basis for your settings

Currently you can reference to the next files in Settings or (Re)Pair screens:

  • Bootstrap 5.3.0
    …/net.i-dev.betterlogic/assets/css/bootstrap.min.css
    …/net.i-dev.betterlogic/assets/js/bootstrap.bundle.min.js
  • Font Awesome (Solid and Regular) 6.2.0
    …/net.i-dev.betterlogic/assets/css/fontawesome.min.css
    …/net.i-dev.betterlogic/assets/js/fontawesome.min.js
  • jQuery UI
    …/net.i-dev.betterlogic/assets/js/jquery-ui.min.js
    …/net.i-dev.betterlogic/assets/css/jquery-ui.css
    • jQuery UI Touch-Punch, include this for 'clicks" on mobiles, adjusted for Homey.
      …/net.i-dev.betterlogic/assets/js/jquery-ui.touch-punch.min.js
  • Lodash 4.17.21.
    …/net.i-dev.betterlogic/assets/js/lodash.min.js
  • AngularJS 1.8.2
    …/net.i-dev.betterlogic/assets/js/angular.min.js
    • Drag-and-drop 1.0.3 angularjs (Customized for Homey )
      …/net.i-dev.betterlogic/assets/js/angular-dragdrop.js
    • Smart Table angularjs
      …/net.i-dev.betterlogic/assets/js/smart-table.min.js
      …/net.i-dev.betterlogic/assets/css/smart-table.css

How to include into your App?

3 Likes

How to include the Better Logic Library?

The Basic

There are just a few simple steps to start with the most basic: include the BLL and initialize it:

  • Add BLL through NPM.
    npm install betterlogiclibrary
  • Add the permission to your app.json
    "permissions": ["homey:app:net.i-dev.betterlogic"]
  • Import the BL module in the app.js:.
    const { BL } = require('betterlogiclibrary');
  • Initialize the BL in the app.js onInit:
    await BL.init({homey:this.homey});

There will be no error’s thrown if BLL is not installed or not available, if no modules are used, it is put on silent mode.
Making it not required, but a bonus for users who wish to use BLL coding: If your app supports it, they just need to install BLL (which they already will have i guess).

Decoder

Now, to use the decoder, you do not need any modules loaded. The texts will be decoded by the BLL App, so you do not need to include math.js or lodash into your app to support decoding.

All you need to do, is run the text you wish to decode through the decoder:

  • Import the BL module.
    const { BL } = require('betterlogiclibrary');
  • Use it! Here is an path argument that i want to have decoded:
    args.path = await BL.decode(args.path);

That’s it!

Including modules

To include modules like lodash, follow these steps:

  • Include the module(s) in the BL initialization:
let bl = await new BL({
  homey:this.homey, 
  modules:[
    "_",
    "math",
    "datetime"
]});
  • Now you can use it anywhere:
    BL._.find
    BL._.pickBy
    BL.datetime.toString('dd-MM-yyyy')
    BL.datetime.toString('dddd') = monday

How does it work?

The BLL loader loads modules through the BLL Api. This massively reduces the app install size.
Only requested modules are loaded and the Static BL is generated.
Every time the BLL get’s an update or is installed, all updated files and modules will be reloaded into your app. Your app doesn’t even need a restart for this!

1 Like

npm install betterlogiclibrary

1 Like

Up2date list:

Apps that support BBL coding in (certain) flowcard:

reserved

One more

[And again one more reserved]

Better Logic Library is now available as NPM package.

Easy to install into your app!

npm install betterlogiclibrary

1 Like

Could you change the constructor (in TS) parameters to optional?
Looks like the bl.d.ts is not quite right.

 constructor({ homey, modules, silent, waitTime, waitForBll }?: [{
        homey: string;
        modules;
        silent;
        waitTime;
        waitForBll;
    }, {
        waitForBll: true;
    }]);

Shouldn’t it be like this?

 constructor({ homey?:Homey, modules?:any, silent?:any, waitTime?:any, waitForBll?:any });

Also does we need a BLL object for the decode to work since it a static method?

Hey Spikes,

I have updated the code, i think you will not get any TS errors anymore (i don’t at least :wink: )

Yes, i have changed the contructor (removed it) and created a static init method:
await BL.init({homey:this.homey, silent:true});

It will still create a BL object, which i need, because the BLL object that manages updates and format/setting changes, is an active object.

Edit:

i might change that if it’s better, but it will not effect the usage: all currently exposed methods are static indeed (for BL at least), so it would not break apps.

1 Like

betterlogiclibrary - npm (npmjs.com)

Updated to 0.3.3.

  • Includes all correct TypeScript definitions.
  • Hides non-relative properties / clean def’s.
  • Slim install.
  • Install script reminder of permission set on npm install.
  • Readme.md on the NPM site.

This is a working version, the basis of this will remain as it is.
As far as i can see, the NPM is finished a.t.m.

Because, all functionalities are build into BLL and are requested through the BLL-AppApi.
This NPM package is just the “loader”.

Now i’ll add the customisable functions to the BLL App Settings.

2 Likes

Does this mean that the Better Logic app as we knew it now loads all these libraries or is this a different app? (I lost track of it)

Hey @DaneedeKruyff

Well, yes, Better Logic is now Beter Logic Library.
But it already contained (most of) these Libraries that are now exposed to be consumed by other apps.
The BL app had a size of about 3MB before (App size).
It is now just 3.05MB :slight_smile:

Okay, i did update angluarjs, matjs etc. and added a few new libraries and now am using the minified versions.

The NPM betterlogiclibrary is just a small loader which you can use in other apps to:

  • Decode BLL coding in text-arguments.
  • Use DateTime Object.
  • Use custom functions from BLL.
  • Use Modules for settings, like angularjs and the newest font-awesomes.
  • Load node modules: Loadash and math.js (already a part of BL).
    When an app includes a node module through BLL, The node_modules’ file is read and send as text to the consuming app, where is it build using the normal import constructor.
    So it’s pretty memory/size efficient.
1 Like

Ok, thanks, that explains what ‘happened’ to the app, never looked into it so didn’t even know all these libraries were already in there.
(Apart from lodash it seemed a bit of an overkill to me for what the app did, that’s why I asked)

Well, the Math.js is used in a few flowcards with expressions, but having updated it and more importantly, using the minified version, really saves a lot of space.

So, this way i saw a perfect fit for what has always been written in the description of Better Logic:
An advanced logic library with variable management for Homey.

Hey @Peter_Kawa,

You are gonna like this (i think :wink: )
The functions in the App settings are just like HOOP and DC, but just a little better :wink:

This works lovely on your phone.

Who wants to start coding on there phone? :wink:

2 Likes

All in Review now:

  • Google Services
  • FTP Client
  • Bett Logic Library

Is BLL now non-optional?

When I don’t have BLL installed, I get an error, with BLL installed, it’s fine.

        BL.init({homey: this.homey});
        console.log("Output: " + await BL.decode("Hello, today is {[date(\"dddd\")]}").catch(this.error));
2023-02-28T20:16:47.959Z [err] [Homey:63c568c5e1c0180b8a2acafe] BL.init Error: Better Logic Library is not installed.
    at BL.getAppApi (/app/node_modules/betterlogiclibrary/src/bl.js:344:35)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async BL.init (/app/node_modules/betterlogiclibrary/src/bl.js:200:28)
    at async Function.init (/app/node_modules/betterlogiclibrary/src/bl.js:157:9)
[err] [Homey:63c568c5e1c0180b8a2acafe] TypeError: Cannot read properties of undefined (reading 'resolve')
    at BL.init (/app/node_modules/betterlogiclibrary/src/bl.js:217:44)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Function.isInit (/app/node_modules/betterlogiclibrary/src/bl.js:100:9)
    at async Function.decode (/app/node_modules/betterlogiclibrary/src/bl.js:40:13)
    at async TelegramNotifications.onInit (/app/app.js:56:34)
    at async SDK._initApp (/node_modules/@athombv/homey-apps-sdk-v3/lib/SDK.js:249:7)
    at async SDK.createClient (/node_modules/@athombv/homey-apps-sdk-v3/lib/SDK.js:131:7)
    at async /homey-app-runner/lib/App.js:372:22
    at async App.createClient (/homey-app-runner/lib/App.js:416:5)
Output: undefined

Which app do you mean?
For telegram?

It should still be optional

Please update the NPM to 0.6.8 i just published.

Works perfectly with Google Services, also just optional.
I just removed BLL completly, restarted my HP2023 with GS on it, no errors, everything works correctly (only bll coding is not converted ofc, but thats how it’s suppose to be).