Skip to content

Commit

Permalink
asterisk plugin: fix bug in found_terminator to expect bytes instead …
Browse files Browse the repository at this point in the history
…of str
  • Loading branch information
bmxp committed Oct 20, 2023
1 parent 5fbc769 commit f9fea7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions asterisk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class Asterisk(SmartPlugin):

PLUGIN_VERSION = "1.4.1"
PLUGIN_VERSION = "1.4.2"

DB = 'ast_db'
DEV = 'ast_dev'
Expand Down Expand Up @@ -237,8 +237,27 @@ def hangup(self, hang):
self._command({'Action': 'Hangup', 'Channel': channel}, reply=False)

def found_terminator(self, client, data):
"""called upon data reception"""
data = data.decode()
"""called then terminator is found
:param client: tcp client which is used for the connection
:param str data: the response from asterisk server
:return : None
"""
if isinstance(data, bytes):
data = data.decode()

"""
the response will be normally like ``key: value``
exception is start of communication which presents e.g.
```
Asterisk Call Manager/5.0.4
Response: Success
Message: Authentication accepted
```
The following code puts everything into the dict ``event``
It only implements a very basic inspection of the response
"""
self.logger.debug(f"data to inspect: {data}")
event = {}
for line in data.splitlines():
key, sep, value = line.partition(': ')
Expand Down
4 changes: 2 additions & 2 deletions asterisk/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ plugin:
description:
de: 'Ansteuerung einer Asterisk Telefonanlage'
en: 'Control of an Asterisk PBX'
maintainer: 'Nobody'
maintainer: 'bmxp'
tester: 'Nobody' # Who tests this plugin?
keywords: PBX Asterisk VOIP ISDN
state: ready
documentation: https://www.smarthomeng.de/user/plugins/asterisk/README.html
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/
version: 1.4.1 # Plugin version
version: 1.4.2 # Plugin version
sh_minversion: 1.9.0 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
# py_minversion: 3.6 # minimum Python version to use for this plugin
Expand Down

0 comments on commit f9fea7e

Please sign in to comment.