Skip to content

Commit

Permalink
Merge pull request #203 from deviloper-lab/master
Browse files Browse the repository at this point in the history
PR von deviloper-lab
  • Loading branch information
motom001 authored Feb 23, 2022
2 parents cad0a76 + 845d5e4 commit 20912c3
Show file tree
Hide file tree
Showing 52 changed files with 24,836 additions and 19,764 deletions.
2 changes: 1 addition & 1 deletion doorpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""provide intercomstation to the doorstation by VoIP"""

from doorpi import metadata, DoorPi
from .doorpi import metadata, DoorPi


__version__ = metadata.version
Expand Down
16 changes: 7 additions & 9 deletions doorpi/action/SingleActions/call.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import doorpi
from doorpi.action.base import SingleAction

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)

from doorpi.action.base import SingleAction
import doorpi
logger.debug('%s loaded', __name__)


def call(number):
doorpi.DoorPi().sipphone.call(number)
def call(number): doorpi.DoorPi().sipphone.call(number)

def get(parameters):
parameter_list = parameters.split(',')
if len(parameter_list) is not 1: return None
if len(parameter_list) is not 1:
return None

number = parameter_list[0]
return CallAction(call, number=number)

return CallAction(call, number = number)

class CallAction(SingleAction):
pass
16 changes: 8 additions & 8 deletions doorpi/action/SingleActions/file_call_value.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import doorpi
from doorpi.action.base import SingleAction

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)
logger.debug('%s loaded', __name__)

import doorpi
from doorpi.action.base import SingleAction

def call_phonenumber_from_file(filename):
try:
with open(doorpi.DoorPi().parse_string(filename), 'r') as f:
phonenumber = f.readline().strip(' \t\n\r')

logger.debug("firing sipphone.call for this number: %s", phonenumber)
logger.debug('firing sipphone.call for this number: %s', phonenumber)
doorpi.DoorPi().sipphone.call(phonenumber)
logger.debug("finished sipphone.call for this number: %s", phonenumber)
logger.debug('finished sipphone.call for this number: %s', phonenumber)

except Exception as ex:
logger.exception("couldn't get phonenumber from file (%s)", ex)
logger.exception('could not get phonenumber from file (%s)', ex)
return False
return True

def get(parameters):
return CallPhoneNumberFromFileAction(call_phonenumber_from_file, filename = parameters)
return CallPhoneNumberFromFileAction(call_phonenumber_from_file, filename=parameters)


class CallPhoneNumberFromFileAction(SingleAction):
pass
18 changes: 9 additions & 9 deletions doorpi/action/SingleActions/hangup.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)

import doorpi
from doorpi.action.base import SingleAction

from time import sleep

import logging
logger = logging.getLogger(__name__)
logger.debug('%s loaded', __name__)


def hangup(waittime):
logger.trace("hangup requested")
if waittime > 0:
logger.debug("Waiting %s seconds before sending hangup request", waittime)
logger.debug('Waiting %s seconds before sending hangup request', waittime)
sleep(float(waittime))
return doorpi.DoorPi().sipphone.hangup()

def get(parameters):
if not parameters.isdigit(): return None
if not parameters.isdigit():
return None
return HangupAction(hangup, parameters)


class HangupAction(SingleAction):
pass
84 changes: 43 additions & 41 deletions doorpi/action/SingleActions/ipsrpc_call_value.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import doorpi
from doorpi.action.base import SingleAction

import requests
import json
from requests.auth import HTTPBasicAuth

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)

import doorpi
import requests
import json
from requests.auth import HTTPBasicAuth
from doorpi.action.base import SingleAction

def ips_rpc_create_config():
config = {}
Expand All @@ -21,61 +21,63 @@ def ips_rpc_create_config():
return config

def ips_rpc_fire(method, config, *parameters):
payload = {
"method": method,
"params": parameters,
"jsonrpc": config['jsonrpc'],
"id": 0,
}
return requests.post(
payload = json.dumps({
'method': method,
'params': parameters,
'jsonrpc': config['jsonrpc'],
'id': 0 }).encode('utf-8')
response = requests.post(
config['webservice_url'],
headers = config['headers'],
auth = HTTPBasicAuth(config['username'], config['password']),
data = json.dumps(payload)
)
data = payload)
return json.loads(response.content.decode('utf-8'))

def ips_rpc_check_variable_exists(key, config = None):
if config is None: config = ips_rpc_create_config()
response = ips_rpc_fire('IPS_VariableExists', config, key)
return response.json['result']
def ips_rpc_check_variable_exists(key, config=None):
if config is None:
config = ips_rpc_create_config()
return ips_rpc_fire('IPS_VariableExists', config, key)['result']

def ips_rpc_get_variable_type(key, config = None):
if config is None: config = ips_rpc_create_config()
response = ips_rpc_fire('IPS_GetVariable', config, key)
return response.json['result']['VariableValue']['ValueType']
def ips_rpc_get_variable_type(key, config=None):
if config is None:
config = ips_rpc_create_config()
return ips_rpc_fire('IPS_GetVariable', config, key)['result']['VariableValue']['ValueType']

def ips_rpc_get_variable_value(key, config = None):
if config is None: config = ips_rpc_create_config()
response = ips_rpc_fire('GetValue', config, key)
return response.json['result']
def ips_rpc_get_variable_value(key, config=None):
if config is None:
config = ips_rpc_create_config()
return ips_rpc_fire('GetValue', config, key)['result']

def ips_rpc_call_phonenumber_from_variable(key, config = None):
def ips_rpc_call_phonenumber_from_variable(key, config=None):
try:
if config is None: config = ips_rpc_create_config()
if ips_rpc_check_variable_exists(key, config) is not True: raise Exception("var %s doesn't exist", key)
if config is None:
config = ips_rpc_create_config()
if ips_rpc_check_variable_exists(key, config) is not True:
raise Exception('no variable %s', key)
type = ips_rpc_get_variable_type(key, config)
if type is None: raise Exception("type of var %s couldn't find", key)
# http://www.ip-symcon.de/service/dokumentation/befehlsreferenz/variablenverwaltung/ips-getvariable/
# Variablentyp (0: Boolean, 1: Integer, 2: Float, 3: String)
elif type is not 3: raise Exception("phonenumber from var %s is not a string", key)
if type is None:
raise Exception('type of variable %s unknown', key)
# variable types (0: boolean, 1: integer, 2: float, 3: string)
elif type is not 3:
raise Exception("type of variable %s is not a string", key)

phonenumber = ips_rpc_get_variable_value(key, config)
logger.debug("fire now sipphone.call for this number: %s", phonenumber)
logger.debug('fire now sipphone.call for this number: %s', phonenumber)
doorpi.DoorPi().sipphone.call(phonenumber)
logger.debug("finished sipphone.call for this number: %s", phonenumber)

logger.debug('finished sipphone.call for this number: %s', phonenumber)
except Exception as ex:
logger.exception("couldn't get phonenumber from IpsRpc (%s)", ex)
logger.exception('couldn\'t get phonenumber from IpsRpc (%s)', ex)
return False
return True

def get(parameters):
parameter_list = parameters.split(',')
if len(parameter_list) is not 1: return None
if len(parameter_list) is not 1:
return None

key = int(parameter_list[0])
return IPSRpcCallPhonenumberFromVariableAction(ips_rpc_call_phonenumber_from_variable, key)

return IpsRpcCallPhonenumberFromVariableAction(ips_rpc_call_phonenumber_from_variable, key)

class IpsRpcCallPhonenumberFromVariableAction(SingleAction):
class IPSRpcCallPhonenumberFromVariableAction(SingleAction):
pass
89 changes: 46 additions & 43 deletions doorpi/action/SingleActions/ipsrpc_setvalue.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import doorpi
from doorpi.action.base import SingleAction

import requests
from requests.auth import HTTPBasicAuth
import json

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)
logger.debug('%s loaded', __name__)

import doorpi
import requests
import json
from requests.auth import HTTPBasicAuth
from doorpi.action.base import SingleAction

def ips_rpc_create_config():
config = {}
Expand All @@ -21,58 +21,61 @@ def ips_rpc_create_config():
return config

def ips_rpc_fire(method, config, *parameters):
payload = {
"method": method,
"params": parameters,
"jsonrpc": config['jsonrpc'],
"id": 0,
}
return requests.post(
payload = json.dumps({
'method': method,
'params': parameters,
'jsonrpc': config['jsonrpc'],
'id': 0 }).encode('utf-8')
response = requests.post(
config['webservice_url'],
headers = config['headers'],
auth = HTTPBasicAuth(config['username'], config['password']),
data = json.dumps(payload)
)
headers=config['headers'],
auth=HTTPBasicAuth(config['username'], config['password']),
data=payload)
return json.loads(response.content.decode('utf-8'))

def ips_rpc_check_variable_exists(key, config = None):
if config is None: config = ips_rpc_create_config()
response = ips_rpc_fire('IPS_VariableExists', config, key)
return response.json['result']
def ips_rpc_check_variable_exists(key, config=None):
if config is None:
config = ips_rpc_create_config()
return ips_rpc_fire('IPS_VariableExists', config, key)['result']

def ips_rpc_get_variable_type(key, config = None):
if config is None: config = ips_rpc_create_config()
response = ips_rpc_fire('IPS_GetVariable', config, key)
return response.json['result']['VariableValue']['ValueType']
def ips_rpc_get_variable_type(key, config=None):
if config is None:
config = ips_rpc_create_config()
return ips_rpc_fire('IPS_GetVariable', config, key)['result']['VariableValue']['ValueType']

def ips_rpc_set_value(key, value, config = None):
def ips_rpc_set_value(key, value, config=None):
try:
if config is None: config = ips_rpc_create_config()
if ips_rpc_check_variable_exists(key, config) is not True: raise Exception("var %s doesn't exist", key)
if config is None:
config = ips_rpc_create_config()
if ips_rpc_check_variable_exists(key, config) is not True:
raise Exception('no variable %s found', key)
type = ips_rpc_get_variable_type(key, config)
if type is None: raise Exception("type of var %s couldn't find", key)
# http://www.ip-symcon.de/service/dokumentation/befehlsreferenz/variablenverwaltung/ips-getvariable/
# Variablentyp (0: Boolean, 1: Integer, 2: Float, 3: String)
if type is None:
raise Exception('type of variable %s unknown', key)
# variable type (0: boolean, 1: integer, 2: float, 3: string)
elif type == 0:
if value.lower() in ['true', 'yes', '1']: value = True
else: value = False
elif type == 1: value = int(value)
elif type == 2: value = float(value)
elif type == 3: value = str(value)
else: value = str(value)
value = (value.lower() in ['true', 'yes', '1'])
elif type == 1:
value = int(value)
elif type == 2:
value = float(value)
else:
value = str(value)
ips_rpc_fire('SetValue', config, key, value)
except Exception as ex:
logger.exception("couldn't send IpsRpc (%s)", ex)
logger.exception('send IpsRpc (%s) failed', ex)
return False
return True

def get(parameters):
parameter_list = parameters.split(',')
if len(parameter_list) is not 2: return None
if len(parameter_list) is not 2:
return None

key = int(parameter_list[0])
value = parameter_list[1]
return IPSRpcSetValueAction(ips_rpc_set_value, key, value)

return IpsRpcSetValueAction(ips_rpc_set_value, key, value)

class IpsRpcSetValueAction(SingleAction):
pass
class IPSRpcSetValueAction(SingleAction):
pass
14 changes: 6 additions & 8 deletions doorpi/action/SingleActions/log.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from doorpi.action.base import SingleAction

import logging
logger = logging.getLogger(__name__)
logger.debug("%s loaded", __name__)
logger.debug('%s loaded', __name__)

from doorpi.action.base import SingleAction

def log(message):
logger.debug(message)
def log(message): logger.debug(message)

def get(parameters):
parameter_list = parameters.split(',')
if len(parameter_list) is not 1: return None
if len(parameter_list) is not 1:
return None

message = parameter_list[0]

return LogAction(log, message)

class LogAction(SingleAction):
pass
pass
Loading

0 comments on commit 20912c3

Please sign in to comment.