python-openhab-rest-client 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openhab/Actions.py +43 -0
- openhab/Addons.py +163 -0
- openhab/Audio.py +66 -0
- openhab/Auth.py +105 -0
- openhab/ChannelTypes.py +54 -0
- openhab/Client.py +197 -0
- openhab/ConfigDescriptions.py +44 -0
- openhab/Discovery.py +28 -0
- openhab/Events.py +302 -0
- openhab/Iconsets.py +21 -0
- openhab/Inbox.py +64 -0
- openhab/Items.py +264 -0
- openhab/Links.py +98 -0
- openhab/Logging.py +55 -0
- openhab/ModuleTypes.py +47 -0
- openhab/Persistence.py +103 -0
- openhab/ProfileTypes.py +32 -0
- openhab/Rules.py +206 -0
- openhab/Services.py +78 -0
- openhab/Sitemaps.py +88 -0
- openhab/Systeminfo.py +34 -0
- openhab/Tags.py +82 -0
- openhab/Templates.py +38 -0
- openhab/ThingTypes.py +42 -0
- openhab/Things.py +199 -0
- openhab/Transformations.py +58 -0
- openhab/UI.py +75 -0
- openhab/UUID.py +18 -0
- openhab/Voice.py +147 -0
- openhab/__init__.py +66 -0
- python_openhab_rest_client-0.1.0.dist-info/LICENSE +21 -0
- python_openhab_rest_client-0.1.0.dist-info/METADATA +2391 -0
- python_openhab_rest_client-0.1.0.dist-info/RECORD +70 -0
- python_openhab_rest_client-0.1.0.dist-info/WHEEL +5 -0
- python_openhab_rest_client-0.1.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/actions.py +55 -0
- tests/addons.py +96 -0
- tests/audio.py +16 -0
- tests/auth.py +45 -0
- tests/channel_events.py +14 -0
- tests/channel_types.py +29 -0
- tests/config_descriptions.py +23 -0
- tests/discovery.py +23 -0
- tests/events.py +41 -0
- tests/iconsets.py +19 -0
- tests/inbox.py +53 -0
- tests/inbox_events.py +15 -0
- tests/item_events.py +38 -0
- tests/items.py +120 -0
- tests/link_events.py +14 -0
- tests/links.py +74 -0
- tests/logging_test.py +43 -0
- tests/module_types.py +14 -0
- tests/persistence.py +78 -0
- tests/profile_types.py +13 -0
- tests/rules.py +151 -0
- tests/services.py +52 -0
- tests/sitemaps.py +65 -0
- tests/systeminfo.py +14 -0
- tests/tags.py +53 -0
- tests/templates.py +28 -0
- tests/test.py +11 -0
- tests/thing_events.py +17 -0
- tests/thing_types.py +28 -0
- tests/things.py +75 -0
- tests/transformations.py +38 -0
- tests/ui.py +70 -0
- tests/uuid.py +18 -0
- tests/voice.py +119 -0
tests/tags.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, Tags
|
|
7
|
+
|
|
8
|
+
# Client initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
tagsApi = Tags(client)
|
|
11
|
+
|
|
12
|
+
# Beispiele für die Tags-API
|
|
13
|
+
def tagsExamples():
|
|
14
|
+
# Alle Tags abrufen
|
|
15
|
+
allTags = tagsApi.getTags()
|
|
16
|
+
print("All Tags:", allTags)
|
|
17
|
+
|
|
18
|
+
# Ein neues Tag erstellen
|
|
19
|
+
# Beispiel für das Tag-Datenobjekt
|
|
20
|
+
newTagData = {
|
|
21
|
+
"uid": "CustomTag",
|
|
22
|
+
"name": "CustomTag",
|
|
23
|
+
"label": "My Custom Tag",
|
|
24
|
+
"description": "This is a custom tag",
|
|
25
|
+
"synonyms": ["Custom", "Tag"],
|
|
26
|
+
"editable": True
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
response = tagsApi.createTag(newTagData)
|
|
31
|
+
print("Tag Created:", response)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
print("Error creating tag:", e)
|
|
34
|
+
|
|
35
|
+
# Details zu einem Tag abrufen
|
|
36
|
+
tagDetails = tagsApi.getTag("Property_Voltage")
|
|
37
|
+
print("Details for newTag:", tagDetails)
|
|
38
|
+
|
|
39
|
+
# Ein Tag aktualisieren
|
|
40
|
+
updatedTagData = {
|
|
41
|
+
"id": "Property_Voltage",
|
|
42
|
+
"label": "Updated Tag"
|
|
43
|
+
}
|
|
44
|
+
tagsApi.updateTag("Property_Voltage", newTagData)
|
|
45
|
+
print("newTag updated.")
|
|
46
|
+
|
|
47
|
+
# Ein Tag löschen
|
|
48
|
+
tagsApi.deleteTag("Property_Voltage")
|
|
49
|
+
print("newTag deleted.")
|
|
50
|
+
|
|
51
|
+
# Funktion ausführen
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
tagsExamples()
|
tests/templates.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, Templates
|
|
7
|
+
|
|
8
|
+
# OpenHABClient initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
templatesApi = Templates(client)
|
|
11
|
+
|
|
12
|
+
# Alle Templates abrufen
|
|
13
|
+
try:
|
|
14
|
+
allTemplates = templatesApi.getAllTemplates()
|
|
15
|
+
print("Alle Templates:")
|
|
16
|
+
for template in allTemplates:
|
|
17
|
+
print(f"- {template['uid']}: {template['label']}")
|
|
18
|
+
except Exception as e:
|
|
19
|
+
print(f"Fehler beim Abrufen der Templates: {e}")
|
|
20
|
+
|
|
21
|
+
# Spezifisches Template abrufen
|
|
22
|
+
try:
|
|
23
|
+
templateUid = "example_template_uid" # Beispiel-UID
|
|
24
|
+
specificTemplate = templatesApi.getTemplateByUID(templateUid)
|
|
25
|
+
print("\nDetails des spezifischen Templates:")
|
|
26
|
+
print(specificTemplate)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"Fehler beim Abrufen des spezifischen Templates: {e}")
|
tests/test.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
|
|
7
|
+
from openhab import OpenHABClient
|
|
8
|
+
|
|
9
|
+
# Client initialisieren (ersetze 'http://openhab-url' mit deiner URL und 'auth_token' mit deinem Token)
|
|
10
|
+
#client = OpenHABClient(base_url='http://openhab-url', auth_token='your_auth_token')
|
|
11
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
tests/thing_events.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, ThingEvents
|
|
7
|
+
|
|
8
|
+
# Client initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
thingEvents = ThingEvents(client)
|
|
11
|
+
|
|
12
|
+
# Beispielaufrufe
|
|
13
|
+
print(thingEvents.ThingAddedEvent("*"))
|
|
14
|
+
print(thingEvents.ThingRemovedEvent("*"))
|
|
15
|
+
print(thingEvents.ThingUpdatedEvent("*"))
|
|
16
|
+
print(thingEvents.ThingStatusInfoEvent("*"))
|
|
17
|
+
print(thingEvents.ThingStatusInfoChangedEvent("*"))
|
tests/thing_types.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, ThingTypes
|
|
7
|
+
|
|
8
|
+
# OpenHABClient initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
thingTypesApi = ThingTypes(client)
|
|
11
|
+
|
|
12
|
+
# Alle Thing-Typen abrufen
|
|
13
|
+
try:
|
|
14
|
+
allThingTypes = thingTypesApi.getAllThingTypes()
|
|
15
|
+
print("Alle Thing-Typen:")
|
|
16
|
+
for thingType in allThingTypes:
|
|
17
|
+
print(f"- {thingType['UID']}: {thingType['label']}")
|
|
18
|
+
except Exception as e:
|
|
19
|
+
print(f"Fehler beim Abrufen der Thing-Typen: {e}")
|
|
20
|
+
|
|
21
|
+
# Spezifischen Thing-Typ abrufen
|
|
22
|
+
try:
|
|
23
|
+
thingTypeUid = "mqtt:homeassistant" # Beispiel-UID
|
|
24
|
+
specificThingType = thingTypesApi.getThingType(thingTypeUid)
|
|
25
|
+
print("\nDetails des spezifischen Thing-Typs:")
|
|
26
|
+
print(specificThingType)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"Fehler beim Abrufen des spezifischen Thing-Typs: {e}")
|
tests/things.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
import traceback
|
|
5
|
+
|
|
6
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
7
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
8
|
+
from openhab import OpenHABClient, Things
|
|
9
|
+
|
|
10
|
+
# Client initialisieren
|
|
11
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
12
|
+
thingsApi = Things(client)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def safeCall(description, func, *args, **kwargs):
|
|
16
|
+
try:
|
|
17
|
+
print(f"{description}...")
|
|
18
|
+
response = func(*args, **kwargs)
|
|
19
|
+
print("Erfolgreich:", response)
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(f"Fehler bei {description}: {e}")
|
|
22
|
+
traceback.print_exc() # Stacktrace ausgeben
|
|
23
|
+
|
|
24
|
+
# 1. Alle Things abrufen
|
|
25
|
+
#safeCall("Alle Things abrufen", thingsApi.getAllThings)
|
|
26
|
+
|
|
27
|
+
# 2. Ein spezifisches Thing per UID abrufen
|
|
28
|
+
thingUID = "mqtt:topic:mybroker:newthing"
|
|
29
|
+
safeCall(f"Thing {thingUID} abrufen", thingsApi.getThingByUID, thingUID)
|
|
30
|
+
|
|
31
|
+
# 3. Ein neues Thing erstellen
|
|
32
|
+
newThing = {
|
|
33
|
+
"UID": "mqtt:topic:mybroker:newthing",
|
|
34
|
+
"label": "Neues MQTT Thing",
|
|
35
|
+
"thingTypeUID": "mqtt:topic",
|
|
36
|
+
"bridgeUID": "mqtt:broker:mybroker",
|
|
37
|
+
"configuration": {},
|
|
38
|
+
"channels": []
|
|
39
|
+
}
|
|
40
|
+
safeCall("Neues Thing erstellen", thingsApi.createThing, newThing)
|
|
41
|
+
|
|
42
|
+
#time.sleep(2) # Warte, damit OpenHAB das neue Thing registrieren kann
|
|
43
|
+
|
|
44
|
+
thingUID = "mqtt:topic:mybroker:newthing"
|
|
45
|
+
# 4. Ein Thing aktualisieren
|
|
46
|
+
updatedData = {"label": "Aktualisiertes MQTT Thing"}
|
|
47
|
+
#safeCall(f"Thing {thingUID} aktualisieren", thingsApi.updateThing, thingUID, updatedData)
|
|
48
|
+
|
|
49
|
+
# 5. Ein Thing löschen
|
|
50
|
+
#safeCall(f"Thing {thingUID} löschen", thingsApi.deleteThing, thingUID, force=True)
|
|
51
|
+
|
|
52
|
+
# 6. Die Konfiguration eines Things aktualisieren
|
|
53
|
+
configUpdate = {"retain": True}
|
|
54
|
+
safeCall(f"Thing {thingUID} Konfiguration aktualisieren", thingsApi.updateThingConfiguration, thingUID, configUpdate)
|
|
55
|
+
|
|
56
|
+
# 7. Den Status eines Things abrufen
|
|
57
|
+
#safeCall(f"Thing {thingUID} Status abrufen", thingsApi.getThingStatus, thingUID)
|
|
58
|
+
|
|
59
|
+
# 8. Ein Thing aktivieren oder deaktivieren
|
|
60
|
+
safeCall(f"Thing {thingUID} aktivieren", thingsApi.enableThing, thingUID, enabled=True)
|
|
61
|
+
|
|
62
|
+
# 9. Den Firmware-Status abrufen
|
|
63
|
+
safeCall(f"Thing {thingUID} Firmware-Status abrufen", thingsApi.getThingFirmwareStatus, thingUID)
|
|
64
|
+
|
|
65
|
+
# 10. Eine Firmware aktualisieren
|
|
66
|
+
firmwareVersion = "1.2.3"
|
|
67
|
+
safeCall(f"Thing {thingUID} Firmware auf {firmwareVersion} aktualisieren", thingsApi.updateThingFirmware, thingUID, firmwareVersion)
|
|
68
|
+
|
|
69
|
+
# 11. Alle verfügbaren Firmwares für ein Thing abrufen
|
|
70
|
+
safeCall(f"Thing {thingUID} verfügbare Firmwares abrufen", thingsApi.getThingFirmwares, thingUID)
|
|
71
|
+
|
|
72
|
+
# 12. Den Konfigurationsstatus eines Things abrufen
|
|
73
|
+
safeCall(f"Thing {thingUID} Konfigurationsstatus abrufen", thingsApi.getThingConfigStatus, thingUID)
|
|
74
|
+
|
|
75
|
+
print("Alle API-Tests abgeschlossen.")
|
tests/transformations.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, Transformations
|
|
7
|
+
|
|
8
|
+
# Client initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
transformationsApi = Transformations(client)
|
|
11
|
+
|
|
12
|
+
# Alle Transformationen abrufen
|
|
13
|
+
transformationsList = transformationsApi.getTransformations()
|
|
14
|
+
print(transformationsList)
|
|
15
|
+
|
|
16
|
+
# Eine spezifische Transformation abrufen
|
|
17
|
+
uid = "en.map"
|
|
18
|
+
transformation = transformationsApi.getTransformation(uid)
|
|
19
|
+
print(transformation)
|
|
20
|
+
|
|
21
|
+
# Eine Transformation aktualisieren
|
|
22
|
+
updatedData = {
|
|
23
|
+
"uid": "my_custom_map",
|
|
24
|
+
"label": "My Custom Map",
|
|
25
|
+
"type": "map",
|
|
26
|
+
"configuration": {"function": "CLOSED=geschlossen\nOPEN=offen\nNULL=unbekannt\n"},
|
|
27
|
+
"editable": True
|
|
28
|
+
}
|
|
29
|
+
#updatedTransformation = transformationsApi.updateTransformation(uid, updatedData)
|
|
30
|
+
#print(updatedTransformation)
|
|
31
|
+
|
|
32
|
+
# Eine Transformation löschen
|
|
33
|
+
#deletedTransformation = transformationsApi.deleteTransformation(uid)
|
|
34
|
+
#print(deletedTransformation)
|
|
35
|
+
|
|
36
|
+
# Alle Transformation-Dienste abrufen
|
|
37
|
+
services = transformationsApi.getTransformationServices()
|
|
38
|
+
print(services)
|
tests/ui.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, UI
|
|
7
|
+
|
|
8
|
+
# Client initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
uiApi = UI(client)
|
|
11
|
+
|
|
12
|
+
# Alle UI-Komponenten im Namespace "home" abrufen
|
|
13
|
+
namespace = "home"
|
|
14
|
+
uiComponents = uiApi.getUiComponents(namespace)
|
|
15
|
+
print("Alle UI-Komponenten:\n")
|
|
16
|
+
print(uiComponents)
|
|
17
|
+
|
|
18
|
+
# Eine neue UI-Komponente hinzufügen
|
|
19
|
+
componentData = {
|
|
20
|
+
"component": "Button",
|
|
21
|
+
"config": {
|
|
22
|
+
"label": "Turn On Light",
|
|
23
|
+
"action": "turn_on"
|
|
24
|
+
},
|
|
25
|
+
"slots": {
|
|
26
|
+
"slot1": [{"component": "Icon", "config": {"icon": "light"}}]
|
|
27
|
+
},
|
|
28
|
+
"uid": "unique-button-uid",
|
|
29
|
+
"tags": ["button", "light-control"],
|
|
30
|
+
"props": {
|
|
31
|
+
"uri": "/control/light",
|
|
32
|
+
"parameters": [
|
|
33
|
+
{"name": "light", "label": "Light", "type": "TEXT", "required": True}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"timestamp": "2025-01-27T15:37:35.741Z",
|
|
37
|
+
"type": "button"
|
|
38
|
+
}
|
|
39
|
+
newComponent = uiApi.addUiComponent(namespace, componentData)
|
|
40
|
+
print("Neue UI-Komponente:\n")
|
|
41
|
+
print(newComponent)
|
|
42
|
+
|
|
43
|
+
# Eine spezifische UI-Komponente abrufen
|
|
44
|
+
componentUid = "unique-button-uid"
|
|
45
|
+
component = uiApi.getUiComponent(namespace, componentUid)
|
|
46
|
+
print("Einzelne UI-Komponente:\n")
|
|
47
|
+
print(component)
|
|
48
|
+
|
|
49
|
+
# Eine UI-Komponente aktualisieren
|
|
50
|
+
updatedComponentData = {
|
|
51
|
+
"component": "Button",
|
|
52
|
+
"config": {
|
|
53
|
+
"label": "Turn Off Light",
|
|
54
|
+
"action": "turn_off"
|
|
55
|
+
},
|
|
56
|
+
"uid": "unique-button-uid"
|
|
57
|
+
}
|
|
58
|
+
updatedComponent = uiApi.updateUiComponent(namespace, componentUid, updatedComponentData)
|
|
59
|
+
print("Geänderte UI-Komponente:\n")
|
|
60
|
+
print(updatedComponent)
|
|
61
|
+
|
|
62
|
+
# Eine UI-Komponente löschen
|
|
63
|
+
deletedComponent = uiApi.deleteUiComponent(namespace, componentUid)
|
|
64
|
+
print("Gelöschte UI-Komponente:\n")
|
|
65
|
+
print(deletedComponent)
|
|
66
|
+
|
|
67
|
+
# Alle UI-Kacheln abrufen
|
|
68
|
+
uiTiles = uiApi.getUiTiles()
|
|
69
|
+
print("Kacheln einer UI-Komponente:\n")
|
|
70
|
+
print(uiTiles)
|
tests/uuid.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad (eine Ebene höher) zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, UUID
|
|
7
|
+
|
|
8
|
+
# Client initialisieren (ersetze 'http://openhab-url' mit deiner URL und 'auth_token' mit deinem Token)
|
|
9
|
+
# client = OpenHABClient(base_url='http://openhab-url', auth_token='your_auth_token')
|
|
10
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
11
|
+
uuidApi = UUID(client)
|
|
12
|
+
|
|
13
|
+
# Rufe die UUID ab
|
|
14
|
+
try:
|
|
15
|
+
openhabUuid = uuidApi.getUUID()
|
|
16
|
+
print(f"Die UUID von OpenHAB ist: {openhabUuid}")
|
|
17
|
+
except Exception as e:
|
|
18
|
+
print(f"Fehler beim Abrufen der UUID: {e}")
|
tests/voice.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# Füge den Projektwurzelpfad zum Python-Suchpfad hinzu
|
|
5
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
6
|
+
from openhab import OpenHABClient, Voice
|
|
7
|
+
|
|
8
|
+
# Client initialisieren
|
|
9
|
+
client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
|
|
10
|
+
voiceApi = Voice(client)
|
|
11
|
+
|
|
12
|
+
# Beispiele für die Voice-API mit Fehlerbehandlung
|
|
13
|
+
def voiceExamples():
|
|
14
|
+
try:
|
|
15
|
+
# 1. Standardstimme abrufen
|
|
16
|
+
print(1)
|
|
17
|
+
defaultVoice = voiceApi.getDefaultVoice()
|
|
18
|
+
print("Default Voice:", defaultVoice)
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"Fehler beim Abrufen der Standardstimme: {e}")
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
# 2. Liste aller Stimmen abrufen
|
|
24
|
+
print(2)
|
|
25
|
+
allVoices = voiceApi.getVoices()
|
|
26
|
+
print("All Voices:", allVoices)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"Fehler beim Abrufen aller Stimmen: {e}")
|
|
29
|
+
allVoices = []
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
# 3. Text mit einer Stimme ausgeben
|
|
33
|
+
print(3)
|
|
34
|
+
if allVoices:
|
|
35
|
+
voiceId = allVoices[0]['id']
|
|
36
|
+
response = voiceApi.sayText("Hello from OpenHAB!", voiceID=voiceId, sinkId="your_audio_sink_id")
|
|
37
|
+
print(f"Text spoken using Voice {voiceId}:", response)
|
|
38
|
+
except Exception as e:
|
|
39
|
+
print(f"Fehler beim Sprechen des Textes: {e}")
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
# 4. Liste aller Interpreter abrufen
|
|
43
|
+
print(4)
|
|
44
|
+
interpreters = voiceApi.getInterpreters(language="en")
|
|
45
|
+
print("Interpreters:", interpreters)
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(f"Fehler beim Abrufen der Interpreter: {e}")
|
|
48
|
+
interpreters = []
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
# 5. Text interpretieren (Standard-Interpreter)
|
|
52
|
+
print(5)
|
|
53
|
+
interpretedText = voiceApi.interpretText("Turn on the lights", language="en", IDs=[])
|
|
54
|
+
print("Interpreted Text:", interpretedText)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print(f"Fehler beim Interpretieren des Textes: {e}")
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
# 6. Mehrere Interpreter zur Interpretation ansprechen
|
|
60
|
+
print(6)
|
|
61
|
+
if interpreters:
|
|
62
|
+
interpreterIds = [interpreter['id'] for interpreter in interpreters[:2]] # Max. 2 Interpreter
|
|
63
|
+
interpretedTextBatch = voiceApi.interpretTextBatch("Turn off the heater", language="en", IDs=interpreterIds)
|
|
64
|
+
print("Batch Interpreted Text:", interpretedTextBatch)
|
|
65
|
+
except Exception as e:
|
|
66
|
+
print(f"Fehler beim Batch-Interpretieren des Textes: {e}")
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
# 7. Details eines einzelnen Interpreters abrufen
|
|
70
|
+
print(7)
|
|
71
|
+
if interpreters:
|
|
72
|
+
interpreterId = interpreters[0]['id']
|
|
73
|
+
interpreterDetails = voiceApi.getInterpreter(interpreterId, language="en")
|
|
74
|
+
print(f"Interpreter details for {interpreterId}:", interpreterDetails)
|
|
75
|
+
except Exception as e:
|
|
76
|
+
print(f"Fehler beim Abrufen des Interpreters: {e}")
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
print(8)
|
|
80
|
+
# 8. Dialog starten
|
|
81
|
+
dialogResponse = voiceApi.startDialog(
|
|
82
|
+
sourceID="audioSource1",
|
|
83
|
+
keyword="Hello",
|
|
84
|
+
sttID="sttSystem",
|
|
85
|
+
ttsID="ttsSystem",
|
|
86
|
+
voiceID="voice1",
|
|
87
|
+
sinkID="audioOut"
|
|
88
|
+
)
|
|
89
|
+
print("Dialog started:", dialogResponse)
|
|
90
|
+
except Exception as e:
|
|
91
|
+
print(f"Fehler beim Starten des Dialogs: {e}")
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
# 9. Dialog stoppen
|
|
95
|
+
print(9)
|
|
96
|
+
dialogStopResponse = voiceApi.stopDialog(sourceID="audioSource1")
|
|
97
|
+
print("Dialog stopped:", dialogStopResponse)
|
|
98
|
+
except Exception as e:
|
|
99
|
+
print(f"Fehler beim Stoppen des Dialogs: {e}")
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
# 10. Listen and Answer ausführen
|
|
103
|
+
print(10)
|
|
104
|
+
listenAndAnswerResponse = voiceApi.listenAndAnswer(
|
|
105
|
+
sourceID="audioSource1",
|
|
106
|
+
sttID="sttSystem",
|
|
107
|
+
ttsID="ttsSystem",
|
|
108
|
+
voiceID="voice1",
|
|
109
|
+
hliIDs=["interpreter1", "interpreter2"],
|
|
110
|
+
sinkID="audioOut",
|
|
111
|
+
listeningItem="light_switch"
|
|
112
|
+
)
|
|
113
|
+
print("Listen and Answer response:", listenAndAnswerResponse)
|
|
114
|
+
except Exception as e:
|
|
115
|
+
print(f"Fehler bei Listen and Answer: {e}")
|
|
116
|
+
|
|
117
|
+
# Funktion ausführen
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
voiceExamples()
|