Module websocket
Dieses Modul implementiert die Möglichkeit mit SmartHomeNG über das Websocket Protokoll zu kommunizieren.
API des Moduls
- class modules.websocket.Websocket(*args, **kargs)[Quellcode]
Bases:
lib.model.module.Module
- version = '1.0.5'
- longname = 'Websocket module for SmartHomeNG'
- port = 0
- start()[Quellcode]
If the module needs to startup threads or uses python modules that create threads, put thread creation code or the module startup code here.
Otherwise don’t enter code here
- stop()[Quellcode]
If the module has started threads or uses python modules that created threads, put cleanup code here.
Otherwise don’t enter code here
- set_smartvisu_support(protocol_enabled=False, default_acl='ro', query_definitions=False, series_updatecycle=0)[Quellcode]
Set state of smartvisu support
- Parameter
protocol_enabled – enable or disable the payload protocol for smartVISU
query_definitions – enable or disable the query of item definitions over websocket protocol
series_updatecycle – update cycle for smartVISU series requests (if 0, timing from database plugin is used)
- get_port()[Quellcode]
- get_tls_port()[Quellcode]
- get_use_tls()[Quellcode]
- USERS = {}
- async ws_server(ip, port, ssl_context=None)[Quellcode]
- async handle_new_connection(websocket, path)[Quellcode]
Wait for incoming connection and handle the request
- async register(websocket)[Quellcode]
Register a new incoming connection
- async unregister(websocket)[Quellcode]
Unregister an incoming connection
- async log_connection_event(action, websocket)[Quellcode]
Print info about connection/disconnection of users
- STATE = {'value': 0}
- state_event()[Quellcode]
- users_event()[Quellcode]
- async notify_state()[Quellcode]
- async notify_users()[Quellcode]
- async counter_sync(websocket)[Quellcode]
- sv_monitor_items = {}
- sv_monitor_logs = {}
- sv_clients = {}
- sv_update_series = {}
- clients = []
- proto = 4
- janus_queue = None
- async get_shng_class_instances()[Quellcode]
Ensure that the instance vars for items and logics are initialized
- client_address(websocket)[Quellcode]
- json_serial(obj)[Quellcode]
JSON serializer for objects not serializable by default json code
- async smartVISU_protocol_v4(websocket)[Quellcode]
- build_client_info(client_addr)[Quellcode]
Build string with client host info for info/error logging :param client_addr: :return: info string
- build_sw_info(client_addr)[Quellcode]
Build string with client host info for info/error logging :param client_addr: :return: info string
- build_log_info(client_addr)[Quellcode]
Build string with client info (name and software) for info/error logging :param client_addr: :return: info string
- async prepare_monitor(data, client_addr)[Quellcode]
Prepare the return of item monitoring data
- Parameter
data – data of the visu’s request
client_addr – address of the client (visu)
- Rückgabe
answer to the visu
- async prepare_series(data, client_addr)[Quellcode]
Prepare the return of series data
- Parameter
data – data of the visu’s request
client_addr – address of the client (visu)
- Rückgabe
answer to the visu
- set_periodic_series_updates(reply, client_addr)[Quellcode]
-> blocking method - called via run_in_executor()
- async update_all_series()[Quellcode]
Async task to periodically update the series data for the visu(s)
- async sleep(seconds)[Quellcode]
sleep method with abort, if smarthomeNG leaves running mode :param seconds:
- update_series(client_addr)[Quellcode]
-> blocking method - called via run_in_executor()
- async cancel_series(data, client_addr)[Quellcode]
Cancel the update of series data
- Parameter
data – data of the visu’s request
client_addr – address of the client (visu)
- Rückgabe
answer to the visu
- cancel_periodic_series_updates(reply, path, client_addr)[Quellcode]
-> blocking method - called via run_in_executor()
- async update_visu()[Quellcode]
Async task to update the visu(s) if items have changed or an url command has been issued
- async update_item(item_name, item_value, source)[Quellcode]
send JSON data with new value of an item
- async update_log(log_entry)[Quellcode]
send JSON data with update to log
- async request_logic(data, client_addr)[Quellcode]
Request logic (trigger, enable, disable)
- async request_list_items(path, client_addr)[Quellcode]
Build the requested list of logics
- async request_list_logics(enabled, client_addr)[Quellcode]
Build the requested list of logics
- update_visuitem(item, caller=None, source=None, dest=None)[Quellcode]
This method gets called when an item value changes
it is thread based and is called from other threads than the websocket module uses
- Parameter
item – item object that has been changed
caller – Caller that changed the item
source – Source that made the caller change the item
dest – Destination for the change (usually None)
- Rückgabe
- update_visulog(event, data)[Quellcode]
This method gets called when an item value changes
it is thread based and is called from other threads than the websocket module uses
- Parameter
event – Type of monitored event (only ‚log‘ is handled)
data – data of log entry
- Rückgabe
- set_visu_url(url, clientip='')[Quellcode]
Tell the websocket client (visu) to load a specific url
- get_visu_client_info()[Quellcode]
Get client info for web interface of smartvisu plugin :return:
Metadaten
# Metadata for the plugin
module:
# Global plugin attributes
classname: Websocket
version: 1.0.5
sh_minversion: 1.9.1.2
# sh_maxversion: # maximum shNG version to use this module (leave empty if latest)
# py_minversion: 3.6 # minimum Python version to use for this module
# py_maxversion: # maximum Python version to use for this module (leave empty if latest)
description:
de: 'Modul implementiert die Websocket Kommunikation für SmartHomeNG'
en: 'Module implements websocket communication for SmartHomeNG'
parameters:
# Definition of parameters to be configured in etc/module.yaml
enabled:
type: bool
default: True
description:
de: 'Websocket Unterstützung aktivieren oder deaktivieren'
en: 'Enable or disable websocket support'
ip:
type: ipv4
description:
de: IP Adresse auf der das websocket Modul aktiv sein soll - muss normalerweise nicht angegeben werden
en: IP adress on which the websocket module should operate - not needed, has only to be specified for special configurations
fr: Adresse IP sur laquelle le module websocket devrait fonctionner - il n'est généralement pas nécessaire de la spécifier
port:
type: int
valid_min: 0
valid_max: 65535
default: 2424
description:
de: Portnummer für die unverschlüsselte Websocket Kommunikation
en: Port number for the unencrypted access to websockets
fr: Numéro de port pour l'accès à l'interface websocket
tls_port:
type: int
valid_min: 0
valid_max: 65535
default: 2425
description:
de: Portnummer für die verschlüsselte Websocket Kommunikation
en: Port number for the encrypted access to websockets
fr: Numéro de port pour l'accès à l'interface web si utilisation de wss
use_tls:
type: bool
default: False
description:
de: Auf True setzen, um Zugriffe über wss:// zu ermöglichen (Zertifikat muss installiert sein)
en: Set to true to allow access over wss:// (certificate has to be installed)
fr: Mettre sur 'true' pour activer les accès par https (certificats doivent être installés)
tls_cert:
type: str
default: shng.cer
description:
de: Name der Zertifikatsdatei mit der Endung '.cer' oder '.pem'. Die Datei muss im Verzeichnis ../etc liegen
en: Name of the certificate file (with extension .cer od .pem). The file musst be stored in ../etc
fr: Nom du fichier contanent les certificats. Le fichier doit se trouver dans ../etc
tls_key:
type: str
default: shng.key
description:
de: Name der Datei mit dem privaten Schlüssel und der Endung '.key'. Die Datei muss im Verzeichnis ../etc liegen
en: Name of the private key file. The file musst be stored in ../etc
fr: Nom du fichier contanent les clés privés. Le fichier doit se trouver dans ../etc
Konfiguration
Konfigurationsdokumentation ist unter Konfiguration auf der Seite Module websocket Neu zu finden.