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

Version and OpenHAB compatibility check #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions Core/automation/jsr223/core/components/000_Version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import core
from core.log import logging, LOG_PREFIX
from org.openhab.core import OpenHAB

log = logging.getLogger(LOG_PREFIX + ".core")

def scriptLoaded(*args):
log.info("openhab2-jython version: {}".format(core.__version__))
if not core.openhab_support(OpenHAB.getVersion(), OpenHAB.buildString()):
log.warn("OpenHAB in version '{}' is not fully supported by openhab2-jython-{}".format(
OpenHAB.getVersion(), core.__version__))
21 changes: 21 additions & 0 deletions Core/automation/lib/python/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,24 @@ def _item_getattr(self, name):
return self[name]

type(items).__getattr__ = _item_getattr.__get__(items, type(items))

__version__="1.0.0a"

def openhab_support(version, build_number):
"""Checks if given OpenHab version is compatible with this release

Arguments:
version {str} -- version of OpenHab (ex. 2.4.0, 2.4.0-M2)
build_number {str} -- build string reported by OpenHAB instance (ignored for now)

Returns:
True -- scripts are known to be working with this version of OH
False -- OH version is too old or not tested, issues might arise
"""
from pkg_resources import parse_version

# Get rid of -SNAPSHOT or -MX suffix for 'epoch' comparison
ver_tuple = version.split("-", 1)
ver_epoch = parse_version(ver_tuple[0])

return ver_epoch >= parse_version("2.4.0")