def getActualBackgroundPath():
    localDatabase = database.LocalDatabase()
    background = localDatabase.getConfig('panel_background')
    backgroundPath = localDatabase.getBackgroundPath(background)
    localDatabase.close()
    emit('getActualBackgroundPath',
         {'data': json.dumps({'path': backgroundPath})})
    def __checkDatabaseOrder(self):
        localDatabase = database.LocalDatabase()
        if localDatabase.getPositions("switchRow") == None:
            idList = []
            for device in (self.getStatusOfFavoriteDevicesLight()):
                idList.append(device["idx"])
            orderValue = {"order": idList}
            localDatabase.insertPositions("switchRow", orderValue)

        if localDatabase.getPositions("sensorRow") == None:
            idList = []
            for device in (self.getStatusOfFavoriteDevicesTemp()):
                idList.append(device["idx"])
            orderValue = {"order": idList}
            localDatabase.insertPositions("sensorRow", orderValue)

        if localDatabase.getPositions("sceneRow") == None:
            idList = []
            for device in (self.getFavoriteScenes()):
                idList.append(device["idx"])
            orderValue = {"order": idList}
            localDatabase.insertPositions("sceneRow", orderValue)

        if localDatabase.getPositions("weatherRow") == None:
            idList = []
            for device in (self.getOfFavoriteDevicesWeather()):
                idList.append(device["idx"])
            orderValue = {"order": idList}
            localDatabase.insertPositions("weatherRow", orderValue)
 def getStatusOfFavoriteDevicesTemp(self):
     data = self.connector.sendAndReceiveData(
         'type=devices&used=true&filter=temp&favorite=1')
     if data == False: return False
     else:
         output = []
         for device in data['result']:
             try:
                 localDatabase = database.LocalDatabase()
                 output.append({
                     "Name": device["Name"],
                     "idx": device["idx"],
                     "Data": device["Data"],
                     "Type": device["Type"],
                     "LastUpdate": device["LastUpdate"],
                     "TypeImg": device["TypeImg"]
                 })
                 if not self.__searchInDatabase(device["idx"], "sensorRow"):
                     positions = localDatabase.getPositions("sensorRow")
                     positions.append(device["idx"])
                     localDatabase.updatePositions("sensorRow",
                                                   {"order": positions})
             except Exception as e:
                 print(e)
         return output
 def getStatusOfFavoriteDevicesLight(self):
     data = self.connector.sendAndReceiveData(
         'type=devices&used=true&filter=light&favorite=1')
     if data == False: return False
     else:
         output = []
         for device in data['result']:
             try:
                 localDatabase = database.LocalDatabase()
                 if device["Name"]:  #filter devices only with name
                     tmpJson = {
                         "Name": device["Name"],
                         "idx": device["idx"],
                         "Status": device["Status"],
                         "SwitchType": device["SwitchType"],
                         "Level": device["Level"],
                         "DimmerType": device["DimmerType"],
                         "LastUpdate": device["LastUpdate"],
                         "Image": device["Image"]
                     }
                     if device["SwitchType"] == "Selector":
                         tmpJson["LevelNames"] = base64.b64decode(
                             device["LevelNames"].encode("utf-8")).decode(
                                 "utf-8").split("|")
                     if not self.__searchInDatabase(tmpJson["idx"],
                                                    "switchRow"):
                         positions = localDatabase.getPositions("switchRow")
                         positions.append(tmpJson["idx"])
                         localDatabase.updatePositions(
                             "switchRow", {"order": positions})
                     output.append(tmpJson)  #append only specyfic values
             except Exception as e:
                 print(e)
         return output
def getStatusOfFavoriteDevicesTemp():
    data = domoticz.getStatusOfFavoriteDevicesTemp()
    localDatabase = database.LocalDatabase()
    emit('getTempDevice', {
        'data': json.dumps(data),
        'order': localDatabase.getPositions("sensorRow")
    })
    localDatabase.close()
def getFavoriteScenes():
    localDatabase = database.LocalDatabase()
    data = domoticz.getFavoriteScenes()
    emit('getFavoriteScenes', {
        'data': json.dumps(data),
        'order': localDatabase.getPositions("sceneRow")
    })
    localDatabase.close()
def getStatusOfFavoriteDevicesLight():
    data = domoticz.getStatusOfFavoriteDevicesLight()
    localDatabase = database.LocalDatabase()
    emit('getLightDevice', {
        'data': json.dumps(data),
        'order': localDatabase.getPositions("switchRow")
    })
    localDatabase.close()
예제 #8
0
 def reloadConnectionParams(self):
     localDatabase = database.LocalDatabase()
     self.username = utils.hashText(
         localDatabase.getConfig('controller_username'))
     self.password = localDatabase.getConfig('controller_password')
     self.ip = localDatabase.getConfig('controller_ip')
     self.port = int(localDatabase.getConfig('controller_port'))
     localDatabase.close()
def getFavoriteWeather():
    localDatabase = database.LocalDatabase()
    data = domoticz.getOfFavoriteDevicesWeather()
    emit(
        'getWeatherDevice', {
            'data': json.dumps(data),
            'order': localDatabase.getPositions("weatherRow")
        })
    localDatabase.close()
 def __searchInDatabase(self, idx, positionType):
     try:
         localDatabase = database.LocalDatabase()
         positions = localDatabase.getPositions(positionType)
         found = False
         for position in positions:
             if position == idx:
                 found = True
                 break
         return found
     except Exception as e:
         print(e)
         return True
def deleteBackground(data):
    localDatabase = database.LocalDatabase()
    if data['background'] != 'default 1' and data['background'] != 'default 2':
        if data['background'] == localDatabase.getConfig('panel_background'):
            localDatabase.updateConfig('panel_background', 'default 1')
        tmpPath = 'static/' + localDatabase.getBackgroundPath(
            data['background'])
        if os.path.exists(tmpPath):
            os.remove(tmpPath)
        localDatabase.deleteBackground(data['background'])
    getBackgrounds()
    getActualBackground()
    getActualBackgroundPath()
    setBackground({'background': localDatabase.getConfig('panel_background')})
    localDatabase.close()
def getFullConfig(data):
    localDatabase = database.LocalDatabase()
    noHash = False
    if data['controller_password'] == 'HaHa! No way...':
        noHash = True
        data['controller_password'] = localDatabase.getConfig(
            'controller_password')
    for configName in data:
        if configName == 'controller_password':
            if (noHash):
                localDatabase.updateConfig(configName, data[configName])
            else:
                localDatabase.updateConfig(configName,
                                           utils.hashText(data[configName]))
        else:
            localDatabase.updateConfig(configName, data[configName])
    localDatabase.close()
    domoticz.reloadConnection()
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and allowedFile(file.filename):
            file.save(
                os.path.join(BACGROUND_UPLOAD_FOLDER,
                             file.filename.replace(' ', '')))
            localDatabase = database.LocalDatabase()
            localDatabase.addBackground(
                file.filename.split('.')[0],
                f'img/upload/{file.filename}'.replace(' ', ''))
            localDatabase.close()
            return redirect(request.url)
    return redirect(request.url)
 def getFavoriteScenes(self):
     data = self.connector.sendAndReceiveData('type=scenes&favorite=1')
     if data == False: return False
     else:
         localDatabase = database.LocalDatabase()
         output = []
         try:
             for scene in data['result']:
                 output.append({
                     "Name": scene["Name"],
                     "idx": scene["idx"],
                     "Type": scene["Type"],
                     "LastUpdate": scene["LastUpdate"],
                     "Image": "Scene"
                 })
                 if not self.__searchInDatabase(scene["idx"], "sceneRow"):
                     positions = localDatabase.getPositions("sceneRow")
                     positions.append(scene["idx"])
                     localDatabase.updatePositions("sceneRow",
                                                   {"order": positions})
         except:
             pass
         return output
예제 #15
0
from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import database
from api import api
import os
import sys
sys.path.append('../')
import records

PORT = 9090
HOST = '127.0.0.1'


class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/XmlRpcService')


server = SimpleXMLRPCServer((HOST, PORT),
                            requestHandler=RequestHandler,
                            allow_none=True)
server.register_introspection_functions()

print(os.path.join('sqlite_test', 'application.db'))

db = database.LocalDatabase(
    db_file=os.path.join('XMLRPC', 'sqlite_test', 'application.db'))
server.register_instance(api.Api(database=db))

print("The server is running at Port: " + PORT.__str__() + ", Host: " +
      HOST.__str__())

server.serve_forever()
def widgetOrder(data):
    localDatabase = database.LocalDatabase()
    localDatabase.updatePositions("sensorRow", {"order": data["sensorRow"]})
    localDatabase.updatePositions("switchRow", {"order": data["switchRow"]})
    localDatabase.updatePositions("sceneRow", {"order": data["sceneRow"]})
    localDatabase.close()
def getFullConfig():
    localDatabse = database.LocalDatabase()
    allSettings = localDatabse.getFullConfig()
    localDatabse.close()
    emit('getFullConfig', {'data': json.dumps(allSettings)})
def getBackgrounds():
    localDatabase = database.LocalDatabase()
    backgrounds = localDatabase.getBackgroundList()
    localDatabase.close()
    emit('getBackgrounds', {'data': json.dumps({'backgrounds': backgrounds})})
def getActualBackground():
    localDatabase = database.LocalDatabase()
    background = localDatabase.getConfig('panel_background')
    localDatabase.close()
    emit('getActualBackground',
         {'data': json.dumps({'background': background})})
def setBackground(data):
    localDatabase = database.LocalDatabase()
    localDatabase.updateConfig('panel_background', data['background'])
    localDatabase.close()