Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch452 committed May 22, 2019
2 parents fe8ad58 + 6400fcd commit 6a424fc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.0] - 2019-05-22

### Added
- French Translation (thanks to [laventin85](https://github.com/laventin85))
- Number validation now accounts for NaN values
- README instructions for choosing a specific version of this module

### Fixed
- Console error when resuming the module (lastUpdateTime variable initialized and updated)
- Check for 'object' type when checking for axis.js script
- Hide "Socket Notification Received" message for non-development mode

## [1.1.0] - 2018-06-05

### Added
Expand Down
20 changes: 12 additions & 8 deletions MMM-LocalTemperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* MIT Licensed.
*/

var axis, Log, config;

/**
* Register the module with the MagicMirror program
*/
Expand Down Expand Up @@ -63,6 +65,7 @@ Module.register("MMM-LocalTemperature", {
self.validPinSchemes = [ "BOARD", "BCMv1", "BCMv2", "WPI" ];
self.validFontSizes = [ "x-small", "small", "medium", "large", "x-large" ];
self.currentweatherLoaded = false;
self.lastUpdateTime = new Date(0);

var pinMapping = [
{ "BOARD": 10, "BCMv1": 15, "BCMv2": 15, "WPI": 16 },
Expand Down Expand Up @@ -94,13 +97,13 @@ Module.register("MMM-LocalTemperature", {
];

// Process and validate configuration options
if (axis.isNumber(self.config.updateInterval) && self.config.updateInterval >= 0.5) { self.config.updateInterval = self.config.updateInterval * 60 * 1000; }
if (axis.isNumber(self.config.updateInterval) && !isNaN(self.config.updateInterval) && self.config.updateInterval >= 0.5) { self.config.updateInterval = self.config.updateInterval * 60 * 1000; }
else { self.config.updateInterval = self.defaults.updateInterval * 60 * 1000; }
if (axis.isNumber(self.config.retryDelay) && self.config.retryDelay >= 10) { self.config.retryDelay = self.config.retryDelay * 1000; }
if (axis.isNumber(self.config.retryDelay) && !isNaN(self.config.retryDelay) && self.config.retryDelay >= 10) { self.config.retryDelay = self.config.retryDelay * 1000; }
else { self.config.retryDelay = self.defaults.retryDelay * 1000; }
if (axis.isNumber(self.config.initialLoadDelay) && self.config.initialLoadDelay >= 0) { self.config.initialLoadDelay = self.config.initialLoadDelay * 1000; }
if (axis.isNumber(self.config.initialLoadDelay) && !isNaN(self.config.initialLoadDelay) && self.config.initialLoadDelay >= 0) { self.config.initialLoadDelay = self.config.initialLoadDelay * 1000; }
else { self.config.initialLoadDelay = self.defaults.initialLoadDelay * 1000; }
if (!axis.isNumber(self.config.retryDelay) || self.config.retryDelay < 0) { self.config.animationSpeed = self.defaults.animationSpeed; }
if (!axis.isNumber(self.config.retryDelay) || isNaN(self.config.retryDelay) || self.config.retryDelay < 0) { self.config.animationSpeed = self.defaults.animationSpeed; }
if (!axis.isString(self.config.scriptPath) || self.config.scriptPath.length < 1 ) { self.config.scriptPath = self.defaults.scriptPath; }
if (!self.validUnits.includes(self.config.units)) { self.config.units = self.defaults.units; }
self.tempUnit = unitMap[self.config.units];
Expand All @@ -115,7 +118,7 @@ Module.register("MMM-LocalTemperature", {
if (!axis.isString(self.config.temperatureText) || self.config.temperatureText.length < 1 ) { self.config.temperatureText = self.defaults.temperatureText; }
if (!axis.isString(self.config.humidityText) || self.config.humidityText.length < 1 ) { self.config.humidityText = self.defaults.humidityText; }
if (!self.validPinSchemes.includes(self.config.pinScheme)) { self.config.pinScheme = self.defaults.pinScheme; }
if (!axis.isNumber(self.config.sensorPin)) { self.config.sensorPin = self.defaults.sensorPin; }
if (!axis.isNumber(self.config.sensorPin) || isNaN(self.config.sensorPin)) { self.config.sensorPin = self.defaults.sensorPin; }
if (!axis.isBoolean(self.config.sendTemperature)) { self.config.sendTemperature = self.defaults.sendTemperature; }
if (!axis.isBoolean(self.config.sendHumidity)) { self.config.sendHumidity = self.defaults.sendHumidity; }
if (!axis.isBoolean(self.config.roundTemperature)) { self.config.roundTemperature = self.defaults.roundTemperature; }
Expand Down Expand Up @@ -230,6 +233,7 @@ Module.register("MMM-LocalTemperature", {
else { self.log(payload.message, payload.logType); }
} else if (notification === "DATA_RECEIVED") {
if (payload.isSuccessful) {
self.lastUpdateTime = new Date();
self.log(self.translate("DATA_SUCCESS", { "numberOfAttempts": payload.original.attemptNum }));
self.log(("Sensor Data: " + JSON.stringify(payload.data)), "dev");
self.sensorData = payload.data;
Expand Down Expand Up @@ -257,11 +261,11 @@ Module.register("MMM-LocalTemperature", {

if (axis.isNull(self.sensorData)) { return; }

if (self.config.sendTemperature && axis.isNumber(self.sensorData[self.tempUnit])) {
if (self.config.sendTemperature && axis.isNumber(self.sensorData[self.tempUnit]) && !isNaN(self.sensorData[self.tempUnit])) {
self.sendNotification("INDOOR_TEMPERATURE", self.sensorData[self.tempUnit]);
}

if (self.config.sendHumidity && axis.isNumber(self.sensorData.humidity)) {
if (self.config.sendHumidity && axis.isNumber(self.sensorData.humidity) && !isNaN(self.sensorData.humidity)) {
self.sendNotification("INDOOR_HUMIDITY", self.sensorData.humidity);
}

Expand Down Expand Up @@ -396,7 +400,7 @@ Module.register("MMM-LocalTemperature", {
*/
getScripts: function() {
var scripts = [];
if (typeof axis !== "function") { scripts.push(this.file("scripts/axis.js")); }
if (typeof axis !== "object") { scripts.push(this.file("scripts/axis.js")); }
return scripts;
},

Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This module reads and displays temperature and humidity information from a senso

| Status | Version | Date | Maintained? | Minimum MagicMirror² Version |
|:------- |:------- |:---------- |:----------- |:---------------------------- |
| Working | `1.1.0` | 2018-06-05 | Yes |`2.2.1` |
| Working | `1.2.0` | 2019-05-22 | Yes |`2.2.1` |

### Example
![Example of MMM-LocalTemperature](images/sample.png?raw=true "Example screenshot")
Expand Down Expand Up @@ -55,9 +55,9 @@ var config = {

| Option | Details
|:----------------------- |:-------------
| `sensorPin` | **REQUIRED** - The GPIO Pin number that is connected to the data pin on the sensor. The default pin scheme is the standard Raspberry Pi (BCM) GPIO numbering system for Rev 2 Pi's. See the `pinScheme` option for other numbering systems.<br />**Type:** `number`<br />
| `sensorPin` | **REQUIRED** - The GPIO Pin number that is connected to the data pin on the sensor. The default pin scheme is the standard Raspberry Pi (BCM) GPIO numbering system for Rev 2 Pi's. See the `pinScheme` option for other numbering systems.<br />**Type:** `number`
| `pinScheme` | *Optional* - The pin numbering system to use for the `sensorPin` option. See this [interactive pinout diagram](https://pinout.xyz) for more details on pin usage for the Raspberry Pi. <br />Note: Ultimately the `sensorPin` value will be converted to the WiringPi system, becuase that is the library used by the `DHT` program to interact with the pin. However, any of these numbering systems can be used, since this module will convert the `sensorPin` value automatically based on the selected scheme. <br />**Type:** `string`<br />**Default:** `"BCMv2"`<br />**Options:**<br />- `"BCMv2"` The standard Raspberry Pi GPIO numbering system on current (Rev 2) boards<br />- `"BCMv1"` The standard Raspberry Pi GPIO numbering system on older (Rev 1) boards<br />- `"BOARD"` The physical pin numbering on the GPIO header<br />- `"WPI"` The WiringPi numbering system
| `units` | *Optional* - The unit system to use for the temperature value. (`"metric"` = Celcius, `"imperial"` = Fahrenheit, `"default"` = Kelvin)<br />**Type:** `string`<br />**Default:** `config.units`<br />**Options:** `"metric"`, `"imperial"`, `"default"`
| `units` | *Optional* - The unit system to use for the temperature value. (`"metric"` = Celcius, `"imperial"` = Fahrenheit, `"default"` = Kelvin)<br />**Type:** `string`<br />**Default:** `config.units`<br />**Options:** `"metric"`, `"imperial"`, `"default"`
| `sendTemperature` | *Optional* - When `true`, an "INDOOR_TEMPERATURE" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor temperature within the built-in 'currentweather' module. The 'currentweather' module's `showIndoorTemperature` option must be set to `true` for it to display the data sent from this module.<br />**Type:** `boolean`<br />**Default:** `true`
| `sendHumidity` | *Optional* - When `true`, an "INDOOR_HUMIDITY" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor humidity within the built-in 'currentweather' module. The 'currentweather' module's `showIndoorHumidity` option must be set to `true` for it to display the data sent from this module.<br />**Type:** `boolean`<br />**Default:** `true`
| `showTemperature` | *Optional* - When `true`, the module will display the temperature on screen.<br />**Type:** `boolean`<br />**Default:** `false`
Expand Down Expand Up @@ -107,6 +107,19 @@ git reset --hard
git pull
```

## Manually Choose a Version

To use an older version of this module, use your terminal to:
1. Navigate to your MMM-LocalTemperature folder. If you are using the default installation directory, use the command:<br />`cd ~/MagicMirror/modules/MMM-LocalTemperature`
2. Fetch all the available tags<br />`git fetch`
3. Show all the available tags<br />`git tag`
4. Checkout one of the available tags<br />`git checkout {tag_name}`<br />Example: `git checkout v1.0.0`


To switch back to the latest version, use your terminal to:
1. Navigate to your MMM-LocalTemperature folder. If you are using the default installation directory, use the command:<br />`cd ~/MagicMirror/modules/MMM-LocalTemperature`
2. Checkout the master branch<br />`git checkout master`

## License

### The MIT License (MIT)
Expand Down
5 changes: 2 additions & 3 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module.exports = NodeHelper.create({

/**
* Override the start function to run when the module is started up.
* Used to provice initialization information to the console and to map
* additional routes.
* Used to provide initialization information to the console.
*/
start: function () {
var self = this;
Expand All @@ -40,7 +39,7 @@ module.exports = NodeHelper.create({
*/
socketNotificationReceived: function(notification, payload) {
var self = this;
console.log(self.name + ": Socket Notification Received: \"" + notification + "\".");
if (payload.developerMode) { console.log(self.name + ': Socket Notification Received: "' + notification + '".'); }
if (notification === "GET_DATA") {
self.getSensorData(payload);
} else if (notification === "INIT") {
Expand Down
6 changes: 3 additions & 3 deletions translations/en.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"INVALID_PIN": "The provided pin number ({pinValue}) is invalid.",
"INVALID_PIN": "The provided pin number ({pinValue}) is invalid. ",
"SUSPENDED": "Suspended",
"RESUMED": "Resumed",
"LOADING": "Loading &hellip;",
"DATA_REQUESTED": "Request sent to get the sensor data. ",
"DATA_SUCCESS": "Sensor read Successful, data received from the sensor after {numberOfAttempts} attempt(s). ",
"DATA_FAILURE_RETRY": "Sensor read Error, trying again in {retryTimeInSeconds} seconds. ",
"DATA_FAILURE": "Sensor read Error, unable to read the data from the sensor. ",
"UPDATE_SCHEDULED": "Update scheduled to run automatically every {minutes} minute(s).",
"INITIAL_DELAY": "Initial delay set. Starting in {seconds} second(s).",
"UPDATE_SCHEDULED": "Update scheduled to run automatically every {minutes} minute(s). ",
"INITIAL_DELAY": "Initial delay set. Starting in {seconds} second(s). ",
"DECIMAL_SYMBOL": ".",
"SHOW_TEMP_CELCIUS": "Temperature: {temperature_var}&deg;C",
"SHOW_TEMP_KELVIN": "Temperature: {temperature_var} K",
Expand Down
17 changes: 17 additions & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"INVALID_PIN": "Le numéro de broche fourni ({pinValue}) n'est pas valide. ",
"SUSPENDED": "Suspendu",
"RESUMED": "Reprise",
"LOADING": "Chargement &hellip;",
"DATA_REQUESTED": "Demande envoyée pour obtenir les données du capteur. ",
"DATA_SUCCESS": "Lecture du capteur réussie, données reçues du capteur après une tentative de {numberOfAttempts}. ",
"DATA_FAILURE_RETRY": "Erreur de lecture du capteur, réessayant dans {retryTimeInSeconds} secondes. ",
"DATA_FAILURE": "Erreur de lecture du capteur, incapable de lire les données du capteur. ",
"UPDATE_SCHEDULED": "Mise à jour programmée pour s'exécuter automatiquement toutes les {minutes} minutes. ",
"INITIAL_DELAY": "Réglage du délai initial. Démarrage dans {seconds} seconde(s). ",
"DECIMAL_SYMBOL": ",",
"SHOW_TEMP_CELCIUS": "Température: {temperature_var}&deg;C",
"SHOW_TEMP_KELVIN": "Température: {temperature_var} K",
"SHOW_TEMP_FAHRENHEIT": "Température: {temperature_var}&deg;F",
"SHOW_HUMIDITY": "Humidité: {humidity_var}%"
}

0 comments on commit 6a424fc

Please sign in to comment.