From 78c02923cfdc7993924eb5c3f06b57394cfc12d1 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 20 Feb 2021 22:13:42 +0100 Subject: [PATCH] New Plugin: Where the ISS at? --- debian/control | 15 ++++ debian/nymea-plugin-wheretheissat.install.in | 4 + wheretheissat/README.md | 10 +++ .../integrationpluginwheretheissat.js | 51 +++++++++++++ .../integrationpluginwheretheissat.json | 57 ++++++++++++++ wheretheissat/iss.svg | 75 +++++++++++++++++++ wheretheissat/meta.json | 13 ++++ wheretheissat/wheretheissat.mjs | 20 +++++ 8 files changed, 245 insertions(+) create mode 100644 debian/nymea-plugin-wheretheissat.install.in create mode 100644 wheretheissat/README.md create mode 100644 wheretheissat/integrationpluginwheretheissat.js create mode 100644 wheretheissat/integrationpluginwheretheissat.json create mode 100644 wheretheissat/iss.svg create mode 100644 wheretheissat/meta.json create mode 100644 wheretheissat/wheretheissat.mjs diff --git a/debian/control b/debian/control index a3c0e990..1564b6f5 100644 --- a/debian/control +++ b/debian/control @@ -1044,6 +1044,21 @@ Description: nymea.io plugin to connect to your Tado account This package will install the nymea.io plugin for Tado +Package: nymea-plugin-wheretheissat +Architecture: any +Depends: ${shlibs:Depends}, + ${misc:Depends}, + nymea-plugins-translations, +Description: nymea.io plugin to monitor the ISS position + The nymea daemon is a plugin based IoT (Internet of Things) server. The + server works like a translator for devices, things and services and + allows them to interact. + With the powerful rule engine you are able to connect any device available + in the system and create individual scenes and behaviors for your environment. + . + This package will install the nymea.io plugin for wheretheiss.at + + Package: nymea-plugin-zigbee-lumi Architecture: any Depends: ${shlibs:Depends}, diff --git a/debian/nymea-plugin-wheretheissat.install.in b/debian/nymea-plugin-wheretheissat.install.in new file mode 100644 index 00000000..7a810ea4 --- /dev/null +++ b/debian/nymea-plugin-wheretheissat.install.in @@ -0,0 +1,4 @@ +wheretheissat/integrationpluginwheretheissat.json usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/wheretheissat/ +wheretheissat/integrationpluginwheretheissat.js usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/wheretheissat/ +wheretheissat/wheretheissat.mjs usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/wheretheissat/ + diff --git a/wheretheissat/README.md b/wheretheissat/README.md new file mode 100644 index 00000000..890825b1 --- /dev/null +++ b/wheretheissat/README.md @@ -0,0 +1,10 @@ +# Where the ISS at? + +This is a simple plugin to track the current position of the ISS. + +While this plugin works and does what it is supposed to do, it is mostly meant as an example plugin to demonstrate writing nymea plugins in JavaScript. + +## More + +[wheretheissat.at](http://wheretheiss.at) +[API documentation](https://wheretheiss.at/w/developer) diff --git a/wheretheissat/integrationpluginwheretheissat.js b/wheretheissat/integrationpluginwheretheissat.js new file mode 100644 index 00000000..5d0fdad1 --- /dev/null +++ b/wheretheissat/integrationpluginwheretheissat.js @@ -0,0 +1,51 @@ +import { getSatellites } from "./wheretheissat.mjs"; +import { getSatelliteData } from "./wheretheissat.mjs"; + +var pluginTimer; + +export function init() { + console.warn("JS init called!"); +} + +export function discoverThings(info) { + getSatellites( (response) => { + for (var i = 0; i < response.length; i++) { + var params = []; + var param = {}; + param.paramTypeId = "1d10b8e2-aea4-495c-8b1f-f44ef088f667"; + param.value = response[i].id + params.push(param) + info.addThingDescriptor("4bdedd0b-e268-4671-9b3e-948c853b7b9b", response[i].name, "Satellite", params); + }; + info.finish(Thing.ThingErrorNoError); + }); +} + +export function setupThing(info) { + var device = info.thing; + var satelliteId = info.thing.paramValue("1d10b8e2-aea4-495c-8b1f-f44ef088f667"); + if (satelliteId === undefined) { + console.warn("Could not find satelliteId in params") + info.finish(Thing.ThingErrorMissingParameter); + return; + } + + getSatelliteData(satelliteId, (response) => { + device.setStateValue("d702143f-9454-412b-88df-83b5655a5000", response.latitude) + device.setStateValue("42d9b2a1-0e51-4a92-9804-8f6f68ed6fd1", response.longitude) + info.finish(Thing.ThingErrorNoError); + + pluginTimer = hardwareManager.pluginTimerManager.registerTimer(5); + pluginTimer.timeout.connect(function() { + getSatelliteData(satelliteId, (response) => { + device.setStateValue("d702143f-9454-412b-88df-83b5655a5000", response.latitude) + device.setStateValue("42d9b2a1-0e51-4a92-9804-8f6f68ed6fd1", response.longitude) + }) + }) + }); +} + +export function thingRemoved(thing) { + hardwareManager.pluginTimerManager.unregisterTimer(pluginTimer); +} + diff --git a/wheretheissat/integrationpluginwheretheissat.json b/wheretheissat/integrationpluginwheretheissat.json new file mode 100644 index 00000000..3671c964 --- /dev/null +++ b/wheretheissat/integrationpluginwheretheissat.json @@ -0,0 +1,57 @@ +{ + "name": "whereTheIssAt", + "displayName": "Where the ISS at?", + "id": "aca9d478-25c9-435f-b8d2-caf9c39a9b19", + "vendors": [ + { + "name": "nymea", + "displayName": "nymea GmbH", + "id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6", + "thingClasses": [ + { + "name": "satellite", + "displayName": "Satellite monitor", + "id": "4bdedd0b-e268-4671-9b3e-948c853b7b9b", + "setupMethod": "JustAdd", + "createMethods": ["Discovery", "User"], + "interfaces": [ ], + "paramTypes": [ + { + "id": "1d10b8e2-aea4-495c-8b1f-f44ef088f667", + "name": "satelliteId", + "displayName": "Satellite ID", + "type": "QString" + } + ], + "stateTypes":[ + { + "id": "d702143f-9454-412b-88df-83b5655a5000", + "name": "latitude", + "displayName": "Latitude", + "displayNameEvent": "Latitude changed", + "type": "double", + "defaultValue": 0 + }, + { + "id": "42d9b2a1-0e51-4a92-9804-8f6f68ed6fd1", + "name": "longitude", + "displayName": "Longitude", + "displayNameEvent": "Longitude changed", + "type": "double", + "defaultValue": 0 + } + ], + "actionTypes":[ + + ], + "eventTypes":[ + + ] + } + ] + } + ] +} + + + diff --git a/wheretheissat/iss.svg b/wheretheissat/iss.svg new file mode 100644 index 00000000..0a966a6b --- /dev/null +++ b/wheretheissat/iss.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wheretheissat/meta.json b/wheretheissat/meta.json new file mode 100644 index 00000000..074b7cd9 --- /dev/null +++ b/wheretheissat/meta.json @@ -0,0 +1,13 @@ +{ + "title": "Where the ISS at", + "tagline": "Monitors the current ISS position.", + "icon": "iss.svg", + "stability": "consumer", + "offline": true, + "technologies": [ + "network" + ], + "categories": [ + "sensor" + ] +} diff --git a/wheretheissat/wheretheissat.mjs b/wheretheissat/wheretheissat.mjs new file mode 100644 index 00000000..6d7d23f3 --- /dev/null +++ b/wheretheissat/wheretheissat.mjs @@ -0,0 +1,20 @@ +export function getSatellites(callback) { + var request = new XMLHttpRequest() + request.open("GET", "https://api.wheretheiss.at/v1/satellites"); + request.onload = function() { + var response = JSON.parse(request.response); + callback(response); + } + request.send(); +} + +export function getSatelliteData(satelliteId, callback) { + var request = new XMLHttpRequest() + request.open("GET", "https://api.wheretheiss.at/v1/satellites/" + satelliteId); + request.onload = function() { + var data = JSON.parse(request.response); + callback(data); + } + request.send(); +} +