Class SmartDevicePlugin

Die Klasse SmartDevicePlugin implementiert die Basisklasse aller Device-Plugins. Die vorhandenen Methoden sind im Folgenden beschrieben.

Zusätzlich werden die Methoden der Klasse lib.utils.Utils vererbt.

class lib.model.smartdeviceplugin.SmartDevicePlugin(*args, **kargs)[Quellcode]

Bases: SmartPlugin

The class SmartDevicePlugin implements the base class of smart-plugins designed especially for device connectivity.

It implements a fully functional plugin with all necessary methods to set up network or serial connections, handle item parsing and updating and converting data from shng to the device and vice versa.

In the easiest cases, only the command specifications in commands.py and possibly DT-* datatype classes are needed; additional command classes or plugin code can be added if necessary or desired.

The implemented methods are described below, inherited methods are only described if changed/overwritten.

remove_item(item)[Quellcode]

remove item references from plugin

update_plugin_config(**kwargs)[Quellcode]

update plugin configuration parameters and (re)run relevant configuration methods

suspend(by=None)[Quellcode]

sets plugin into suspended mode, no network/serial activity and no item changed

resume(by=None)[Quellcode]

disabled suspended mode, network/serial connections are resumed

on_suspend()[Quellcode]

called when suspend is enabled. Overwrite as needed

on_resume()[Quellcode]

called when suspend is disabled. Overwrite as needed

set_suspend(suspend_active=None, by=None)[Quellcode]

enable / disable suspend mode: open/close connections, schedulers

run()[Quellcode]

Run method for the plugin

stop()[Quellcode]

Stop method for the plugin

connect()[Quellcode]

Open connection

disconnect()[Quellcode]

Close connection

parse_item(item)[Quellcode]

Default plugin parse_item method. Is called when the plugin is initialized. The plugin can, corresponding to its attribute keywords, decide what to do with the item in future, like adding it to an internal array for future reference :type item: :param item: The item to process. :return: Recall function for item updates

update_item(item, caller=None, source=None, dest=None)[Quellcode]

Item has been updated

This method is called, if the value of an item has been updated by SmartHomeNG. It should write the changed value out to the device (hardware/interface) that is managed by this plugin.

Parameter:
  • item – item to be updated towards the plugin

  • caller – if given it represents the callers name

  • source – if given it represents the source

  • dest – if given it represents the dest

send_command(command, value=None, return_result=False, **kwargs)[Quellcode]

Sends the specified command to the device providing <value> as data Not providing data will issue a read command, trying to read the value from the device and writing it to the associated item.

Parameter:
  • command (str) – the command to send

  • value – the data to send, if applicable

Rückgabe:

True if send was successful, False otherwise

Rückgabetyp:

bool

on_data_received(by, data, command=None)[Quellcode]

Callback function for received data e.g. from an event loop Processes data and dispatches value to plugin class

Parameter:
  • command (str) – the command in reply to which data was received

  • data – received data in ‚raw‘ connection format

  • by – client object / name / identifier

dispatch_data(command, value, by=None)[Quellcode]

Callback function - new data has been received from device. Value is already in item-compatible format, so find appropriate item and update value

Parameter:
  • command (str) – command for or in reply to which data was received

  • value – data

  • by – str

read_all_commands(group='')[Quellcode]

Triggers all configured read commands or all configured commands of given group

is_valid_command(command, read=None)[Quellcode]

Validate if ‚command‘ is a valid command for this device Possible to check only for reading or writing

Parameter:
  • command (str) – the command to test

  • read (bool | NoneType) – check for read (True) or write (False), or both (None)

Rückgabe:

True if command is valid, False otherwise

Rückgabetyp:

bool

get_lookup(lookup, mode='fwd')[Quellcode]

returns the lookup table for name <lookup>, None on error

has_recursive_custom_attribute(index=1)[Quellcode]
set_custom_item(item, command, index, value)[Quellcode]

this is called by parse_items if xx_custom[123] is found.

on_connect(by=None)[Quellcode]

callback if connection is made.

on_disconnect(by=None)[Quellcode]

callback if connection is broken.

read_initial_values()[Quellcode]

control call of _read_initial_values - run instantly or delay