progress
This commit is contained in:
parent
801dd73469
commit
5b5e0b3c64
@ -6,6 +6,7 @@ class SSH(object):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def __init__(self, devices):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
self.devices = {}
|
||||
for device in devices:
|
||||
self.devices[device] = {}
|
||||
self.devices[device]['user'] = devices[device]['user']
|
||||
@ -25,6 +26,30 @@ class SSH(object):
|
||||
if(command=="upgrade"):
|
||||
self.upgrade(device)
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def config(self):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
config = {
|
||||
"device" : {
|
||||
"name" : "",
|
||||
"ip" : "",
|
||||
"user" : ""
|
||||
},
|
||||
"shutdown" : {
|
||||
"device" : "name",
|
||||
"state" : "button"
|
||||
},
|
||||
"reboot" : {
|
||||
"device" : "name",
|
||||
"state" : "button"
|
||||
},
|
||||
"upgrade" : {
|
||||
"device" : "name",
|
||||
"state" : "button"
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def shutdown(self, device):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
|
@ -7,9 +7,23 @@ class WOL(object):
|
||||
def __init__(self, devices):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
count = 0
|
||||
self.devices= {}
|
||||
for device in devices:
|
||||
self.devices[device] = devices[device]['mac']
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def config(self):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
config = {
|
||||
"device" : {
|
||||
"name" : "",
|
||||
"mac" : ""
|
||||
},
|
||||
"wake" : {
|
||||
"device" : "name",
|
||||
"state" : "button"
|
||||
}
|
||||
}
|
||||
return config
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def wakeDevice(self, device):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
|
@ -26,6 +26,81 @@ class Yeelight(object):
|
||||
except:
|
||||
print(bulb + " ist in keiner Gruppe")
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def config(self):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
config = {
|
||||
"rgb" : {
|
||||
"device" : {
|
||||
"name" : "",
|
||||
"ip" : "",
|
||||
"type" : "rgb"
|
||||
},
|
||||
"power" : {
|
||||
"device" : "name",
|
||||
"state" : "switch"
|
||||
},
|
||||
"brightness" : {
|
||||
"device" : "name",
|
||||
"state" : "dimmer"
|
||||
},
|
||||
"temperature" : {
|
||||
"device" : "name",
|
||||
"state" : "dimmer"
|
||||
},
|
||||
"color" : {
|
||||
"device" : "name",
|
||||
"r" : "dimmer",
|
||||
"g" : "dimmer",
|
||||
"b" : "dimmer"
|
||||
}
|
||||
},
|
||||
"white" : {
|
||||
"device" : {
|
||||
"name": "",
|
||||
"ip" : "",
|
||||
"type" : "white"
|
||||
},
|
||||
"power" : {
|
||||
"device" : "name",
|
||||
"state" : "switch"
|
||||
},
|
||||
"brightness" : {
|
||||
"device" : "name",
|
||||
"state" : "dimmer"
|
||||
},
|
||||
"temperature" : {
|
||||
"device" : "name",
|
||||
"state" : "dimmer"
|
||||
}
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def state(self):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
state = {}
|
||||
for bulb in self.bulbs:
|
||||
state[bulb] = {}
|
||||
try:
|
||||
properties = self.bulbs[bulb].get_properties()
|
||||
except:
|
||||
state[bulb]['offline'] = True
|
||||
finally:
|
||||
state[bulb]['offline'] = False
|
||||
state[bulb]['power'] = properties['power']
|
||||
state[bulb]['brightness'] = properties['bright']
|
||||
state[bulb]['temperature'] = properties['ct']
|
||||
state[bulb]['color'] = properties['rgb']
|
||||
state[bulb]['groups'] = {}
|
||||
for group in self.groups:
|
||||
if(bulb in self.groups[group]):
|
||||
state[bulb]['groups'][group] = ""
|
||||
#r, g, b = tuple(int(properties['rgb'][i:i+2], 16) for i in (0, 2 ,4))
|
||||
#print("r:" + str(r) + " g: " + str(g) + " b: " + str(b))
|
||||
return state
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def command(self, data):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
|
@ -1,4 +1,4 @@
|
||||
from flask import Flask, request
|
||||
from flask import Flask, request, jsonify
|
||||
|
||||
|
||||
##---------------------------------------------------------------------------------------##
|
||||
@ -10,6 +10,29 @@ class Webserver(object):
|
||||
print("Webserver initialisiert")
|
||||
self.settings = config.read("settings")
|
||||
self.devices = config.read("devices")
|
||||
self.config = {}
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def createConfig(self, module, devices, config):
|
||||
##-----------------------------------------------------------------------------------##
|
||||
#print("Module: " + str(module))
|
||||
#print("Devices: " + str(devices))
|
||||
#print("Config: " + str(config))
|
||||
self.config[module] = {}
|
||||
if(module == "yeelight"):
|
||||
for device in devices:
|
||||
self.config[module][device] = {}
|
||||
self.config[module][device] = self.devices[module][device]
|
||||
if(devices[device]['type'] == "rgb"):
|
||||
self.config[module][device]['config'] = config['rgb']
|
||||
if(devices[device]['type'] == "white"):
|
||||
self.config[module][device]['config'] = config['white']
|
||||
return
|
||||
|
||||
for device in devices:
|
||||
self.config[module][device] = {}
|
||||
self.config[module][device] = self.devices[module][device]
|
||||
self.config[module][device]['config'] = config
|
||||
|
||||
##-----------------------------------------------------------------------------------##
|
||||
def run(self):
|
||||
@ -20,8 +43,11 @@ class Webserver(object):
|
||||
print("Enabled Yeelight")
|
||||
from app.devices import yeelight
|
||||
self.yeelight = yeelight.Yeelight(self.devices['yeelight'])
|
||||
devices = self.devices['yeelight']
|
||||
config = self.yeelight.config()
|
||||
self.createConfig("yeelight", devices, config)
|
||||
|
||||
@app.route('/yeelight', methods=['POST'])
|
||||
@app.route('/rest/yeelight', methods=['POST'])
|
||||
def yeelight():
|
||||
app.logger.debug("JSON received...")
|
||||
app.logger.debug(request.json)
|
||||
@ -38,8 +64,11 @@ class Webserver(object):
|
||||
print("Enabled SSH")
|
||||
from app.devices import ssh
|
||||
self.ssh = ssh.SSH(self.devices['ssh'])
|
||||
devices = self.devices['ssh']
|
||||
config = self.ssh.config()
|
||||
self.createConfig("ssh", devices, config)
|
||||
|
||||
@app.route('/ssh', methods=['POST'])
|
||||
@app.route('/rest/ssh', methods=['POST'])
|
||||
def ssh():
|
||||
app.logger.debug("JSON received...")
|
||||
app.logger.debug(request.json)
|
||||
@ -56,8 +85,11 @@ class Webserver(object):
|
||||
print("Enabled WOL")
|
||||
from app.devices import wol
|
||||
self.wol = wol.WOL(self.devices['wol'])
|
||||
devices = self.devices['wol']
|
||||
config = self.wol.config()
|
||||
self.createConfig("wol", devices, config)
|
||||
|
||||
@app.route('/wol', methods=['POST'])
|
||||
@app.route('/rest/wol', methods=['POST'])
|
||||
def wol():
|
||||
app.logger.debug("JSON received...")
|
||||
app.logger.debug(request.json)
|
||||
@ -70,22 +102,29 @@ class Webserver(object):
|
||||
else:
|
||||
print("Disabled SSH")
|
||||
|
||||
if(self.devices['denon'] != None):
|
||||
print("Enabled Denon")
|
||||
from app.devices import denon
|
||||
self.denon = wol.WOL(self.devices['denon'])
|
||||
#if(self.devices['denon'] != None):
|
||||
# print("Enabled Denon")
|
||||
# from app.devices import denon
|
||||
# self.denon = denon.Denon(self.devices['denon'])
|
||||
# devices = self.devices['denon']
|
||||
# config = self.denon.config()
|
||||
# self.createConfig("denon", devices, config)
|
||||
|
||||
@app.route('/denon', methods=['POST'])
|
||||
def denon():
|
||||
app.logger.debug("JSON received...")
|
||||
app.logger.debug(request.json)
|
||||
if request.json:
|
||||
data = request.get_json(force=True)
|
||||
self.denon.command(data)
|
||||
return '200'
|
||||
else:
|
||||
return '500'
|
||||
else:
|
||||
print("Disabled Denon")
|
||||
# @app.route('/rest/denon', methods=['POST'])
|
||||
# def denon():
|
||||
# app.logger.debug("JSON received...")
|
||||
# app.logger.debug(request.json)
|
||||
# if request.json:
|
||||
# data = request.get_json(force=True)
|
||||
# self.denon.command(data)
|
||||
# return '200'
|
||||
# else:
|
||||
# return '500'
|
||||
#else:
|
||||
# print("Disabled Denon")
|
||||
|
||||
app.run(debug=False, host='0.0.0.0')
|
||||
@app.route('/rest/config', methods=['GET'])
|
||||
def config():
|
||||
return jsonify(self.config)
|
||||
|
||||
app.run(debug=True, host='0.0.0.0')
|
@ -2,19 +2,34 @@
|
||||
"yeelight" : {
|
||||
"fernseher" : {
|
||||
"ip" : "192.168.178.127",
|
||||
"type" : "rgb"
|
||||
"type" : "rgb",
|
||||
"groups" : {
|
||||
"zimmer" : "zimmer",
|
||||
"passiv" : "passiv"
|
||||
}
|
||||
},
|
||||
"regal" : {
|
||||
"ip" : "192.168.178.128",
|
||||
"type" : "rgb"
|
||||
"type" : "rgb",
|
||||
"groups" : {
|
||||
"zimmer" : "zimmer",
|
||||
"passiv" : "passiv"
|
||||
}
|
||||
},
|
||||
"monitor" : {
|
||||
"ip" : "192.168.178.126",
|
||||
"type" : "rgb"
|
||||
"type" : "rgb",
|
||||
"groups" : {
|
||||
"zimmer" : "zimmer",
|
||||
"passiv" : "passiv"
|
||||
}
|
||||
},
|
||||
"bett" : {
|
||||
"ip" : "192.168.178.122",
|
||||
"type" : "rgb"
|
||||
"type" : "rgb",
|
||||
"groups" : {
|
||||
"zimmer" : "zimmer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ssh" : {
|
||||
|
@ -1,8 +1,8 @@
|
||||
# TODO
|
||||
|
||||
1. Return available commands
|
||||
2. Presets (Yeelight)
|
||||
3. Website.....
|
||||
1. ~~Return available commands~~
|
||||
2. Presets (Yeelight) .... Progress
|
||||
3. Website..... Progress
|
||||
4. Yamaha Receiver
|
||||
5. Yeelight Flow
|
||||
6. Wecker
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="container-fluid text-center bg-grey">
|
||||
<div class="yeelight container-fluid text-center bg-grey">
|
||||
<h2>Lampen</h2>
|
||||
<div class="row text-center">
|
||||
<div class="col-sm-4 bg-grey">
|
||||
|
0
www/html/yeelight.html
Normal file
0
www/html/yeelight.html
Normal file
181
www/js/cm.js
181
www/js/cm.js
@ -2,61 +2,204 @@
|
||||
// CM - Hauptfunktion
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class CM
|
||||
{
|
||||
constructor ()
|
||||
{
|
||||
this.BodyDataAction();
|
||||
var config = {}
|
||||
|
||||
console.log("CM LOADED");
|
||||
}
|
||||
|
||||
BodyDataAction ()
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function bodyDataAction ()
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
var menuButtons = document.getElementById("navbarBtn").
|
||||
getElementsByTagName("button");
|
||||
for (var i = 0; i < menuButtons.length; i++) {
|
||||
menuButtons[i].onclick = function(evt) {
|
||||
var res = evt.target.id;
|
||||
CM_o.Menu(res);
|
||||
menu(res);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Menu (message)
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function menu (message, request=null)
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
var selectedId = $(".selected").attr('id');
|
||||
switch (message)
|
||||
{
|
||||
case 'pageDevices':
|
||||
console.log( "pageDevices")
|
||||
this.LoadContent('html/devices.html');
|
||||
//loadContent('html/devices.html');
|
||||
generateDevices();
|
||||
document.getElementById('pageDevices').className = "btn btn-outline-light text-dark active";
|
||||
document.getElementById('pageSettings').className = "btn btn-outline-light text-dark";
|
||||
break;
|
||||
case 'pageSettings':
|
||||
console.log( "pageDevices")
|
||||
this.LoadContent('html/settings.html');
|
||||
//loadContent('html/settings.html');
|
||||
document.getElementById('pageDevices').className = "btn btn-outline-light text-dark";
|
||||
document.getElementById('pageSettings').className = "btn btn-outline-light text-dark active";
|
||||
break;
|
||||
case 'switchRequest':
|
||||
console.log( request )
|
||||
switchRequest(request);
|
||||
break;
|
||||
default:
|
||||
alert ('[CM] Unbekannte Anfrage: ' + message);
|
||||
}
|
||||
}
|
||||
|
||||
LoadContent ( path )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function switchRequest (request)
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
$.get( path, function( data ) {
|
||||
var req = request.split(".");
|
||||
switch (req[0])
|
||||
{
|
||||
case 'yeelight':
|
||||
var bulb = req[1]
|
||||
var type = req[2]
|
||||
var value = req[3]
|
||||
var cmd = {};
|
||||
cmd[bulb] = {};
|
||||
cmd[bulb][type] = value;
|
||||
postYeelight(cmd);
|
||||
break;
|
||||
default:
|
||||
alert ('[POST] Unbekannte Anfrage: ' + req[0]);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function generateYeelightBulbs ( data , type)
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
$( ".content" ).append($('<div class="yeelight'+type+' container-fluid text-center bg-grey">'));
|
||||
$( ".yeelight"+type ).append($("<h3></h3>").text("Yeelight " + type));
|
||||
$( ".yeelight"+type ).append($('<div class="yeelight'+type+'row row text-center">'));
|
||||
for (bulb in data)
|
||||
{
|
||||
$( ".yeelight"+type+"row" ).append($('<div class="'+ bulb + 'col col-sm-3 bg-grey">'));
|
||||
$( "." + bulb + "col" ).append($("<p></p>").text(bulb));
|
||||
$( "." + bulb + "col" ).append($('<div class="' + bulb + 'btn btn-group">'));
|
||||
var configBulb = data[bulb]['config']
|
||||
for (setting in configBulb)
|
||||
{
|
||||
if (configBulb[setting]['state'] == "switch")
|
||||
{
|
||||
var command = "on";
|
||||
$( "." + bulb + "btn" ).append($('<button '+
|
||||
'id="yeelight.'+bulb+'.'+setting+'.on" ' +
|
||||
'type="button" class="' + bulb + 'btnAn btn btn-primary">An</button>'));
|
||||
var buttonOn = document.getElementById('yeelight.'+bulb+'.'+setting+'.on');
|
||||
buttonOn.onclick = function(evt) {
|
||||
var res = evt.target.id;
|
||||
menu('switchRequest', res);}
|
||||
var command = "off";
|
||||
$( "." + bulb + "btn" ).append($('<button '+
|
||||
'id="yeelight.'+bulb+'.'+setting+'.off" ' +
|
||||
'type="button" class="' + bulb + 'btnAn btn btn-primary">Aus</button>'));
|
||||
var buttonOff = document.getElementById('yeelight.'+bulb+'.'+setting+'.off');
|
||||
buttonOff.onclick = function(evt) {
|
||||
var res = evt.target.id;
|
||||
menu('switchRequest', res);}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function generateYeelightGroups ( data )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
console.log(data);
|
||||
var groups = {}
|
||||
for (bulb in data)
|
||||
{
|
||||
for (group in data[bulb]['groups'])
|
||||
{
|
||||
if (group in groups)
|
||||
{
|
||||
//groups[group] = data[bulb];
|
||||
}
|
||||
else
|
||||
{
|
||||
groups[group] = {};
|
||||
groups[group] = data[bulb];
|
||||
}
|
||||
}
|
||||
};
|
||||
console.log(groups);
|
||||
generateYeelightBulbs(groups,"Gruppen");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function generateYeelight ( data )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
generateYeelightBulbs(data,"Bulbs");
|
||||
generateYeelightGroups(data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function generateDevices ( )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
for (module in config)
|
||||
{
|
||||
if(module == "yeelight")
|
||||
{
|
||||
generateYeelight(config[module]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function getConfig ( )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
$.ajax('/rest/config', {
|
||||
type : 'GET',
|
||||
dataType: "json",
|
||||
success : function(data) {
|
||||
config = data;
|
||||
bodyDataAction();
|
||||
menu("pageDevices");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function postYeelight ( cmd )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
$.ajax('/rest/yeelight', {
|
||||
type : 'POST',
|
||||
dataType: "json",
|
||||
contentType: 'application/json',
|
||||
data : JSON.stringify(cmd),
|
||||
success : function(data) {
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
function loadContent ( content )
|
||||
//-----------------------------------------------------------------------------------//
|
||||
{
|
||||
$.get( content, function( data ) {
|
||||
$( ".content" ).html( data );
|
||||
console.log( "Load was performed." );
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------//
|
||||
$(function() {
|
||||
console.log("ONLOAD");
|
||||
CM_o = new CM();
|
||||
CM_o.Menu("pageDevices");
|
||||
|
||||
getConfig();
|
||||
|
||||
console.log("CM LOADED");
|
||||
});
|
||||
//-----------------------------------------------------------------------------------//
|
Reference in New Issue
Block a user