mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-08 07:53:36 +00:00
Merge branch 'develop' into master
This commit is contained in:
commit
27ca5125aa
12 changed files with 387 additions and 146 deletions
|
|
@ -16,6 +16,24 @@ from includes import globalVars # Global variables
|
|||
from includes.helper import configHandler
|
||||
from includes.helper import wildcardHandler
|
||||
|
||||
def isSignal(poc_id):
|
||||
"""
|
||||
@type poc_id: string
|
||||
@param poc_id: POCSAG Ric
|
||||
|
||||
@requires: Configuration has to be set in the config.ini
|
||||
|
||||
@return: True if the Ric is Signal, other False
|
||||
@exception: none
|
||||
"""
|
||||
# If RIC is Signal return True, else False
|
||||
if globalVars.config.get("POC", "netIdent_ric"):
|
||||
if poc_id in globalVars.config.get("POC", "netIdent_ric"):
|
||||
logging.info("RIC %s is net ident", poc_id)
|
||||
return True
|
||||
else:
|
||||
logging.info("RIC %s is no net ident", poc_id)
|
||||
return False
|
||||
|
||||
##
|
||||
#
|
||||
|
|
@ -61,6 +79,7 @@ def run(typ, freq, data):
|
|||
text = globalVars.config.get("Divera", "fms_text")
|
||||
title = globalVars.config.get("Divera", "fms_title")
|
||||
priority = globalVars.config.get("Divera", "fms_prio")
|
||||
vehicle = globalVars.config.get("Divera", "fms_vehicle")
|
||||
|
||||
elif typ == "ZVEI":
|
||||
#
|
||||
|
|
@ -68,25 +87,33 @@ def run(typ, freq, data):
|
|||
#
|
||||
text = globalVars.config.get("Divera", "zvei_text")
|
||||
title = globalVars.config.get("Divera", "zvei_title")
|
||||
priority = globalVars.config.get("Divera","zvei_std_prio")
|
||||
priority = globalVars.config.get("Divera","zvei_prio")
|
||||
zvei_id = globalVars.config.get("Divera","zvei_id")
|
||||
|
||||
elif typ == "POC":
|
||||
#
|
||||
# building message for POC
|
||||
#
|
||||
if data["function"] == '1':
|
||||
priority = globalVars.config.get("Divera", "SubA")
|
||||
elif data["function"] == '2':
|
||||
priority = globalVars.config.get("Divera", "SubB")
|
||||
elif data["function"] == '3':
|
||||
priority = globalVars.config.get("Divera", "SubC")
|
||||
elif data["function"] == '4':
|
||||
priority = globalVars.config.get("Divera", "SubD")
|
||||
if isSignal(data["ric"]):
|
||||
|
||||
logging.debug("RIC is net ident")
|
||||
return
|
||||
else:
|
||||
priority = ''
|
||||
#
|
||||
# building message for POC
|
||||
#
|
||||
if data["function"] == '1':
|
||||
priority = globalVars.config.get("Divera", "SubA")
|
||||
elif data["function"] == '2':
|
||||
priority = globalVars.config.get("Divera", "SubB")
|
||||
elif data["function"] == '3':
|
||||
priority = globalVars.config.get("Divera", "SubC")
|
||||
elif data["function"] == '4':
|
||||
priority = globalVars.config.get("Divera", "SubD")
|
||||
else:
|
||||
priority = ''
|
||||
|
||||
text = globalVars.config.get("Divera", "poc_text")
|
||||
title = globalVars.config.get("Divera", "poc_title")
|
||||
text = globalVars.config.get("Divera", "poc_text")
|
||||
title = globalVars.config.get("Divera", "poc_title")
|
||||
ric = globalVars.config.get("Divera", "poc_ric")
|
||||
|
||||
|
||||
else:
|
||||
logging.warning("Invalid type: %s", typ)
|
||||
|
|
@ -97,30 +124,91 @@ def run(typ, freq, data):
|
|||
# Divera-Request
|
||||
#
|
||||
logging.debug("send Divera for %s", typ)
|
||||
|
||||
# replace the wildcards
|
||||
text = wildcardHandler.replaceWildcards(text, data)
|
||||
title = wildcardHandler.replaceWildcards(title, data)
|
||||
|
||||
# Logging data to send
|
||||
# Replace wildcards & Logging data to send
|
||||
title = wildcardHandler.replaceWildcards(title, data)
|
||||
logging.debug("Title : %s", title)
|
||||
text = wildcardHandler.replaceWildcards(text, data)
|
||||
logging.debug("Text : %s", text)
|
||||
logging.debug("Priority: %s", priority)
|
||||
|
||||
if typ == "FMS":
|
||||
vehicle = wildcardHandler.replaceWildcards(vehicle, data)
|
||||
logging.debug("Vehicle : %s", vehicle)
|
||||
elif typ == "POC":
|
||||
ric = wildcardHandler.replaceWildcards(ric, data)
|
||||
logging.debug("RIC : %s", ric)
|
||||
elif typ == "ZVEI":
|
||||
zvei_id = wildcardHandler.replaceWildcards(zvei_id, data)
|
||||
logging.debug("ZVEI_ID : %s", zvei_id)
|
||||
else:
|
||||
logging.info("No wildcards to replace and no Typ selected!")
|
||||
|
||||
# check priority value
|
||||
if (priority != 'false') and (priority != 'true'):
|
||||
logging.info("No Priority set for type '%s'! Skipping Divera-Alarm!", typ)
|
||||
return
|
||||
|
||||
# start the connection
|
||||
conn = httplib.HTTPSConnection("www.divera247.com:443")
|
||||
conn.request("GET", "/api/alarm",
|
||||
urllib.urlencode({
|
||||
"accesskey": globalVars.config.get("Divera", "accesskey"),
|
||||
"title": title,
|
||||
"text": text,
|
||||
"priority": priority,
|
||||
}))
|
||||
# Check FMS
|
||||
if typ == "FMS":
|
||||
if (vehicle == ''):
|
||||
logging.info("No Vehicle set!")
|
||||
|
||||
# Check POC
|
||||
elif typ == "POC":
|
||||
if (ric == ''):
|
||||
logging.info("No RIC set!")
|
||||
|
||||
# Check ZVEI
|
||||
elif typ == "ZVEI":
|
||||
if (zvei_id == ''):
|
||||
logging.info("No ZVEI_ID set!")
|
||||
|
||||
else:
|
||||
logging.info("No ZVEI, FMS or POC alarm")
|
||||
|
||||
# start connection to Divera
|
||||
if typ == "FMS":
|
||||
# start the connection FMS
|
||||
conn = httplib.HTTPSConnection("www.divera247.com:443")
|
||||
conn.request("GET", "/api/fms",
|
||||
urllib.urlencode({
|
||||
"accesskey": globalVars.config.get("Divera", "accesskey"),
|
||||
"vehicle_ric": vehicle,
|
||||
"status_id": data["status"],
|
||||
"status_note": data["directionText"],
|
||||
"title": title,
|
||||
"text": text,
|
||||
"priority": priority,
|
||||
}))
|
||||
|
||||
elif typ == "ZVEI":
|
||||
# start connection ZVEI; zvei_id in Divera is alarm-RIC!
|
||||
conn = httplib.HTTPSConnection("www.divera247.com:443")
|
||||
conn.request("GET", "/api/alarm",
|
||||
urllib.urlencode({
|
||||
"accesskey": globalVars.config.get("Divera", "accesskey"),
|
||||
"title": title,
|
||||
"ric": zvei_id,
|
||||
"text": text,
|
||||
"priority": priority,
|
||||
}))
|
||||
|
||||
elif typ == "POC":
|
||||
# start connection POC
|
||||
conn = httplib.HTTPSConnection("www.divera247.com:443")
|
||||
conn.request("GET", "/api/alarm",
|
||||
urllib.urlencode({
|
||||
"accesskey": globalVars.config.get("Divera", "accesskey"),
|
||||
"title": title,
|
||||
"ric": ric,
|
||||
"text": text,
|
||||
"priority": priority,
|
||||
}))
|
||||
|
||||
|
||||
else:
|
||||
loggin.debug("No Type is set", exc_info=True)
|
||||
return
|
||||
|
||||
except:
|
||||
logging.error("cannot send Divera request")
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ In the data map are the folowing informations:
|
|||
- ric
|
||||
- function
|
||||
- functionChar
|
||||
- ricFuncChar
|
||||
- msg
|
||||
- bitrate
|
||||
- description
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ def run(typ,freq,data):
|
|||
bot = telegram.Bot(token='%s' % BOTTokenAPIKey)
|
||||
# Send message to chat via Telegram BOT API
|
||||
logging.debug("Send message to chat via Telegram BOT API")
|
||||
bot.sendMessage('%s' % BOTChatIDAPIKey, text)
|
||||
bot.sendMessage('%s' % BOTChatIDAPIKey, text, parse_mode=telegram.ParseMode.HTML)
|
||||
|
||||
# Generate location information only for specific RIC
|
||||
if typ == "POC" and data["ric"] == RICforLocationAPIKey:
|
||||
|
|
|
|||
113
plugins/fhemCmd/fhemCmd.py
Normal file
113
plugins/fhemCmd/fhemCmd.py
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
"""
|
||||
Plugin for calling FHEM home automation
|
||||
|
||||
@author: Marco Schotthöfer
|
||||
|
||||
@requires: python-fhem (pip install fhem)
|
||||
"""
|
||||
|
||||
#
|
||||
# Imports
|
||||
#
|
||||
import logging # Global logger
|
||||
from includes import globalVars # Global variables
|
||||
|
||||
# Helper function, uncomment to use
|
||||
#from includes.helper import timeHandler
|
||||
#from includes.helper import wildcardHandler
|
||||
from includes.helper import configHandler
|
||||
from includes.helper import wildcardHandler
|
||||
import fhem
|
||||
|
||||
##
|
||||
#
|
||||
# onLoad (init) function of plugin
|
||||
# will be called one time by the pluginLoader on start
|
||||
#
|
||||
def onLoad():
|
||||
"""
|
||||
While loading the plugins by pluginLoader.loadPlugins()
|
||||
this onLoad() routine is called one time for initialize the plugin
|
||||
|
||||
@requires: nothing
|
||||
|
||||
@return: nothing
|
||||
@exception: Exception if init has an fatal error so that the plugin couldn't work
|
||||
|
||||
"""
|
||||
try:
|
||||
########## User onLoad CODE ##########
|
||||
pass
|
||||
########## User onLoad CODE ##########
|
||||
except:
|
||||
logging.error("unknown error")
|
||||
logging.debug("unknown error", exc_info=True)
|
||||
raise
|
||||
|
||||
##
|
||||
#
|
||||
# Main function of plugin
|
||||
# will be called by the alarmHandler
|
||||
#
|
||||
def run(typ,freq,data):
|
||||
"""
|
||||
This function is the implementation of the Plugin.
|
||||
|
||||
If necessary the configuration hast to be set in the config.ini.
|
||||
|
||||
@type typ: string (FMS|ZVEI|POC)
|
||||
@param typ: Typ of the dataset
|
||||
@type data: map of data (structure see readme.md in plugin folder)
|
||||
@param data: Contains the parameter for dispatch
|
||||
@type freq: string
|
||||
@keyword freq: frequency of the SDR Stick
|
||||
|
||||
@requires: If necessary the configuration hast to be set in the config.ini.
|
||||
|
||||
@return: nothing
|
||||
@exception: nothing, make sure this function will never thrown an exception
|
||||
"""
|
||||
try:
|
||||
if configHandler.checkConfig("fhemCmd"): #read and debug the config (let empty if no config used)
|
||||
|
||||
protocol = globalVars.config.get("fhemCmd", "protocol")
|
||||
logging.debug("protocol: %s", protocol)
|
||||
|
||||
server = globalVars.config.get("fhemCmd", "server")
|
||||
logging.debug("server: %s", server)
|
||||
|
||||
port = globalVars.config.get("fhemCmd", "port")
|
||||
logging.debug("port: %s", port)
|
||||
|
||||
username = globalVars.config.get("fhemCmd", "username")
|
||||
logging.debug("username: %s", username)
|
||||
|
||||
password = globalVars.config.get("fhemCmd", "password")
|
||||
logging.debug("password: %s", password)
|
||||
|
||||
########## User Plugin CODE ##########
|
||||
if typ == "FMS":
|
||||
fhemCommand = globalVars.config.get("fhemCmd", "commandFMS")
|
||||
elif typ == "ZVEI":
|
||||
fhemCommand = globalVars.config.get("fhemCmd", "commandZVEI")
|
||||
elif typ == "POC":
|
||||
fhemCommand = globalVars.config.get("fhemCmd", "commandPOC")
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
return False
|
||||
|
||||
fhemCommand = wildcardHandler.replaceWildcards(fhemCommand, data)
|
||||
logging.debug("fhemCommand: %s", fhemCommand)
|
||||
|
||||
fh = fhem.Fhem(server=server, protocol=protocol, port=port, username=username, password=password)
|
||||
|
||||
fh.send_cmd(fhemCommand)
|
||||
del fh
|
||||
########## User Plugin CODE ##########
|
||||
|
||||
except:
|
||||
logging.error("unknown error")
|
||||
logging.debug("unknown error", exc_info=True)
|
||||
1
plugins/fhemCmd/requirements.txt
Normal file
1
plugins/fhemCmd/requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
fhem
|
||||
|
|
@ -92,14 +92,14 @@ def run(typ,freq,data):
|
|||
#logging.warning("%s not supported", typ)
|
||||
elif typ == "POC":
|
||||
if globalVars.config.get("gpiocontrol", "activerics") == "":
|
||||
th = threading.Thread(target = trigger)
|
||||
th.start()
|
||||
else
|
||||
if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"):
|
||||
th = threading.Thread(target = trigger)
|
||||
th.start()
|
||||
else:
|
||||
logging.info("Ric not in activerics")
|
||||
th = threading.Thread(target = trigger)
|
||||
th.start()
|
||||
else:
|
||||
if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"):
|
||||
th = threading.Thread(target = trigger)
|
||||
th.start()
|
||||
else:
|
||||
logging.info("Ric not in activerics")
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
########## User Plugin CODE ##########
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue