Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
msinn committed Jan 24, 2021
2 parents cd72128 + b712e59 commit dc3e4ea
Show file tree
Hide file tree
Showing 87 changed files with 3,010 additions and 959 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def plugin_release():
return '1.8.0'
return '1.8.1'


def plugin_branch():
Expand Down
89 changes: 46 additions & 43 deletions alexarc4shng/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,7 @@ plugin:
keywords: Alexa Amazon Remote Control
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1336416-alexa-text-to-speach
state: develop # State of the Plugin
restartable: True # Plugin is restartable

plugin_functions:
# Definition of function interface of the plugin

send_cmd:
type: str
description:
de: "Sendet einen Befehl an Alexa."
en: "Sends a command to Alexa."
parameters:
dvName:
type: str
description:
de: "Name des Alexa Devices."
en: "Name of Alexa device."
cmdName:
type: str
description:
de: "Name des Befehls, z.b. Text2Speech."
en: "Name of command, e.g. Text2Speech."
mValue:
type: str
description:
de: "Wert, der gesendet werden soll, numerische Werte ohne Hochkomma als Zahl"
en: "Value to send, numeric Values without Quotes as Num"

get_last_alexa:
type: str
description:
de: "Liefert die Geräte-ID des zuletzt verwendeten Alexa-Gerätes zurück"
en: "delivers the Device-ID of the last used Alexa-Device"

logic_parameters: NONE # No logic parameters for this plugin
item_structs: NONE # no item structure needed
item_attributes:
# Definition of item attributes defined by this plugin
alexa_cmd_XX:
type: str
mandatory: True
description:
de: 'String um die Befehle zu definieren'
en: 'string to define orders'
restartable: True # Plugin is restartable

parameters:
# Definition of parameters to be configured in etc/plugin.yaml
Expand Down Expand Up @@ -95,3 +53,48 @@ parameters:
de: 'Sekunden bis zum automatischen refreshen des Cookie-files'
en: 'seconds till the next automatic login to get a new cookie'

logic_parameters: NONE # No logic parameters for this plugin
item_structs: NONE # no item structure needed
item_attributes: NONE # no item attributes needed

item_attribute_prefixes:
# Definition of item attributes that only have a common prefix (enter 'item_attribute_prefixes: NONE' or ommit this section, if section should be empty)
# NOTE: This section should only be used, if really nessesary (e.g. for the stateengine plugin)
alexa_cmd_:
type: str
mandatory: True
description:
de: 'String um die Befehle zu definieren (alexa_cmd_01, alexa_cmd_02, ...)'
en: 'string to define commands (alexa_cmd_01, alexa_cmd_02, ...)'

plugin_functions:
# Definition of function interface of the plugin

send_cmd:
type: str
description:
de: "Sendet einen Befehl an Alexa."
en: "Sends a command to Alexa."
parameters:
dvName:
type: str
description:
de: "Name des Alexa Devices."
en: "Name of Alexa device."
cmdName:
type: str
description:
de: "Name des Befehls, z.b. Text2Speech."
en: "Name of command, e.g. Text2Speech."
mValue:
type: str
description:
de: "Wert, der gesendet werden soll, numerische Werte ohne Hochkomma als Zahl"
en: "Value to send, numeric Values without Quotes as Num"

get_last_alexa:
type: str
description:
de: "Liefert die Geräte-ID des zuletzt verwendeten Alexa-Gerätes zurück"
en: "delivers the Device-ID of the last used Alexa-Device"

61 changes: 44 additions & 17 deletions casambi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Casambi(SmartPlugin):
"""

# Use VERSION = '1.0.0' for your initial plugin Release
PLUGIN_VERSION = '1.7.1' # (must match the version specified in plugin.yaml)
PLUGIN_VERSION = '1.7.2' # (must match the version specified in plugin.yaml)

def __init__(self, sh):
"""
Expand Down Expand Up @@ -89,8 +89,6 @@ def __init__(self, sh):
self._init_complete = False
return

self.sessionID, self.networkID, self.numberNetworks = self.getSessionCredentials()

self.init_webinterface()

return
Expand All @@ -111,7 +109,7 @@ def getSessionCredentials(self):
headers={'X-Casambi-Key': self.api_key,
'content-type': 'application/json'}, timeout=10, verify=False)

#self.logger.debug("Session request response: {0}".format(sessionrequest_response.text))
self.logger.debug("Session request response: {0}".format(sessionrequest_response.text))
statusCode = sessionrequest_response.status_code
if statusCode == 200:
self.logger.debug("Sending session request command successful")
Expand Down Expand Up @@ -148,6 +146,7 @@ def getSessionCredentials(self):

def openWebsocket(self, networkID):

self.logger.debug("start openWebsocket")
reference = 'REFERENCE-ID'; # Reference handle created by client to link messages to relevant callbacks
socketType = 1; # Client type, use value 1 (FRONTEND)

Expand Down Expand Up @@ -318,6 +317,8 @@ def run(self):
# if you need to create child threads, do not make them daemon = True!
# They will not shutdown properly. (It's a python bug)

self.sessionID, self.networkID, self.numberNetworks = self.getSessionCredentials()

self.thread = threading.Thread(target=self.eventHandler, name='CasambiEventHandler')
self.thread.daemon = False
self.thread.start()
Expand All @@ -326,20 +327,43 @@ def run(self):
def eventHandler(self):
self.logger.debug("EventHandler thread started")
if self.networkID:
self.logger.debug("Trying to open websocket once")
self.openWebsocket(self.networkID)
else:
self.logger.warning("Cannot open websocket once. Invalid networkID")

errorCount = 0
doReconnect = False
while self.alive:
try:
receivedData = self.websocket.recv()
self.logger.debug("Received data: {0}".format(receivedData))
errorCount = 0
except Exception as e:
self.logger.info("Error during data reception: {0}".format(e))
errorCount = errorCount + 1
doReconnect = True
#self.logger.debug("Starting loop")

if not self.websocket or self.websocket.connected == False:
self.logger.debug("Websocket no longer connected.")
doReconnect = True
errorCount = errorCount + 1
else:
self.logger.debug("Starting data receive")
try:
self.logger.debug("Trying to receive data")
receivedData = self.websocket.recv()
self.logger.debug("Received data: {0}".format(receivedData))
errorCount = 0
except timeout:
self.logger.debug("Reception timeout")
except socket.timeout:
self.logger.debug("Socket reception timeout")
except Exception as e:
self.logger.info("Error during data reception: {0}".format(e))
errorCount = errorCount + 1
doReconnect = True

if not receivedData:
self.logger.debug("Received empty data")
else:
self.logger.debug("Received data: {0}".format(receivedData))
self.decodeEventData(receivedData)

# Error handling:
if errorCount > 2:
errorCount = 1
self.logger.debug("Waiting for 60 seconds")
Expand All @@ -348,11 +372,14 @@ def eventHandler(self):
if not self.alive:
break

if doReconnect and self.networkID:
self.openWebsocket(self.networkID)
doReconnect = False

self.decodeEventData(receivedData)
if doReconnect:
if self.networkID:
self.logger.debug("Trying to reopen websocket")
self.openWebsocket(self.networkID)
doReconnect = False
else:
self.logger.warning("Cannot reconnect due to invalid network ID")


if self.websocket:
self.websocket.close()
Expand Down
2 changes: 1 addition & 1 deletion casambi/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugin:
# documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1496182-supportthread-f%C3%BCr-casambi-plugin

version: 1.7.1 # Plugin version (must match the version specified in __init__.py)
version: 1.7.2 # Plugin version (must match the version specified in __init__.py)
sh_minversion: 1.7 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: False # plugin supports multi instance
Expand Down
14 changes: 10 additions & 4 deletions database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Database(SmartPlugin):
"""

ALLOW_MULTIINSTANCE = True
PLUGIN_VERSION = '1.5.14'
PLUGIN_VERSION = '1.5.15'

# SQL queries: {item} = item table name, {log} = log table name
# time, item_id, val_str, val_num, val_bool, changed
Expand Down Expand Up @@ -308,12 +308,15 @@ def id(self, item, create=True, cur=None):
:rtype: int | None
"""

id = self.readItem(str(item.id()), cur=cur)
try:
id = self.readItem(str(item.id()), cur=cur)
except Exception as e:
self.logger.warning(f"id(): No id found for item {item.id()} - Exception {e}")

if id is None and create == True:
id = [self.insertItem(item.id(), cur)]

if (COL_ITEM_ID >= len(id)) or (id == None):
if (id is None) or (COL_ITEM_ID >= len(id)) :
return None
return int(id[COL_ITEM_ID])

Expand Down Expand Up @@ -1143,7 +1146,10 @@ def remove_older_than_maxage(self):
try:
item_id = self.id(item, create=False)
except:
self.logger.critical("remove_older_than_maxage: no id for item {}".format(item))
if item_id is None:
self.logger.info("remove_older_than_maxage: no id for item {}".format(item))
else:
self.logger.critical("remove_older_than_maxage: no id for item {}".format(item))
return
time_end = self.get_maxage_ts(item)
timestamp_end = self._timestamp(time_end)
Expand Down
2 changes: 1 addition & 1 deletion database/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugin:
documentation: http://smarthomeng.de/user/plugins/database/user_doc.html
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1021844-neues-database-plugin

version: 1.5.14 # Plugin version
version: 1.5.15 # Plugin version
sh_minversion: 1.8.0 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: True # plugin supports multi instance
Expand Down
36 changes: 22 additions & 14 deletions homematic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Homematic(SmartPlugin):
the update functions for the items
"""

PLUGIN_VERSION = '1.5.0'
PLUGIN_VERSION = '1.5.1'
# ALLOW_MULTIINSTANCE = False

connected = False
Expand Down Expand Up @@ -122,10 +122,10 @@ def __init__(self, sh, *args, **kwargs):
except:
self.logger.error("Unable to start HomeMatic object - SmartHomeNG will be unable to terminate the thread vor this plugin (instance)")
self.connected = False
# self._init_complete = False
# stop the thread that got created by initializing pyhomematic
# self.hm.stop()
# return
# self._init_complete = False
# stop the thread that got created by initializing pyhomematic
# self.hm.stop()
# return

# start communication with HomeMatic ccu
try:
Expand All @@ -136,13 +136,13 @@ def __init__(self, sh, *args, **kwargs):
if self.connected:
# TO DO: sleep besser lösen!
sleep(20)
# self.logger.warning("Plugin '{}': self.hm.devices".format(self.hm.devices))
if self.hm.devices.get(self.hm_id,{}) == {}:
# self.logger.warning("Plugin '{}': self.hm.devices".format(self.hm.devices))
if self.hm.devices.get(self.hm_id, {}) == {}:
self.logger.error("Connection to ccu failed")
# self._init_complete = False
# stop the thread that got created by initializing pyhomematic
# self.hm.stop()
# return
# self._init_complete = False
# stop the thread that got created by initializing pyhomematic
# self.hm.stop()
# return

self.hm_items = []

Expand All @@ -158,6 +158,7 @@ def run(self):
Run method for the plugin
"""
self.logger.debug("Run method called")

self.alive = True
# if you want to create child threads, do not make them daemon = True!
# They will not shutdown properly. (It's a python bug)
Expand All @@ -169,6 +170,7 @@ def stop(self):
"""
self.logger.debug("Stop method called")
self.alive = False

self.hm.stop()
self.hmip.stop()

Expand All @@ -191,7 +193,6 @@ def parse_item(self, item):
# self.logger.debug("parse_item: {}".format(item))
dev_id = self.get_iattr_value(item.conf, 'hm_address')


dev_type = self.get_iattr_value(item.conf, 'hm_type')

dev_type = '?'
Expand Down Expand Up @@ -254,7 +255,13 @@ def parse_item(self, item):
elif hm_node == 'EV':
value = dev.event(hm_function)
elif hm_node == 'SE':
value = dev.getSensorData(hm_function)
try:
#Do not read sensors during initialization (could result in a warning 'HMGeneric.getValue: ...'
#to logger 'pyhomematic.devicetypes.generic'
# value = dev.getSensorData(hm_function)
pass
except Exception as e:
self.logger.warning(f"parse_item: Item {item._path} Exception {e}")
elif hm_node == 'WR':
value = dev.getWriteData(hm_function)
else:
Expand All @@ -269,7 +276,8 @@ def parse_item(self, item):
self.logger.info("Initializing {} with '{}' from address={}:{}, function={}".format(item, value, hm_address, hm_channel, hm_function))
item(value, 'HomeMatic', 'Init')
else:
if not init_error:
if (not init_error) and (hm_node != 'SE'):
# Dont log an error for sensors, since sensor data is not read during initialization
self.logger.error("Not initializing {} from address={}:{}, function='{}'".format(item, hm_node, hm_address, hm_channel, hm_function))

return self.update_item
Expand Down
4 changes: 3 additions & 1 deletion homematic/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ plugin:
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1501815-support-thread-zum-homematic-plugin

# Following entries are for Smart-Plugins:
version: 1.5.0 # Plugin version
version: 1.5.1 # Plugin version
sh_minversion: 1.5 # 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
# py_maxversion: # maximum Python version to use for this plugin (leave empty if latest)
multi_instance: True
restartable: unknown
classname: Homematic # class containing the plugin
Expand Down
Loading

0 comments on commit dc3e4ea

Please sign in to comment.