xs1-api-client¶
A python library for accessing actuator and sensor data on the the EZcontrol® XS1 Gateway using their HTTP API.
How to use¶
Installation¶
pip install xs1-api-client
Usage¶
For a basic example have a look at the example.py file. If you need more info have a look at the documentation which should help.
License¶
xs1-api-client by Markus Ressel
Copyright (C) 2017 Markus Ressel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Content:¶
API¶
xs1_api_client package¶
Subpackages¶
xs1_api_client.device package¶
Subpackages¶
-
class
xs1_api_client.device.actuator.base.
XS1Actuator
(state, api_interface)[source]¶ Bases:
xs1_api_client.device.base.XS1Device
Represents a basic XS1 Actuator, there may be special variants for some types.
-
call_function
(function)[source]¶ Calls the specified function by id and saves the api response as the new state
Parameters: function – XS1Function object
-
-
class
xs1_api_client.device.actuator.thermostat.
XS1Thermostat
(state, api_interface)[source]¶ Bases:
xs1_api_client.device.actuator.base.XS1Actuator
Represents a basic XS1 Actuator, there may be special variants for some types.
-
class
xs1_api_client.device.sensor.base.
XS1Sensor
(state, api_interface)[source]¶ Bases:
xs1_api_client.device.base.XS1Device
Represents a XS1 Sensor
Submodules¶
xs1_api_client.device.base module¶
-
class
xs1_api_client.device.base.
XS1Device
(state: dict, api_interface)[source]¶ Bases:
object
This is a generic XS1 device, all other objetcs inherit from this.
-
new_value
()[source]¶ Returns the new value to set for this device. If this value differs from the currrent value the gateway is still trying to update the value on the device. If it does not differ the value has already been set.
Returns: the new value to set for this device
-
set_state
(new_state: dict)[source]¶ Sets a new state for this device. If there is an existing state, new and old values will be merged to retain any information that was missing from api responses.
Parameters: new_state – new representation of this device (api response)
-
set_value
(value)[source]¶ Sets a new value for this device. This method should be implemented by inheriting classes.
Parameters: value – the new value to set
-
Module contents¶
Submodules¶
xs1_api_client.api module¶
This is the main xs1_api_client api which contains the XS1 object to interact with the gateway.
Example usage can be found in the example.py file
-
class
xs1_api_client.api.
XS1
(host: str = None, user: str = None, password: str = None)[source]¶ Bases:
object
This class is the main api interface that handles all communication with the XS1 gateway.
-
call_actuator_function
(actuator_id, function)[source]¶ Executes a function on the specified actuator and sets the response on the passed in actuator.
Parameters: - actuator_id – actuator id to execute the function on and set response value
- function – id of the function to execute
Returns: the api response
-
get_all_actuators
()[source]¶ Requests the list of enabled actuators from the gateway.
Returns: a list of XS1Actuator objects
-
get_all_sensors
()[source]¶ Requests the list of enabled sensors from the gateway.
Returns: list of XS1Sensor objects
-
get_protocol_info
()[source]¶ Retrieves the protocol version that is used by the gateway
Returns: protocol version number
-
get_state_actuator
(actuator_id)[source]¶ Gets the current state of the specified actuator.
Parameters: actuator_id – actuator id Returns: the api response as a dict
-
get_state_sensor
(sensor_id)[source]¶ Gets the current state of the specified sensor.
Parameters: sensor_id – sensor id Returns: the api response as a dict
-
send_request
(command, *parameters)[source]¶ Sends a GET request to the XS1 Gateway and returns the response as a JSON object.
Parameters: - command – command parameter for the URL (see api_constants)
- parameters – additional parameters needed for the specified command like ‘number=3’ (without any ‘&’ symbol)
Returns: the api response as a json object
-
set_actuator_value
(actuator_id, value)[source]¶ Sets a new value for the specified actuator.
Parameters: - actuator_id – actuator id to set the new value on
- value – the new value to set on the specified actuator
Returns: the api response
-
set_connection_info
(host, user, password)[source]¶ Sets private connection info for this XS1 instance. This XS1 instance will also immediately use this connection info.
Parameters: - host – host address the gateway can be found at
- user – username for authentication
- password – password for authentication
-
static
set_global_connection_info
(host, user, password)[source]¶ Sets the global connection info. This initialization is valid for all XS1 instances that do not have a specific connection configuration upon instantiation or using the set_connection_info() method. If you want a XS1 instance to use the global info instead of private use the use_global_connection_info() method.
Parameters: - host – host address the gateway can be found at
- user – username for authentication
- password – password for authentication
-
xs1_api_client.api_constants module¶
XS1 HTTP Web API constants used to create GET request URLs and parse the JSON answer.
-
xs1_api_client.api_constants.
COMMAND_GET_CONFIG_INFO
= 'get_config_info'¶ Command to get (final) configuration information about the gateway
-
xs1_api_client.api_constants.
COMMAND_GET_LIST_ACTUATORS
= 'get_list_actuators'¶ Command to get a list of all actuators
-
xs1_api_client.api_constants.
COMMAND_GET_LIST_SENSORS
= 'get_list_sensors'¶ Command to get a list of all sensors
-
xs1_api_client.api_constants.
COMMAND_GET_PROTOCOL_INFO
= 'get_protocol_info'¶ Command to get information about the protocol version used by the gateway
-
xs1_api_client.api_constants.
COMMAND_GET_STATE_ACTUATOR
= 'get_state_actuator'¶ Command to get the state of a specific actuator
-
xs1_api_client.api_constants.
COMMAND_GET_STATE_SENSOR
= 'get_state_sensor'¶ Command to get the state of a specific sensor
-
xs1_api_client.api_constants.
COMMAND_SET_STATE_ACTUATOR
= 'set_state_actuator'¶ Command to set a new value on an actuator
-
xs1_api_client.api_constants.
COMMAND_SET_STATE_SENSOR
= 'set_state_sensor'¶ Command to set a new value on a sensor (for debugging)
-
xs1_api_client.api_constants.
ERROR_CODES
= {'09': 'type not virtual', '05': 'invalid system', '01': 'invalid command', '06': 'invalid function', '02': 'cmd type missing', '12': 'protocol version mismatch', '10': 'syntax error', '08': 'object not found', '11': 'error time range', '04': 'duplicate name', '07': 'invalid date/time', '03': 'number/name not found'}¶ Dictionary with description values for each error code
-
xs1_api_client.api_constants.
ERROR_CODE_CMD_TYPE_MISSING
= '02'¶ Error code for ‘cmd type missing’
-
xs1_api_client.api_constants.
ERROR_CODE_DUPLICATE
= '04'¶ Error code for ‘duplicate name’
-
xs1_api_client.api_constants.
ERROR_CODE_INVALID_COMMAND
= '01'¶ Error code for ‘invalid command’
-
xs1_api_client.api_constants.
ERROR_CODE_INVALID_DATE_TIME
= '07'¶ Error code for ‘invalid date/time’
-
xs1_api_client.api_constants.
ERROR_CODE_INVALID_FUNCTION
= '06'¶ Error code for ‘invalid function’
-
xs1_api_client.api_constants.
ERROR_CODE_INVALID_SYSTEM
= '05'¶ Error code for ‘invalid system’
-
xs1_api_client.api_constants.
ERROR_CODE_INVALID_TIME_RANGE
= '11'¶ Error code for ‘error time range’
-
xs1_api_client.api_constants.
ERROR_CODE_NOT_FOUND
= '03'¶ Error code for ‘number/name not found’
-
xs1_api_client.api_constants.
ERROR_CODE_OBJECT_NOT_FOUND
= '08'¶ Error code for ‘object not found’
-
xs1_api_client.api_constants.
ERROR_CODE_PROTOCOL_VERSION_MISMATCH
= '12'¶ Error code for ‘protocol version mismatch’
-
xs1_api_client.api_constants.
ERROR_CODE_SYNTAX_ERROR
= '10'¶ Error code for ‘syntax error’
-
xs1_api_client.api_constants.
ERROR_CODE_TYPE_NOT_VIRTUAL
= '09'¶ Error code for ‘type not virtual’
-
xs1_api_client.api_constants.
NODE_ACTUATOR
= 'actuator'¶ Node with an array of actuators
-
xs1_api_client.api_constants.
NODE_DEVICE_BOOTLOADER_VERSION
= 'bootloader'¶ Bootloader version number
-
xs1_api_client.api_constants.
NODE_DEVICE_FIRMWARE_VERSION
= 'firmware'¶ Firmware version number
-
xs1_api_client.api_constants.
NODE_DEVICE_HARDWARE_VERSION
= 'hardware'¶ Hardware revision
-
xs1_api_client.api_constants.
NODE_DEVICE_MAC
= 'mac'¶ MAC address
-
xs1_api_client.api_constants.
NODE_DEVICE_NAME
= 'devicename'¶ Hostname
-
xs1_api_client.api_constants.
NODE_DEVICE_UPTIME
= 'uptime'¶ Uptime in seconds
-
xs1_api_client.api_constants.
NODE_ERROR
= 'error'¶ Node containing the error code
-
xs1_api_client.api_constants.
NODE_INFO
= 'info'¶ Node with gateway specific information
-
xs1_api_client.api_constants.
NODE_PARAM_DESCRIPTION
= 'dsc'¶ Device description
-
xs1_api_client.api_constants.
NODE_PARAM_FUNCTION
= 'function'¶ Array of functions
-
xs1_api_client.api_constants.
NODE_PARAM_ID
= 'id'¶ Device id (only unique within actuators/sensors)
-
xs1_api_client.api_constants.
NODE_PARAM_NAME
= 'name'¶ Device name
-
xs1_api_client.api_constants.
NODE_PARAM_NEW_VALUE
= 'newvalue'¶ New value to set for the device
-
xs1_api_client.api_constants.
NODE_PARAM_NUMBER
= 'number'¶ Alternative device id (only unique within actuators/sensors)
-
xs1_api_client.api_constants.
NODE_PARAM_TYPE
= 'type'¶ Device type
-
xs1_api_client.api_constants.
NODE_PARAM_UNIT
= 'unit'¶ Device value unit
-
xs1_api_client.api_constants.
NODE_PARAM_UTIME
= 'utime'¶ Time this device was last updated
-
xs1_api_client.api_constants.
NODE_PARAM_VALUE
= 'value'¶ Current device value
-
xs1_api_client.api_constants.
NODE_SENSOR
= 'sensor'¶ Node with an array of sensors
-
xs1_api_client.api_constants.
NODE_VERSION
= 'version'¶ Node with protocol version info
-
xs1_api_client.api_constants.
UNIT_BOOLEAN
= 'boolean'¶ Boolean unit type
-
xs1_api_client.api_constants.
URL_PARAM_COMMAND
= 'cmd='¶ command parameter that specifies the method the api is queried with
-
xs1_api_client.api_constants.
URL_PARAM_FUNCTION
= 'function='¶ parameter that specifies the function to execute (on an actuator)
-
xs1_api_client.api_constants.
URL_PARAM_NUMBER
= 'number='¶ number parameter that specifies the id of an actuator or sensor
-
xs1_api_client.api_constants.
URL_PARAM_PASSWORD
= 'pwd='¶ ‘Password’ parameter
-
xs1_api_client.api_constants.
URL_PARAM_USER
= 'user='¶ ‘User’ parameter
-
xs1_api_client.api_constants.
URL_PARAM_VALUE
= 'value='¶ ‘value’ parameter that specifies the new value to set an actuator (or sensor) to
-
xs1_api_client.api_constants.
VALUE_DISABLED
= 'disabled'¶ ‘Disabled’ type