Ver Fonte

Initial commit

Johannes Zellner há 9 anos atrás
commit
4bf98fdde2

+ 10 - 0
app.js

@@ -0,0 +1,10 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var config = require(process.env.HOME + '/.hue.json');
+var server = require('./backend/server.js');
+
+console.log(config)
+
+server.init(config);

+ 49 - 0
backend/routes.js

@@ -0,0 +1,49 @@
+'use strict';
+
+module.exports = {
+    init: init,
+    getLights: getLights,
+    setLight: setLight
+};
+
+var hue = require('node-hue-api'),
+    HueApi = hue.HueApi,
+    lightState = hue.lightState,
+    Color = require('color');
+
+var api = null;
+
+function init(hueConfig, callback) {
+    api = new HueApi(hueConfig.host, hueConfig.username);
+
+    api.config(function (error, result) {
+        if (error) return callback(new Error('Unable to connect', error));
+        if (!result.zigbeechannel) return callback(new Error('Invalid username'));
+
+        callback();
+    });
+}
+
+function getLights(req, res) {
+    api.lights(function (error, result) {
+        if (error) return res.send(500, error);
+
+        console.log('lights:', result);
+
+        res.send(200, result);
+    });
+}
+
+function setLight(req, res) {
+    console.log('set light: %s to color %s', req.params.id, req.body.color);
+
+    var color = new Color(req.body.color);
+
+    var state = lightState.create().rgb(color.rgb().array());
+
+    api.setLightState(req.params.id, state, function (error, result) {
+        if (error) return res.send(500, error);
+
+        res.send(200, {});
+    });
+}

+ 26 - 0
backend/server.js

@@ -0,0 +1,26 @@
+'use strict';
+
+module.exports = {
+    init: init
+};
+
+var express = require('express'),
+    bodyParser = require('body-parser'),
+    routes = require('./routes.js');
+
+function init(hueConfig) {
+    var app = express();
+
+    app.use(bodyParser.json());
+
+    app.get ('/api/lights', routes.getLights);
+    app.post('/api/lights/:id', routes.setLight);
+
+    routes.init(hueConfig, function (error) {
+        if (error) return console.error(error);
+
+        app.listen(3000, function () {
+            console.log('Server listening on port 3000');
+        });
+    });
+}

BIN
frontend/css/MaterialIcons-Regular.eot


BIN
frontend/css/MaterialIcons-Regular.ttf


BIN
frontend/css/MaterialIcons-Regular.woff


BIN
frontend/css/MaterialIcons-Regular.woff2


+ 0 - 0
frontend/css/index.css


+ 36 - 0
frontend/css/material-icons.css

@@ -0,0 +1,36 @@
+@font-face {
+  font-family: 'Material Icons';
+  font-style: normal;
+  font-weight: 400;
+  src: url(MaterialIcons-Regular.eot); /* For IE6-8 */
+  src: local('Material Icons'),
+       local('MaterialIcons-Regular'),
+       url(MaterialIcons-Regular.woff2) format('woff2'),
+       url(MaterialIcons-Regular.woff) format('woff'),
+       url(MaterialIcons-Regular.ttf) format('truetype');
+}
+
+.material-icons {
+  font-family: 'Material Icons';
+  font-weight: normal;
+  font-style: normal;
+  font-size: 24px;  /* Preferred icon size */
+  display: inline-block;
+  line-height: 1;
+  text-transform: none;
+  letter-spacing: normal;
+  word-wrap: normal;
+  white-space: nowrap;
+  direction: ltr;
+
+  /* Support for all WebKit browsers. */
+  -webkit-font-smoothing: antialiased;
+  /* Support for Safari and Chrome. */
+  text-rendering: optimizeLegibility;
+
+  /* Support for Firefox. */
+  -moz-osx-font-smoothing: grayscale;
+
+  /* Support for IE. */
+  font-feature-settings: 'liga';
+}

+ 53 - 0
frontend/index.html

@@ -0,0 +1,53 @@
+<html>
+<head>
+
+    <title>Cloudron HUE</title>
+
+    <link rel="stylesheet" href="../node_modules/vue-material/dist/vue-material.css">
+    <link rel="stylesheet" href="./css/material-icons.css">
+    <link rel="stylesheet" href="./css/index.css">
+
+<head>
+<body>
+
+<div id="app">
+    <md-sidenav class="md-left" ref="leftSidenav" @open="open('Left')" @close="close('Left')">
+        <md-toolbar class="md-large">
+            <div class="md-toolbar-container">
+                <h3 class="md-title">Sidenav content</h3>
+            </div>
+        </md-toolbar>
+
+        <md-list>
+            <md-list-item>
+                <md-icon>whatshot</md-icon>
+                <span>Lights</span>
+
+                <md-list-expand>
+                    <md-list>
+                        <md-list-item class="md-inset">World</md-list-item>
+                        <md-list-item class="md-inset">Americas</md-list-item>
+                        <md-list-item class="md-inset">Europe</md-list-item>
+                    </md-list>
+                </md-list-expand>
+            </md-list-item>
+            <md-list-item @click.native="openAlert" class="md-inset">
+                 Logout
+             </md-list-item>
+        </md-list>
+    </md-sidenav>
+
+    <md-toolbar>
+        <md-button class="md-icon-button" @click.native="toggleLeftSidenav">
+            <md-icon>menu</md-icon>
+        </md-button>
+        <h2 class="md-title">Cloudron HUE</h2>
+    </md-toolbar>
+
+    <md-button class="md-raised md-accent">Login</md-button>
+</div>
+
+<script src="./js/bundle.js"></script>
+
+</body>
+</html>

Diff do ficheiro suprimidas por serem muito extensas
+ 845 - 0
frontend/js/bundle.js


+ 29 - 0
frontend/js/main.js

@@ -0,0 +1,29 @@
+var util = require('util');
+
+console.log(util.format('Hello %s', 'world'));
+
+var Vue = require('vue'),
+    VueMaterial = require('vue-material');
+
+Vue.use(VueMaterial);
+
+var App = new Vue({
+    el: '#app',
+    methods: {
+        toggleLeftSidenav() {
+            this.$refs.leftSidenav.toggle();
+        },
+        toggleRightSidenav() {
+            this.$refs.rightSidenav.toggle();
+        },
+        closeRightSidenav() {
+            this.$refs.rightSidenav.close();
+        },
+        open(ref) {
+            console.log('Opened: ' + ref);
+        },
+        close(ref) {
+            console.log('Closed: ' + ref);
+        }
+    }
+});

+ 21 - 0
package.json

@@ -0,0 +1,21 @@
+{
+  "name": "cloudron-hue",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "body-parser": "^1.17.2",
+    "color": "^1.0.3",
+    "express": "^4.15.3",
+    "node-hue-api": "^2.4.2",
+    "vue-material": "^0.7.1"
+  },
+  "browser": {
+    "vue": "vue/dist/vue.common.js"
+  }
+}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff