Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from DewGew/beta
Browse files Browse the repository at this point in the history
Merge Beta
DewGew authored Jan 26, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e476965 + bd39f62 commit a5ea23e
Showing 9 changed files with 956 additions and 852 deletions.
83 changes: 41 additions & 42 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,89 @@
import os
import sys
from pathlib import Path
import socketserver

from const import PUBLIC_URL
from server import *
from auth import *
from smarthome import *
from helpers import configuration
from const import VERSION, PUBLIC_URL

if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel'] == True:
from pyngrok import ngrok

tunnel = PUBLIC_URL


class ThreadingSimpleServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
pass

def requestDevicesSync():
SmartHomeReqHandler.forceDevicesSync()



def startServer():
global tunnel
# Create tunnel if ngrok_tunnel set to true
if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel'] == True:
if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel'] is True:
try:
if 'ngrok_auth_token' in configuration and configuration['ngrok_auth_token'] != 'auth_token':
ngrok.set_auth_token(configuration['ngrok_auth_token'])
else:
logger.info('If you use the ngrok tunnel option without account the tunnel will be terminated after 5 or 6 hours')
logger.info(
'If you use the ngrok tunnel option without account the tunnel will be terminated after 5 or 6 hours')
public_url = ngrok.connect(configuration['port_number'])
tunnel = public_url.replace("http", "https")
except Exception as e:
logger.error ('Ngrok was unable to start. Error: %s is not valid' % (e))
except Exception as err:
logger.error('Ngrok was unable to start. Error: %s is not valid' % err)
try:
# Create a web server and define the handler to manage the
# incoming request
server = ThreadingSimpleServer(('', configuration['port_number']), AogServer)
logger.info ('========')
logger.info ('Started DZGA v' + VERSION + ' server at port ' + str(configuration['port_number']))
logger.info (' ')
if 'userinterface' in configuration and configuration['userinterface'] == True:
logger.info (' Visit http://localhost:' + str(configuration['port_number']) + '/settings to access the user interface')
logger.info('========')
logger.info('Started DZGA v' + VERSION + ' server at port ' + str(configuration['port_number']))
logger.info(' ')
if 'userinterface' in configuration and configuration['userinterface'] is True:
logger.info(' Visit http://localhost:' + str(
configuration['port_number']) + '/settings to access the user interface')
else:
logger.info (' Configure your settings in config.yaml in Domoticz-Google-Assistant folder')
logger.info (' ')
logger.info(' Configure your settings in config.yaml in Domoticz-Google-Assistant folder')
logger.info(' ')
logger.info('=========')
logger.info ('Visit the Actions on Google console at http://console.actions.google.com')
logger.info ('Under Develop section, replace the fulfillment URL in Actions with:')
logger.info (' ' + tunnel + '/smarthome')
logger.info (' ')
logger.info ('In Account linking, set the Authorization URL to:')
logger.info (' ' + tunnel + '/oauth')
logger.info (' ')
logger.info ('Then set the Token URL to:')
logger.info (' ' + tunnel + '/token')
logger.info (' ')
logger.info ('Finally press \'SAVE\' and then \'TEST\' button')
if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel'] == True:
logger.info ('** NOTE: Ngrok assigns random urls. When server restart the server gets a new url')
logger.info ('=======')
logger.info('Visit the Actions on Google console at http://console.actions.google.com')
logger.info('Under Develop section, replace the fulfillment URL in Actions with:')
logger.info(' ' + tunnel + '/smarthome')
logger.info(' ')
logger.info('In Account linking, set the Authorization URL to:')
logger.info(' ' + tunnel + '/oauth')
logger.info(' ')
logger.info('Then set the Token URL to:')
logger.info(' ' + tunnel + '/token')
logger.info(' ')
logger.info('Finally press \'SAVE\' and then \'TEST\' button')
if 'ngrok_tunnel' in configuration and configuration['ngrok_tunnel'] is True:
logger.info('** NOTE: Ngrok assigns random urls. When server restart the server gets a new url')
logger.info('=======')
print("(Press CTRL+C to stop server)")
# Sync with domoticz at startup
try:
getDevices()
getSettings()
except:
except (ValueError, Exception):
pass
# Exit if running on travis
istravis = os.environ.get('TRAVIS') == 'true'
if istravis == True:
if istravis:
logger.info('Travis test is finished')
exit()
# Wait forever for incoming http requests
server.serve_forever()

except (KeyboardInterrupt, SystemExit):
print()
logger.info ('^C received, shutting down the web server')
logger.info('^C received, shutting down the web server')
server.socket.close()


if __name__ == "__main__":
# Execute only if run as a script

for path,value in {**oauthGetMappings, **smarthomeGetMappings}.items():
for path, value in {**oauthGetMappings, **smarthomeGetMappings}.items():
addGetMappings(path, value)
for path,value in {**oauthPostMappings, **smarthomePostMappings}.items():

for path, value in {**oauthPostMappings, **smarthomePostMappings}.items():
addPostMappings(path, value)

startServer()
Loading

0 comments on commit a5ea23e

Please sign in to comment.