{"_id":"homa","_rev":"54-91175d93f46ae89b070dfab874040a35","name":"homa","description":"Meta package for the HomA framework","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"homa","version":"0.1.0","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqttjs":"~0.1.8","optimist":"~0.3.5","node-schedule":"~0.1.6"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","_id":"homa@0.1.0","readme":"ERROR: No README.md file found!","dist":{"shasum":"68985c47484686690e54cdfe718c3591c3695ea4","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.0.tgz","integrity":"sha512-ge1wGoHJNngbzD1RoUvLB6MNXfYHwuzGNy18Ztmfs8G3ZGvOma2DomRl7lcyTrmCubstg8oUEHqHWcUn+0VqRw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD9U+i8hsZFOj8drf+YIwWWuz+f7UjnDGlLdXXLwxwuyAIhAL3bSwUZFA1Myu86tJyMuL1MWRh6OcvRfiJS21+gqwVR"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.1":{"name":"homa","version":"0.1.1","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqttjs":">=0.1.8","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","_id":"homa@0.1.1","readme":"ERROR: No README.md file found!","dist":{"shasum":"f59cae2a417a5c6f088b91d4be04d49b2a81603f","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.1.tgz","integrity":"sha512-kY/YpuNa6LauL/EYoSmc5qZiBRKPaBGOQ/ISFnlVEqQUV07kjaEzYQWM2j2nnEw7yCbhKPWpAR2WfWAqgG+X6g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF/p8ukOo5RgqT/SqKkmq7VdWcK86GOVqicRcKeFZLrmAiEAnpjXQj1cd7K+BPfAL4Qjs918HlbXMdeMPsPQDy4EIMA="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.3":{"name":"homa","version":"0.1.3","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqttjs":"git://github.com/adamvr/MQTT.js#master","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","_id":"homa@0.1.3","readme":"ERROR: No README.md file found!","dist":{"shasum":"f62cf686623b7ac5dc840b5173b728b4bf8df8e5","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.3.tgz","integrity":"sha512-TOpo0nINbGehaCxInhhfMZIPQRn8cYqnVRsuhJmPDFpbXfIXEGHwb0c9hs5l6l6nDhCy7zYE/94Et9BpdKwIsw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDo1U4qyivB3d7lOELq7AECABJZELUjGjUTcveceg6I/AiEA902a2SYRmyzkq0ksCP7oOQtHD+QYr/NozT3tvK5lY6E="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.4":{"name":"homa","version":"0.1.4","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.1","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","_id":"homa@0.1.4","readme":"ERROR: No README.md file found!","dist":{"shasum":"3073f18fb00a605c74c3cb9c7ebe4b9c03c2f376","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.4.tgz","integrity":"sha512-4saOIqynKsnmVeMiLwMoldUOtVjl1IJ0zpQD4R/AOs1LDaituIWFZ6j12glKciuLa/grZ59iTf1LtbDwMUGvlA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGifX9Wd2XS0a4LLreVHfuI9ciMqiowpKXulng19E82eAiBeRfzwrRzfAL6Uk+PRSN12p5Emj8p3X2KniqhVBccHWA=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.5":{"name":"homa","version":"0.1.5","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.1","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","_id":"homa@0.1.5","readme":"ERROR: No README.md file found!","dist":{"shasum":"f8aa5883a8edbef0b8fbab13cdd3a17a29331001","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.5.tgz","integrity":"sha512-uyFp/T3p1W+qqCgdYi1ZScoyk7LNShjYWG/jTYaGe6sHSlnOSnF2icRQzcfmSzNgM+Tm9nLU0bwPTJh/HuS2vw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGDIhlX5Oxa94//Rg8yOJStLaKBb3VpmLB/kI64L059lAiEA0HEHlrxv2oY8HPYn2l0NutZ4uCA1SJDugrzr8+VU/RI="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.6":{"name":"homa","version":"0.1.6","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.5","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","readme":"# HomA - Node modly\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework \n\n## Functionality \n* MqttHelper Wrapper around the mqtt module\n* StringHelper Provides string formating functions\n* ParamHelper Wrapper around optimist. Provides a common command-line syntax for MQTT parameters\n* logger Exposes an npmlog instance\n* scheduler Exposes a node-schedule instance\n\n\nTo add custom command-line parameters use \n```var argv = homa.paramHelper.describe(\"paramName\", \"description\").default(\"systemId\", \"458293-GoogleCalendarBridge\").argv;```\n\nMind the final .argv that is required by the optimist module to parse the parameters. Parameters can be accessed through ```argv.paramName```\n\n","_id":"homa@0.1.6","dist":{"shasum":"48f401ba1efbb877c9c0e9fa03c8c1f2eab1da9b","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.6.tgz","integrity":"sha512-f/hB1OG6/Kyh+ZdGvWIaMkWaU73+AhpnH/cCVEMHKdCb5XXfDqr2Qd3Spqdoqzeq1PLhEs/u1eL7/qxHr7vHVA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGIO2SF6MyN0Ss08T9tXAOdbwhH8pTyC2oJVmFUu8BmBAiEA1ilANYZ9Gyev36r+tq7LuklHfsEBA5zKbyDw+x9Smb4="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.7":{"name":"homa","version":"0.1.7","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.6","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"MIT","readme":"# HomA - Node module\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework \n\n## Functionality \n* MqttHelper Wrapper around the mqtt module\n* StringHelper Provides string formating functions\n* ParamHelper Wrapper around optimist. Provides a common command-line syntax for MQTT parameters\n* logger Exposes an npmlog instance\n* scheduler Exposes a node-schedule instance\n\n\nTo add custom command-line parameters use \n```var argv = homa.paramHelper.describe(\"paramName\", \"description\").default(\"systemId\", \"458293-GoogleCalendarBridge\").argv;```\n\nMind the final .argv that is required by the optimist module to parse the parameters. Parameters can be accessed through ```argv.paramName```\n\n","_id":"homa@0.1.7","dist":{"shasum":"c5c20d0933bd9c4e5e7e8d2aa884890e07e9a0a8","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.7.tgz","integrity":"sha512-9KNGGeUFk4NrXfk2trkluTgAa+oVR8i29tj+soO6dNiKMb0BPRVGlYV/Zm2anOK9HxrDHCAknK8HmtpTPIfPFA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDxxehJDl0bsfZe8XlKnOpspkS2AeO3FT3W8J4SC4QH0gIhAI6Np5qqHt5mEbP/rlcp6ild7NINDZ6PwL72W8KcjiUH"}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.1.8":{"name":"homa","version":"0.1.8","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.9","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"EPL","readme":"# HomA - Node module\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework \n\n## Functionality \n* MqttHelper Wrapper around the mqtt module\n* StringHelper Provides string formating functions\n* ParamHelper Wrapper around optimist. Provides a common command-line syntax for MQTT parameters\n* logger Exposes an npmlog instance\n* scheduler Exposes a node-schedule instance\n\n\nTo add custom command-line parameters use \n```var argv = homa.paramHelper.describe(\"paramName\", \"description\").default(\"systemId\", \"458293-GoogleCalendarBridge\").argv;```\n\nMind the final .argv that is required by the optimist module to parse the parameters. Parameters can be accessed through ```argv.paramName```\n\n","_id":"homa@0.1.8","dist":{"shasum":"992b3b950a060a989470c4c977884989da4892f7","tarball":"https://registry.npmjs.org/homa/-/homa-0.1.8.tgz","integrity":"sha512-FuKwWZ6Y5vozftiCm1qfD78OEql9fKEx2L28OrD3rHDe5QA2lNHWt6Anb53CSBxxJYUi1Uwbk8wQ7Lc3RUBkBw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEaUxZ4SG2wuQJNGsM9UCAWdvy1ez0yqgTc+nwk26Za9AiEArPvp2FGPdhmX1JYHe2ZdCoSWUkMGW2FcCEVB5GGAxdE="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.2.0":{"name":"homa","version":"0.2.0","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.9","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"EPL","readme":"# HomA - Node module\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework. \n\nThis module provides a common command-line syntex to HomA components that are based on this module. Per default only the broker host and port have to be provided by the user in order to start a component that is based on this module. The parameters can either be supplied with the parameters ```--brokerHost and ```--brokerPort``` or they are read from the environment variables ```HOMA_BROKER_HOST``` and ```HOMA_BROKER_PORT```. If both are provided, the command-line parameters take precedence. \n\nAccording to the [wiki](https://github.com/binarybucks/homA/wiki/Conventions#settings) all further configuration should be saved in an MQTT topic according to the deviceId of the component. The settingsHelper that is provided by this module offers the necessary functions for this task.  \n\nIf no [systemId](https://github.com/binarybucks/homA/wiki/Conventions#systemids) is provided through the ```--systemId``` parameter, the component's default systemId is used. If you are only using a single instance of a component there shouldn't be aby need to use a different systemId than the default one. \n\nWhen writing a new component based on this module, the default systemId can be provided and acquired through \n```\n#!/usr/bin/env node\nvar homa = require('homa');\nvar systemId = homa.paramsWithDefaultSystemId(\"391349-logger\");\n```\nThis requires this module, sets the default systemid to 391349-logger and finishes the parameters so that they can later be accessed by through homa.params.paramKey. \n\n\n## mqttHelper\nProvides helper methods and wraps functions of the mqtt node module.\n\n* ```connect(host, port)``` Connects to the MQTT broker\n* ```publish(topic, payload, retained)``` Publishes a payload to the specified topic retained or non-retained\n* ```schedulePublish(date, topic, payload, retained)``` calls publish(...) with the specified parameters at date\n* ```unschedulePublishes()``` Unschedules all previously scheduled publishes\n* ```disconnect()``` Disconnects form the broker\n* ```subscribe(topic)``` Subscribes to a MQTT topic\n* ```unsubscibe(topic)``` Unsubscribes from a previously subscribed MQTT topic\n\nIt also emits the following events\n\n\n\n## stringHelper\nProvides helper methods for string formating\n* ```pad(n, width, symbol, back)``` Adds symbols to the beginning or enf of string n until it reaches the specified width. \n\n## settings\nProvides functions to store [settings](https://github.com/binarybucks/homA/wiki/Conventions#settings) in an MQTT topic according to the systemId. The general idea behind this is to store everything that is not required to connect to the MQTT broker in a topic of the format /sys/$deviceId/parameter. After connecting to the broker, the module will subscribe to all parameter that are marked as required or optional. \n\nIn the ```message``` event emitted by the mqttHelper, one can use the ```insert(packet.topic, packet.payload)``` function to add any received message into the current settings. If the topic matches the /sys topic format described eariler and the topic parameters is required or optional it can later be used similar to a normal config parameter. \n\nAlso, one can use the ```isBootstrapCompleted()``` to check if all required parameters were received from the broker. To mark a certain parameter key as required, use the provided function ```require(parameter)```. Optional paramters whose values should be retreived can be denoted with the ```optional(parameter)``` funcion. \n\nTo save a value of a parameter at the correct MQTT topic, one can use the ```save(parameter, value)``` function. Additionally, parameter values that were previously received and inserted can be retreived to use them with the help of the ```get(parameter)``` function. This will return the value of the paramter if a message for it was received and inserted. \n\nThe following provides a basic example to use the settingsHelper to read and write two settings from the /sys topic.\n\n```\nvar homa = require('homa') // Require module\nvar systemId = homa.paramsWithDefaultSystemId(\"123456-test\"); // /sys topic format is /sys/123456-test/parmeter\n\t\t\t\t\t\t\n// Connect to the broker\t\t\t\t\t\t\n(function connect() {\n    homa.mqttHelper.connect();\n})();\n\n// Called after the connection to the broker is established\n// Subscribes to \"/sys/123456-test/parmeter1\" and \"/sys/123456-test/parmeter2\"\n// but homa.settings.isBootstrapCompleted() will return true after homa.settings.insert(\"/sys/123456-test/parmeter1\", \"value\") was called \n\nhoma.mqttHelper.on('connect', function(packet) {\t\n\t\thoma.settings.require('parameter1'); // Set required settings\n\t\thoma.settings.optional('parameter2');\n});\n\n// Called when a MQTT message for a subscribed topic is received\nhoma.mqttHelper.on('message', function(packet) {\n\thoma.settings.insert(packet.topic, packet.payload); // Check if a required settings parameter was received. If so, save it for later. \n\n\t// Check if all required values are received. If so, the parameter bootstrap is completed and the normal code execution can start. \n\t// The isLocked() and lock() functions prevent that the inner code is executed more than once, e.g. when a required or optional parameter is published to the according topic again\n\n\tif (!homa.settings.isLocked() && homa.settings.isBootstrapCompleted()) {\n\t\thoma.settings.lock(); // Prevent this code form being executed again\n\t\tconsole.log(\"Hello world, parameter1 is: %s, parameter2 (if received) is: %s\", homa.settings.get(\"parmeter1\"), homa.settings.get(\"parameter2\"));\n\n\t\t// Save some value for parameter2\n\t\thoma.settings.save(\"parameter2\", \"some value\");\n\t}\n});\n\n```\n\n## logger\nExposes an [npmlog](https://npmjs.org/package/npmlog) instance\n\n## params\nExposes an [optimist](https://npmjs.org/package/optimist) instance. Note that before accessing any values paramsWithDefaultSystemId(systemId) has to be called. \n\n","_id":"homa@0.2.0","dist":{"shasum":"c62cd843105b35bee9af6b27bc8cb68f7fc799c6","tarball":"https://registry.npmjs.org/homa/-/homa-0.2.0.tgz","integrity":"sha512-fDx7wjQAwlAcx0k5/KpMni4AJOq25wLk9ql1RugtLtEQQ+4pC19fPh97xHhoSQFdKmUNbj+f7gLryDZ8Bh6A5Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFQwuBY0amuzBZA4AxW+7h1hDmF9v/LgmoIlWX/Isr8bAiAKy4IVOeuE0TQ7eGR+zOcpdIYv1laDklxJRGmWtmXrbA=="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.2.1":{"name":"homa","version":"0.2.1","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.9","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"EPL","readme":"# HomA - Node module\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework. \n\nThis module provides a common command-line syntax to HomA components that are based on this module. Per default only the broker host and port have to be provided by the user in order to start a component that is based on this module. The parameters can either be supplied with the parameters ```--brokerHost``` and ```--brokerPort``` or they are read from the environment variables ```HOMA_BROKER_HOST``` and ```HOMA_BROKER_PORT```. If both are provided, the command-line parameters take precedence. \n\nAccording to the [wiki](https://github.com/binarybucks/homA/wiki/Conventions#settings) all further configuration should be saved in an MQTT topic according to the deviceId of the component. The settingsHelper that is provided by this module offers the necessary functions for this task.  \n\nIf no [systemId](https://github.com/binarybucks/homA/wiki/Conventions#systemids) is provided through the ```--systemId``` parameter, the component's default systemId is used. If you are only using a single instance of a component there shouldn't be aby need to use a different systemId than the default one. \n\nWhen writing a new component based on this module, the default systemId can be provided and acquired through \n```\n#!/usr/bin/env node\nvar homa = require('homa');\nvar systemId = homa.paramsWithDefaultSystemId(\"391349-logger\");\n```\nThis requires this module, sets the default systemId to 391349-logger and finishes the parameters so that they can later be accessed through ```homa.params.paramKey```. \n\n\n## mqttHelper\nProvides helper methods and wraps functions of the mqtt node module.\n\n* ```connect(host, port)``` Connects to the MQTT broker\n* ```publish(topic, payload, retained)``` Publishes a payload to the specified topic retained or non-retained\n* ```schedulePublish(date, topic, payload, retained)``` calls publish(...) with the specified parameters at date\n* ```unschedulePublishes()``` Unschedules all previously scheduled publishes\n* ```disconnect()``` Disconnects form the broker\n* ```subscribe(topic)``` Subscribes to a MQTT topic\n* ```unsubscibe(topic)``` Unsubscribes from a previously subscribed MQTT topic\n\nIt also emits the following events\n\n\n\n## stringHelper\nProvides helper methods for string formating\n* ```pad(n, width, symbol, back)``` Adds symbols to the beginning or enf of string n until it reaches the specified width. \n\n## settings\nProvides functions to store [settings](https://github.com/binarybucks/homA/wiki/Conventions#settings) in an MQTT topic according to the systemId. The general idea behind this is to store everything that is not required to connect to the MQTT broker in a topic of the format /sys/$deviceId/parameter. After connecting to the broker, the module will subscribe to all parameter that are marked as required or optional. \n\nIn the ```message``` event emitted by the mqttHelper, one can use the ```insert(packet.topic, packet.payload)``` function to add any received message into the current settings. If the topic matches the /sys topic format described eariler and the topic parameters is required or optional it can later be used similar to a normal config parameter. \n\nAlso, one can use the ```isBootstrapCompleted()``` to check if all required parameters were received from the broker. To mark a certain parameter key as required, use the provided function ```require(parameter)```. Optional paramters whose values should be retreived can be denoted with the ```optional(parameter)``` funcion. \n\nTo save a value of a parameter at the correct MQTT topic, one can use the ```save(parameter, value)``` function. Additionally, parameter values that were previously received and inserted can be retreived to use them with the help of the ```get(parameter)``` function. This will return the value of the paramter if a message for it was received and inserted. \n\nThe following provides a basic example to use the settingsHelper to read and write two settings from the /sys topic.\n\n```\nvar homa = require('homa') // Require module\nvar systemId = homa.paramsWithDefaultSystemId(\"123456-test\"); // /sys topic format is /sys/123456-test/parmeter\n\t\t\t\t\t\t\n// Connect to the broker\t\t\t\t\t\t\n(function connect() {\n    homa.mqttHelper.connect();\n})();\n\n// Called after the connection to the broker is established\n// Subscribes to \"/sys/123456-test/parmeter1\" and \"/sys/123456-test/parmeter2\"\n// but homa.settings.isBootstrapCompleted() will return true after homa.settings.insert(\"/sys/123456-test/parmeter1\", \"value\") was called \n\nhoma.mqttHelper.on('connect', function(packet) {\t\n\t\thoma.settings.require('parameter1'); // Set required settings\n\t\thoma.settings.optional('parameter2');\n});\n\n// Called when a MQTT message for a subscribed topic is received\nhoma.mqttHelper.on('message', function(packet) {\n\thoma.settings.insert(packet.topic, packet.payload); // Check if a required settings parameter was received. If so, save it for later. \n\n\t// Check if all required values are received. If so, the parameter bootstrap is completed and the normal code execution can start. \n\t// The isLocked() and lock() functions prevent that the inner code is executed more than once, e.g. when a required or optional parameter is published to the according topic again\n\n\tif (!homa.settings.isLocked() && homa.settings.isBootstrapCompleted()) {\n\t\thoma.settings.lock(); // Prevent this code form being executed again\n\t\tconsole.log(\"Hello world, parameter1 is: %s, parameter2 (if received) is: %s\", homa.settings.get(\"parmeter1\"), homa.settings.get(\"parameter2\"));\n\n\t\t// Save some value for parameter2\n\t\thoma.settings.save(\"parameter2\", \"some value\");\n\t}\n});\n\n```\n\n## logger\nExposes an [npmlog](https://npmjs.org/package/npmlog) instance\n\n## params\nExposes an [optimist](https://npmjs.org/package/optimist) instance. Note that before accessing any values paramsWithDefaultSystemId(systemId) has to be called. \n\n","_id":"homa@0.2.1","dist":{"shasum":"ebc63ae8660b9be4c1c526cb9bbcacbbb87df237","tarball":"https://registry.npmjs.org/homa/-/homa-0.2.1.tgz","integrity":"sha512-puC0dMuhnf4Rz9aj1s4QDsDbzncFeBM2GRFyE8op5YkyBvL9R+oTL75b4Gd6vRvcMH5FgCykxHCsI0J17A+MuA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGmdl3nHcgzUZCPpX9lc/KxaltT8lEWVLsYWT062o4GPAiEA4hIFGrJSO5zg8qLgLoYBlTktsEmbmldjMk46SQSdOnE="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"directories":{}},"0.2.2":{"name":"homa","version":"0.2.2","description":"Meta package for the HomA framework","main":"homa.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"dependencies":{"mqtt":">=0.2.3","optimist":">=0.3.5","node-schedule":">=0.1.6","npmlog":">=0.0.2"},"repository":"","author":{"name":"Alexander Rust"},"license":"EPL","readme":"# HomA - Node module\nThis is a small module that provides wrapper functions and tools for components of the HomA smart home framework. \n\nThis module provides a common command-line syntax to HomA components that are based on this module. Per default only the broker host and port have to be provided by the user in order to start a component that is based on this module. The parameters can either be supplied with the parameters ```--brokerHost``` and ```--brokerPort``` or they are read from the environment variables ```HOMA_BROKER_HOST``` and ```HOMA_BROKER_PORT```. If both are provided, the command-line parameters take precedence. \n\nAccording to the [wiki](https://github.com/binarybucks/homA/wiki/Conventions#settings) all further configuration should be saved in an MQTT topic according to the deviceId of the component. The settingsHelper that is provided by this module offers the necessary functions for this task.  \n\nIf no [systemId](https://github.com/binarybucks/homA/wiki/Conventions#systemids) is provided through the ```--systemId``` parameter, the component's default systemId is used. If you are only using a single instance of a component there shouldn't be aby need to use a different systemId than the default one. \n\nWhen writing a new component based on this module, the default systemId can be provided and acquired through \n```\n#!/usr/bin/env node\nvar homa = require('homa');\nvar systemId = homa.paramsWithDefaultSystemId(\"391349-logger\");\n```\nThis requires this module, sets the default systemId to 391349-logger and finishes the parameters so that they can later be accessed through ```homa.params.paramKey```. \n\n\n## mqttHelper\nProvides helper methods and wraps functions of the mqtt node module.\n\n* ```connect(host, port)``` Connects to the MQTT broker\n* ```publish(topic, payload, retained)``` Publishes a payload to the specified topic retained or non-retained\n* ```schedulePublish(date, topic, payload, retained)``` calls publish(...) with the specified parameters at date\n* ```unschedulePublishes()``` Unschedules all previously scheduled publishes\n* ```disconnect()``` Disconnects form the broker\n* ```subscribe(topic)``` Subscribes to a MQTT topic\n* ```unsubscibe(topic)``` Unsubscribes from a previously subscribed MQTT topic\n\nIt also emits the following events\n\n\n\n## stringHelper\nProvides helper methods for string formating\n* ```pad(n, width, symbol, back)``` Adds symbols to the beginning or enf of string n until it reaches the specified width. \n\n## settings\nProvides functions to store [settings](https://github.com/binarybucks/homA/wiki/Conventions#settings) in an MQTT topic according to the systemId. The general idea behind this is to store everything that is not required to connect to the MQTT broker in a topic of the format /sys/$deviceId/parameter. After connecting to the broker, the module will subscribe to all parameter that are marked as required or optional. \n\nIn the ```message``` event emitted by the mqttHelper, one can use the ```insert(packet.topic, packet.payload)``` function to add any received message into the current settings. If the topic matches the /sys topic format described eariler and the topic parameters is required or optional it can later be used similar to a normal config parameter. \n\nAlso, one can use the ```isBootstrapCompleted()``` to check if all required parameters were received from the broker. To mark a certain parameter key as required, use the provided function ```require(parameter)```. Optional paramters whose values should be retreived can be denoted with the ```optional(parameter)``` funcion. \n\nTo save a value of a parameter at the correct MQTT topic, one can use the ```save(parameter, value)``` function. Additionally, parameter values that were previously received and inserted can be retreived to use them with the help of the ```get(parameter)``` function. This will return the value of the paramter if a message for it was received and inserted. \n\nThe following provides a basic example to use the settingsHelper to read and write two settings from the /sys topic.\n\n```\nvar homa = require('homa') // Require module\nvar systemId = homa.paramsWithDefaultSystemId(\"123456-test\"); // /sys topic format is /sys/123456-test/parmeter\n\t\t\t\t\t\t\n// Connect to the broker\t\t\t\t\t\t\n(function connect() {\n    homa.mqttHelper.connect();\n})();\n\n// Called after the connection to the broker is established\n// Subscribes to \"/sys/123456-test/parmeter1\" and \"/sys/123456-test/parmeter2\"\n// but homa.settings.isBootstrapCompleted() will return true after homa.settings.insert(\"/sys/123456-test/parmeter1\", \"value\") was called \n\nhoma.mqttHelper.on('connect', function(packet) {\t\n\t\thoma.settings.require('parameter1'); // Set required settings\n\t\thoma.settings.optional('parameter2');\n});\n\n// Called when a MQTT message for a subscribed topic is received\nhoma.mqttHelper.on('message', function(packet) {\n\thoma.settings.insert(packet.topic, packet.payload); // Check if a required settings parameter was received. If so, save it for later. \n\n\t// Check if all required values are received. If so, the parameter bootstrap is completed and the normal code execution can start. \n\t// The isLocked() and lock() functions prevent that the inner code is executed more than once, e.g. when a required or optional parameter is published to the according topic again\n\n\tif (!homa.settings.isLocked() && homa.settings.isBootstrapCompleted()) {\n\t\thoma.settings.lock(); // Prevent this code form being executed again\n\t\tconsole.log(\"Hello world, parameter1 is: %s, parameter2 (if received) is: %s\", homa.settings.get(\"parmeter1\"), homa.settings.get(\"parameter2\"));\n\n\t\t// Save some value for parameter2\n\t\thoma.settings.save(\"parameter2\", \"some value\");\n\t}\n});\n\n```\n\n## logger\nExposes an [npmlog](https://npmjs.org/package/npmlog) instance\n\n## params\nExposes an [optimist](https://npmjs.org/package/optimist) instance. Note that before accessing any values paramsWithDefaultSystemId(systemId) has to be called. \n\n","_id":"homa@0.2.2","dist":{"shasum":"62bc69808ab35204a66e362c33ea2d6ba7efec9e","tarball":"https://registry.npmjs.org/homa/-/homa-0.2.2.tgz","integrity":"sha512-uawsi41KesjSA/9AJdEdGqi4sY1eh73q5nYm0qIdA/DapextE7a9AdsjrwL2oKAtHE6nMU/4gyDPKgafWeZuzg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICVPQap2nJa1inyn1NL9IauGtpV9FeCoal5ctcaQll2WAiEAnbHXxjVe6uT7HEJNkpkN+lLwhky3PYqEki7aHMVNTkI="}]},"_npmVersion":"1.1.62","_npmUser":{"name":"binarybucks","email":"mail@alr.st"},"maintainers":[{"name":"binarybucks","email":"mail@alr.st"}]}},"readme":"ERROR: No README.md file found!","maintainers":[{"name":"binarybucks","email":"mail@alr.st"}],"time":{"modified":"2022-06-18T21:06:58.858Z","created":"2013-02-25T17:19:52.346Z","0.1.0":"2013-02-25T17:19:54.247Z","0.1.1":"2013-02-25T18:12:14.186Z","0.1.3":"2013-03-04T21:04:15.787Z","0.1.4":"2013-03-05T20:55:25.404Z","0.1.5":"2013-03-07T07:10:00.128Z","0.1.6":"2013-03-12T08:40:55.784Z","0.1.7":"2013-04-08T15:17:41.280Z","0.1.8":"2013-05-30T19:29:46.642Z","0.2.0":"2013-06-11T20:24:23.682Z","0.2.1":"2013-06-11T20:29:35.906Z","0.2.2":"2013-07-29T18:10:48.540Z"},"author":{"name":"Alexander Rust"},"users":{"jamesg":true}}