Skip to content

Commit

Permalink
0.14.1 (#158)
Browse files Browse the repository at this point in the history
0.14.1
- Added Number:Dimensionless as a unit of measurement (closes #157 )
- made z-wave table more robust
  • Loading branch information
spacemanspiff2007 authored Jul 5, 2020
1 parent e984df4 commit e124fca
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion HABApp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.14.0'
__version__ = '0.14.1'
4 changes: 2 additions & 2 deletions HABApp/openhab/connection_handler/func_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def validate(_in):
# limit values to special entries and validate parameters
if ':' in item_type:
__type, __unit = item_type.split(':')
assert __unit in definitions.ITEM_DIMENSION, \
f'{__unit} is not a valid Openhab unit: {", ".join(definitions.ITEM_DIMENSION)}'
assert __unit in definitions.ITEM_DIMENSIONS, \
f'{__unit} is not a valid Openhab unit: {", ".join(definitions.ITEM_DIMENSIONS)}'
assert __type in definitions.ITEM_TYPES, \
f'{__type} is not a valid OpenHAB type: {", ".join(definitions.ITEM_TYPES)}'
else:
Expand Down
12 changes: 8 additions & 4 deletions HABApp/openhab/connection_logic/plugin_thing_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ async def on_connect_function(self):
if not is_zw:
continue

# optional properties which can be set
props = node['properties']
channels = node.get('channels', [])

zw_node.add(int(props['zwave_nodeid']))
# Node-ID, e.g. 5
node_id = props.get('zwave_nodeid')
zw_node.add(int(node_id) if node_id is not None else '')

# optional properties
zw_model.add(props.get('modelId', ''))
zw_fw.add(props.get('zwave_version', ''))

zw_l_channels.add(
', '.join(map(lambda x: x.get('channelTypeUID', ''), filter(lambda x: x.get('linkedItems'), channels))))
', '.join(map(lambda x: x.get('channelTypeUID', ''), filter(lambda x: x.get('linkedItems'), channels)))
)
zw_u_channels.add(', '.join(
map(lambda x: x.get('channelTypeUID', ''), filter(lambda x: not x.get('linkedItems'), channels))))
map(lambda x: x.get('channelTypeUID', ''), filter(lambda x: not x.get('linkedItems'), channels)))
)

log = logging.getLogger('HABApp.openhab.things')
for line in thing_table.get_lines(sort_columns=[thing_uid]):
Expand Down
2 changes: 1 addition & 1 deletion HABApp/openhab/definitions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .definitions import ITEM_TYPES, ITEM_DIMENSION, GROUP_FUNCTIONS
from .definitions import ITEM_TYPES, ITEM_DIMENSIONS, GROUP_FUNCTIONS
from .values import OnOffValue, PercentValue, UpDownValue, HSBValue, QuantityValue, OpenClosedValue, RawValue
from . import rest
2 changes: 1 addition & 1 deletion HABApp/openhab/definitions/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
'Color', 'DateTime', 'Location', 'Player', 'Group', 'Image',
}

ITEM_DIMENSION = {'Length', 'Temperature', 'Pressure', 'Speed', 'Intensity', 'Angle'}
ITEM_DIMENSIONS = {'Length', 'Temperature', 'Pressure', 'Speed', 'Intensity', 'Angle', 'Dimensionless'}

GROUP_FUNCTIONS = {'AND', 'OR', 'NAND', 'NOR', 'AVG', 'MAX', 'MIN', 'SUM'}
4 changes: 3 additions & 1 deletion HABApp/openhab/definitions/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class QuantityValue(ComplexEventValue):
@staticmethod
def split_unit(value: str) -> typing.Tuple[str, str]:
p = value.rfind(' ')
assert p >= 0, f'No unit separator found for QuantityValue in "{value}"'
# dimensionless has no unit
if p < 0:
return value, ''
val = value[0:p]
unit = value[p + 1:]
return val, unit
Expand Down
2 changes: 1 addition & 1 deletion HABApp/openhab/map_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def map_items(name, openhab_type: str, openhab_value: str) -> typing.Optional[Ba
# Quantity types are like this: Number:Temperature and have a unit set: "12.3 °C".
# We have to remove the dimension from the type and remove the unit from the value
if ':' in openhab_type:
openhab_type = openhab_type[:openhab_type.find(':')]
openhab_type, dimension = openhab_type.split(':')
# if the item is not initialized its None and has no dimension
if value is not None:
value, _ = QuantityValue.split_unit(value)
Expand Down
12 changes: 7 additions & 5 deletions HABApp/rule/scheduler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _calculate_next_call(self):
raise NotImplementedError()

def earliest(self, time_obj: typing.Optional[time]) -> 'ScheduledCallbackBase':
"""Set earliest boundary as time of day
"""Set earliest boundary as time of day. ``None`` will disable boundary.
:param time_obj: time obj, scheduler will not run earlier
"""
Expand All @@ -82,7 +82,7 @@ def earliest(self, time_obj: typing.Optional[time]) -> 'ScheduledCallbackBase':
return self

def latest(self, time_obj: typing.Optional[time]) -> 'ScheduledCallbackBase':
"""Set earliest boundary as time of day
"""Set earliest boundary as time of day. ``None`` will disable boundary.
:param time_obj: time obj, scheduler will not run later
"""
Expand All @@ -94,7 +94,7 @@ def latest(self, time_obj: typing.Optional[time]) -> 'ScheduledCallbackBase':
return self

def offset(self, timedelta_obj: typing.Optional[timedelta]) -> 'ScheduledCallbackBase':
"""Set a constant offset to the calculation of the next run
"""Set a constant offset to the calculation of the next run. ``None`` will disable the offset.
:param timedelta_obj: constant offset
"""
Expand All @@ -106,7 +106,8 @@ def offset(self, timedelta_obj: typing.Optional[timedelta]) -> 'ScheduledCallbac
return self

def jitter(self, secs: typing.Optional[int]) -> 'ScheduledCallbackBase':
"""Add a random jitter per call in the intervall [(-1) * secs ... secs] to the next run
"""Add a random jitter per call in the intervall [(-1) * secs ... secs] to the next run.
``None`` will disable jitter.
:param secs: jitter in secs
"""
Expand All @@ -118,7 +119,8 @@ def jitter(self, secs: typing.Optional[int]) -> 'ScheduledCallbackBase':
return self

def boundary_func(self, func: typing.Optional[typing.Callable[[datetime], datetime]]):
"""Add a function which will be called when the datetime changes. Use this to implement custom boundaries
"""Add a function which will be called when the datetime changes. Use this to implement custom boundaries.
Use ``None`` to disable the boundary function.
:param func: Function which returns a datetime obj, arg is a datetime with the next call time
"""
Expand Down
4 changes: 2 additions & 2 deletions conf_testing/rules/test_openhab_event_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from HABApp.core.events import ValueUpdateEvent
from HABApp.openhab.definitions import ITEM_DIMENSION
from HABApp.openhab.definitions.definitions import ITEM_DIMENSIONS

from HABAppTests import TestBaseRule, EventWaiter, OpenhabTmpItem, get_openhab_test_events, \
get_openhab_test_types, get_openhab_test_states, ItemWaiter
Expand All @@ -15,7 +15,7 @@ def __init__(self):
for oh_type in get_openhab_test_types():
self.add_test( f'{oh_type} events', self.test_events, oh_type, get_openhab_test_events(oh_type))

for dimension in ITEM_DIMENSION:
for dimension in ITEM_DIMENSIONS:
self.add_test(f'Quantity {dimension} events', self.test_quantity_type_events, dimension)

def test_events(self, item_type, test_values):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_openhab/test_items/test_mapping.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from HABApp.openhab.map_items import map_items
from HABApp.openhab.items import NumberItem


def test_exception():
assert map_items('test', 'Number', 'asdf') is None


def test_number_unit_of_measurement():
assert map_items('test1', 'Number:Length', '1.0 m') == NumberItem('test', 1)
assert map_items('test2', 'Number:Temperature', '2.0 °C') == NumberItem('test', 2)
assert map_items('test3', 'Number:Pressure', '3.0 hPa') == NumberItem('test', 3)
assert map_items('test4', 'Number:Speed', '4.0 km/h') == NumberItem('test', 4)
assert map_items('test5', 'Number:Intensity', '5.0 W/m2') == NumberItem('test', 5)
assert map_items('test6', 'Number:Dimensionless', '6.0') == NumberItem('test', 6)
assert map_items('test7', 'Number:Angle', '7.0 °') == NumberItem('test', 7)
7 changes: 4 additions & 3 deletions tests/test_openhab/test_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from HABApp.openhab.definitions import HSBValue, OnOffValue, OpenClosedValue, PercentValue, QuantityValue, RawValue, \
UpDownValue
from HABApp.openhab.definitions import ITEM_DIMENSION
from HABApp.openhab.definitions import ITEM_DIMENSIONS


@pytest.mark.parametrize(
Expand Down Expand Up @@ -33,10 +33,11 @@ def test_val_convert(cls, values):

def test_quantity_value():
unit_of_dimension = {
'Length': 'm', 'Temperature': '°C', 'Pressure': 'hPa', 'Speed': 'km/h', 'Intensity': 'W/m²', 'Angle': '°'
'Length': 'm', 'Temperature': '°C', 'Pressure': 'hPa', 'Speed': 'km/h', 'Intensity': 'W/m²', 'Angle': '°',
'Dimensionless': '',
}

for dimension in ITEM_DIMENSION:
for dimension in ITEM_DIMENSIONS:
for val in (-103.3, -3, 0, 0.33535, 5, 55.5, 105.5):
unit = unit_of_dimension[dimension]
v = QuantityValue(f'{val} {unit}')
Expand Down

0 comments on commit e124fca

Please sign in to comment.