Finally finished my first module.
Nothing too fancy but fits my requirements.
Read the statement by Michael Teeuw here.
Posts made by PTcrusher
-
RE: Building my first module, using MMM-API
-
RE: MMM-CalendarWeek
@ptcrusher said in MMM-CalendarWeek:
For some reason i cannot get CalendarWeek to display more than 4 days, could you kindly take a look at my configuration?
{ module: "MMM-CalendarWeek", displayLocation: true, displayDescription: true, maximumNumberOfDays: "7", maximumDaysPerLine: "7", position: "bottom_bar", // This can be any of the regions. Best results in bottom region. config: { // The config property is optional. // If no config is set, an example calendar is shown. // See 'Configuration options' for more information. calendars: [ { maximumNumberOfDays: "7", symbol: "google", url: "", }, { maximumNumberOfDays: "7", symbol: "umbrella-beach", url: "", }, { maximumNumberOfDays: "7", symbol: "building", url: "", }, { maximumNumberOfDays: "7", symbol: "birthday-cake", url: "", } ], } },
Thanks in advance,
Edgar SantosThis options need to go to the config key :)
displayLocation: true, displayDescription: true, maximumNumberOfDays: "7", maximumDaysPerLine: "7",
Now it works fine
-
RE: MMM-CalendarWeek
For some reason i cannot get CalendarWeek to display more than 4 days, could you kindly take a look at my configuration?
{ module: "MMM-CalendarWeek", displayLocation: true, displayDescription: true, maximumNumberOfDays: "7", maximumDaysPerLine: "7", position: "bottom_bar", // This can be any of the regions. Best results in bottom region. config: { // The config property is optional. // If no config is set, an example calendar is shown. // See 'Configuration options' for more information. calendars: [ { maximumNumberOfDays: "7", symbol: "google", url: "", }, { maximumNumberOfDays: "7", symbol: "umbrella-beach", url: "", }, { maximumNumberOfDays: "7", symbol: "building", url: "", }, { maximumNumberOfDays: "7", symbol: "birthday-cake", url: "", } ], } },
Thanks in advance,
Edgar Santos -
RE: Building my first module, using MMM-API
@Sean Did some progress on the module. I removed the dependency on MMM-API since we can define extra routes in node_helper.js.
Now i have a doubt. Should i keep the values that i wish to retrieve in a variable and use the socketNotificationSend/socketNotificationReceived logic or… should i call the extra-routes from my module (MMM-PiggyBank.js) pretending that i’m accessing an external API?
Could you kindly tell me which is the recommended approach?
extraRoutes: function() { var self = this; this.expressApp.get("/MMM-PiggyBank/WITHDRAW", function(req, res) { self.withdrawCash().then((rsp) => res.status(rsp.status).send(rsp.response)); }); this.expressApp.post("/MMM-PiggyBank/CASH_IN", function(req, res) { self.updateCash(req.query.target,req.query.current).then((rsp) => res.status(rsp.status).send(rsp.response)); }); }, updateCash: async function(target,current) { var self = this; try { await self.checkExistance(self.fullyQualFileName()); var oldcontent = await readFile(self.fullyQualFileName()); var contentcandidate = await self.valChanges(target, current, JSON.parse(oldcontent)); var newcontent = await writeFile(self.fullyQualFileName(), JSON.stringify(contentcandidate)); return self.buildSuccessRsp("Successfully saved!"); } catch(err) { return self.buildErrRsp(err); } }, withdrawCash: async function() { var self = this; try { await self.checkExistance(self.fullyQualFileName()); var oldcontent = await readFile(self.fullyQualFileName()); return self.buildSuccessRsp(JSON.parse(oldcontent)); } catch(err) { return self.buildErrRsp(err); } },
-
Building my first module, using MMM-API
Hi,
I’m trying to build my first module for MagicMirror, the plan is to build a PiggyBank.
Basically this would consist on a PiggyBank image that would be visible according to the percentage of money you have related to the target e.g. if we have 30% left to the target the bottom 70% of the image will be visible and 30% of the image will be hidden.The target and the amount of money saved will be stored in a JSON file. According to what i’ve seen the code that handles the store/retrieve of data should be placed in node_helper.js.
. ├── CHANGELOG.md ├── Gruntfile.js ├── LICENSE.txt ├── MMM-PiggyBank.css ├── MMM-PiggyBank.js ├── node_helper.js ├── package.json ├── README.md └── translations ├── en.json └── es.json
The module MMM-Api would be used to change the target or the amount of money saved.
Now my question, in the MMM-Api documention the target is an ACTION in the module. My question here is where do i define the ACTION? Could you kindly show me a mockup/skeloton of and ACTION?
MAGIG_MIRROR_IP:PORT/api/v1/modules/MODULE_NAME/ACTION?payload1key=payload1value&payload2key=payload2value
An ACTION is just the name of a function inside MODULE_NAME.js e.g. processData?
processData: function(data) {
Please bear in mind that I’m new to MagicMirror and to nodejs as well.
I took the chance to look at Head first developing MM module for extreme beginners and MagicMirror2 Module Development Documentation but failed to understand how the ACTION should be defined.Thanks in advance,
Edgar Santos