Skip to main content

A comprehensive testing library for validating and interacting with openHAB installations.

Project description

openhab-test-suite

A comprehensive testing library for validating and interacting with openHAB installations.

openhab-test-suite simplifies the process of testing items, rules, and things in openHAB systems. The library provides an easy-to-use Python API that interacts with the openHAB REST API, enabling automated testing of various components in your smart home environment.


Features

  • Item Testing: Validate item states and ensure proper functionality for various types (e.g., Switch, String, Color).
  • Thing Testing: Verify thing statuses (e.g., ONLINE, OFFLINE, PENDING) and troubleshoot connectivity issues.
  • Rule Testing: Manage and execute rules programmatically to ensure their expected behavior.
  • Supports local and cloud-based openHAB instances.
  • Designed for developers and testers working on openHAB integrations.

Why use openhab-test-suite?

This library helps identify issues quickly, automate validation processes, and maintain a reliable smart home setup. Whether you are building new automations or troubleshooting an existing configuration, openhab-test-suite provides the tools you need.


Requirements

  • Python 3.7 or newer
  • python-openhab-crud library (install using pip install python-openhab-crud)
  • python-openhab-itemevents library (install using pip install python-openhab-itemevents)
  • A running openHAB server with REST API enabled (you have to enable Basic Authentication)

Installation

Install via pip

To install the package using pip, simply run:

pip install openhab-test-suite

Manual Installation

  1. Clone the repository:

    git clone https://github.com/your-repo/openhab-test-suite.git
    cd openhab-test-suite
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Configure your openHAB server settings in your Python code.


Usage

Here is an example of how to use the library for basic operations:

Initialize the Connector

from openhab_test_suite import OpenHABConnector

connector = OpenHABConnector(
    url="http://openhab-server:8080",
    username="your-username",
    password="your-password"
)

Test Items

from openhab_test_suite import ItemTester

itemTester = ItemTester(connector)

# Check if an item is ONLINE
isOnline = itemTester.isItemOnline("LightSwitch1")
print(f"LightSwitch1 online status: {isOnline}")

Test Rules

from openhab_test_suite import RuleTester

ruleTester = RuleTester(connector)

# Run a rule and verify the result
ruleTester.runRule("myRuleUID")

Full List of Methods

OpenHABConnector

Handles communication with the openHAB REST API.

Method Description
get(endpoint, header) Sends a GET request to the specified endpoint. Returns the response.
post(endpoint, header, data) Sends a POST request to the specified endpoint with optional headers and data. Returns the response.
put(endpoint, header, data) Sends a PUT request to the specified endpoint with optional headers and data. Returns the response.

ItemTester

Provides methods to test and validate openHAB items.

Method Description
isItemOnline(itemName) Checks if the specified item is ONLINE.
getItemState(itemName) Retrieves the current state of an item.
setItemState(itemName, value) Sets the state of an item to the specified value.
testItemState(itemName, expectedValue) Tests if the item's state matches the expected value.
sendCommand(itemName, command) Sends a command to the specified item.

ThingTester

Provides methods to test and validate openHAB things.

Method Description
isThingOnline(thingUID) Checks if the specified thing is ONLINE.
getThingStatus(thingUID) Retrieves the current status of a thing.
testThingStatus(thingUID, expectedStatus) Tests if the thing's status matches the expected value.
enableThing(thingUID) Enables the specified thing.
disableThing(thingUID) Disables the specified thing.

RuleTester

Provides methods to manage and test openHAB rules.

Method Description
runRule(ruleUid) Executes a rule immediately.
enableRule(ruleUid) Enables the specified rule.
disableRule(ruleUid) Disables the specified rule.
testRuleExecution(ruleUid, expectedItem, expectedValue) Tests the execution of a rule and verifies the outcome by checking an item's state.
isRuleActive(ruleUid) Checks if the rule is active.
isRuleDisabled(ruleUid) Checks if the rule is disabled.
isRuleRunning(ruleUid) Checks if the rule is currently running.
isRuleIdle(ruleUid) Checks if the rule is in the IDLE state.
getRuleStatus(ruleUid) Retrieves detailed status information about a rule.

Contributing

We welcome contributions to improve openhab-test-suite!

How to contribute:

  1. Fork the repository.
  2. Create a new branch:
    git checkout -b feature/your-feature-name
    
  3. Commit your changes:
    git commit -m "Add your feature description"
    
  4. Push to the branch:
    git push origin feature/your-feature-name
    
  5. Open a pull request.

Please ensure your code adheres to PEP 8 guidelines and includes relevant documentation and tests.


License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openhab_test_suite-0.1.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openhab_test_suite-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file openhab_test_suite-0.1.0.tar.gz.

File metadata

  • Download URL: openhab_test_suite-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.8.10

File hashes

Hashes for openhab_test_suite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c5203de219e8426fcb0d8e0ba09585d92e48055ff9521112526e6f789934e6f3
MD5 f8fdc336bb563e239efe59fa2f9d938d
BLAKE2b-256 5b7ff63944fd3bde07c80b168eda5c48e0fe0ca64fcedb089c002a6a02517d4e

See more details on using hashes here.

File details

Details for the file openhab_test_suite-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openhab_test_suite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c84051c36d7ddca813a5fdbe9cc3be010ef4edfe5d40c895bf2229608ab60cc7
MD5 e0b18c85e9f1849508483e7b1c4832e6
BLAKE2b-256 eacbd8e5da224031000a66ef425f7c9bec7978b5dd605e53e6f0064c40d7c58c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page