Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality to receive Events from Openhab and added methods to create and delete openhab items #22

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4c06593
initial commit for added functionality to receive ItemEvents from Ope…
galexey Dec 5, 2020
969f525
receiving events works.
galexey Dec 8, 2020
1ac15fb
ItemFactory to create new items
galexey Dec 10, 2020
ac20567
added testcases for creation of all itemtypes
galexey Dec 13, 2020
deae6a0
added testcases
galexey Dec 13, 2020
92864c1
cleaning code (PEPs)
galexey Dec 14, 2020
7336dd3
Merge remote-tracking branch 'upstream/master'
galexey Dec 14, 2020
50f7504
merged with upstream master
galexey Dec 14, 2020
47c1a9e
updated samples in readme
galexey Dec 14, 2020
10e6973
fixed bug in event-parsing and testcases
galexey Dec 14, 2020
d442ec6
major refactor to better reflect incoming states/statechange and comm…
galexey Dec 20, 2020
628a9af
changed Server Side Events client to aiohttp_sse_client as suggested …
galexey Dec 30, 2020
0b1e91e
added http_buffersize to avoid "line too long" Exception
galexey Dec 30, 2020
77da438
added audiosinks
galexey Jan 3, 2021
70154e7
fix for _is_my_own_echo and Eventtypes
galexey Jan 20, 2021
7ac50f1
introduced a historylist of sent itemvalues for better echo checking
galexey Jan 28, 2021
64f1799
changed behaviour for not yet implemented OH types
galexey Feb 1, 2021
7ddd650
introduced slotted sending of changes
galexey Feb 2, 2021
3f1ff0c
changed item Factory and item creation methods for slotted sending of…
galexey Feb 3, 2021
55477f3
openHAB3
galexey Feb 13, 2021
2072ede
added widgets
galexey Mar 9, 2021
9f3a21f
added widgets
galexey Mar 9, 2021
c3a331b
decoupled receiving of events from processing of events through an ad…
galexey Mar 10, 2021
614b347
changes widget behaviour
galexey Mar 10, 2021
7ab6e9c
logging Q len
galexey Mar 14, 2021
3b7cfe7
token store
galexey Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ python library for accessing the openHAB REST API
This library allows for easily accessing the openHAB REST API.
A number of features are implemented but not all, this is work in progress.

currently you can
- retrieve current state of items
- send updates and commands to items
- receive commands, updates and changes triggered by openhab
- create new items and groups
- delete items and groups


Requirements
------------

- python >= 3.5
- python :: dateutil
- python :: requests
- python :: sseclient
- openHAB version 2

Installation
Expand All @@ -49,7 +58,7 @@ Example usage of the library:
from openhab import OpenHAB

base_url = 'http://localhost:8080/rest'
openhab = OpenHAB(base_url)
openhab = OpenHAB(base_url,autoUpdate=True)

# fetch all items
items = openhab.fetch_all_items()
Expand Down Expand Up @@ -87,6 +96,60 @@ Example usage of the library:
for v in lights_group.members.values():
v.update('OFF')

# receive updates from openhab:

# fetch a item and keep it
testroom1_LampOnOff = openhab.get_item('light_switch')

#define a callback function to receive events
def onLight_switchCommand(item: openhab.items.Item, event: openhab.events.ItemCommandEvent):
log.info("########################### COMMAND of {} to {} (itemsvalue:{}) from OPENHAB".format(event.itemname, event.newValueRaw, item.state))
if event.source == openhab.events.EventSourceOpenhab:
log.info("this change came from openhab")
# install listener for evetns
testroom1_LampOnOff.add_event_listener(listening_types=openhab.events.ItemCommandEventType, listener=onLight_switchCommand, only_if_eventsource_is_openhab=False)
# switch you will receive update also for your changes in the code. (see
testroom1_LampOnOff.off()

#Events stop to be delivered
testroom1_LampOnOff=None


#create or delete items:
# first instantiate a Factory:
itemFactory = openhab.items.ItemFactory(openhab)
#create the item
testDimmer = itemFactory.create_or_update_item(name="the_testDimmer", data_type=openhab.items.DimmerItem)
#use item
testDimmer.state=95



# you can set change many item attributes:
nameprefix="testcase_1_"
itemname = "{}CreateItemTest".format(nameprefix)
item_quantity_type = "Angle" # "Length",Temperature,,Pressure,Speed,Intensity,Dimensionless,Angle
itemtype = "Number"

labeltext = "das ist eine testzahl:"
itemlabel = "[{labeltext}%.1f °]".format(labeltext=labeltext)
itemcategory = "{}TestCategory".format(nameprefix)
itemtags: List[str] = ["{}testtag1".format(nameprefix), "{}testtag2".format(nameprefix)]
itemgroup_names: List[str] = ["{}testgroup1".format(nameprefix), "{}testgroup2".format(nameprefix)]
grouptype = "{}testgrouptype".format(nameprefix)
functionname = "{}testfunctionname".format(nameprefix)
functionparams: List[str] = ["{}testfunctionnameParam1".format(nameprefix), "{}testfunctionnameParam2".format(nameprefix), "{}testfunctionnameParam3".format(nameprefix)]

x2 = item_factory.create_or_update_item(name=itemname,
data_type=itemtype,
quantity_type=item_quantity_type,
label=itemlabel,
category=itemcategory,
tags=itemtags,
group_names=itemgroup_names,
group_type=grouptype,
function_name=functionname,
function_params=functionparams)

Note on NULL and UNDEF
----------------------
Expand Down
Loading