-
Notifications
You must be signed in to change notification settings - Fork 100
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
Executor Plugin: Improvements and fixes #776
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e8385cd
executor plugin: fix major issue with autocomplete. Now full item pat…
onkelandy 5e1fe2c
executor plugin: allow sorting of saved files, minor code improvements
onkelandy 8195163
executor plugin: re-write autocomplete method using worker and promis…
onkelandy 50a17eb
executor plugin: fix autocomplete dict. Previously (sub)items called …
onkelandy 5078592
executor plugin: fix and extend user_doc
onkelandy 1ba38c9
Executor Plugin: bump version
onkelandy f97d792
executor plugin: introduce popper.js tooltips for sorting
onkelandy 25b5417
executor plugin: add two database example scripts
onkelandy f1df7d6
executor plugin: introduce example scripts that can be loaded in the …
onkelandy 81326c1
executor plugin: change order of file list
onkelandy dbeb644
executor plugin: update user_doc
onkelandy 24b3c98
executor plugin: add new log levels such as notice, dbglow, etc.
onkelandy 231f5ac
executor plugin: improve button enable/disable
onkelandy c62414e
executor plugin: add additional examples
onkelandy c4a46c5
executor plugin: minor adjustment for button disable/input field clea…
onkelandy e23bf29
executor plugin: fix check_items example
onkelandy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import os | ||
|
||
with os.popen('ip neigh show') as result: | ||
# permanent, noarp, reachable, stale, none, incomplete, delay, probe, failed | ||
ip = '192.168.10.56' | ||
mac = "b4:b5:2f:ce:6d:29" | ||
value = False | ||
lines = str(result.read()).splitlines() | ||
for line in lines: | ||
if (ip in line or mac in line) and ("REACHABLE" in line or "STALE" in line): | ||
value = True | ||
break | ||
#sh.devices.laptop.status(value) | ||
print(f"set item to {value}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
given following items within a yaml: | ||
|
||
|
||
MyItem: | ||
MyChildItem: | ||
type: num | ||
initial_value: 12 | ||
MyGrandchildItem: | ||
type: str | ||
initial_value: "foo" | ||
|
||
Within a logic it is possible to set the value of MyChildItem to 42 with | ||
``sh.MyItem.MyChildItem(42)`` and retrieve the Items value with | ||
``value = sh.MyItem.MyChildItem()`` | ||
|
||
Often beginners forget the parentheses and instead write | ||
``sh.MyItem.MyChildItem = 42`` when they really intend to assign the value ``42`` | ||
to the item or write ``value = sh.MyItem.MyChildItem`` when they really want to | ||
retrieve the item's value. | ||
|
||
But using ``sh.MyItem.MyChildItem = 42`` destroys the structure here and makes | ||
it impossible to retrieve the value of the child | ||
``MyItem.MyChildItem.MyGrandchildItem`` | ||
Alike, an instruction as ``value = sh.MyItem.MyChildItem`` will not assign the | ||
value of ``sh.MyItem.MyChildItem`` but assign a reference to the item object | ||
``sh.MyItem.MyChildItem`` | ||
|
||
It is not possible with Python to intercept an assignment to a variable or an | ||
objects' attribute. The only thing one can do is search all items for a | ||
mismatching item type. | ||
|
||
This logic checks all items returned by SmartHomeNG, and if it encounters one | ||
which seems to be damaged like described before, it attempts to repair the | ||
broken assignment. | ||
|
||
""" | ||
from lib.item import Items | ||
from lib.item.item import Item | ||
|
||
def repair_item(sh, item): | ||
path = item.id() | ||
path_elems = path.split('.') | ||
ref = sh | ||
|
||
# traverse through object structure sh.path1.path2... | ||
try: | ||
for path_part in path_elems[:-1]: | ||
ref = getattr(ref, path_part) | ||
|
||
setattr(ref, path_elems[-1], item) | ||
print(f'Item reference repaired for {path}') | ||
return True | ||
except NameError: | ||
print(f'Error: item traversal for {path} failed at part {path_part}. Item list not sorted?') | ||
|
||
return False | ||
|
||
|
||
def get_item_type(sh, path): | ||
expr = f'type(sh.{path})' | ||
return str(eval(expr)) | ||
|
||
|
||
def check_item(sh, path): | ||
global get_item_type | ||
|
||
return get_item_type(sh, path) == "<class 'lib.item.item.Item'>" | ||
|
||
|
||
# to get access to the object instance: | ||
items = Items.get_instance() | ||
|
||
# to access a method (eg. to get the list of Items): | ||
# allitems = items.return_items() | ||
problems_found = 0 | ||
problems_fixed = 0 | ||
|
||
for one in items.return_items(ordered=True): | ||
# get the items full path | ||
path = one.property.path | ||
try: | ||
if not check_item(sh, path): | ||
logger.error(f"Error: item {path} has type {get_item_type(sh, path)} but should be an Item Object") | ||
problems_found += 1 | ||
if repair_item(sh, one): | ||
if check_item(sh, path): | ||
problems_fixed += 1 | ||
except ValueError as e: | ||
logger.error(f'Error {e} while processing item {path}, parent defective? Items not sorted?') | ||
|
||
if problems_found: | ||
logger.error(f"{problems_found} problematic item assignment{'' if problems_found == 1 else 's'} found, {problems_fixed} item assignment{'' if problems_fixed == 1 else 's'} fixed") | ||
else: | ||
logger.warning("no problems found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from lib.item import Items | ||
items = Items.get_instance() | ||
myfiller = " " | ||
allItems = items.return_items() | ||
for myItem in allItems: | ||
if not hasattr(myItem,'db'): | ||
continue | ||
mycount = myItem.db('countall', 0) | ||
print (myItem.property.name + myfiller[0:len(myfiller)-len(myItem.property.name)]+ ' - Anzahl Datensätze :'+str(mycount)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import json | ||
|
||
def myconverter(o): | ||
import datetime | ||
if isinstance(o, datetime.datetime): | ||
return o.__str__() | ||
data = sh.<your item here>.series('max','1d','now') | ||
pretty = json.dumps(data, default = myconverter, indent = 2, separators=(',', ': ')) | ||
print(pretty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
der stub_logger müsste noch um neuere methoden wie notice etc. erweitert werden...