Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Apr 12, 2024
1 parent abe9ed9 commit 17f880f
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 50 deletions.
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Packages required to build the documentation
sphinx == 7.2.6
sphinx-autodoc-typehints == 2.0.0
sphinx-autodoc-typehints == 2.0.1
sphinx_rtd_theme == 2.0.0
sphinx-exec-code == 0.12
autodoc_pydantic == 2.0.1
autodoc_pydantic == 2.1.0
sphinx-copybutton == 0.5.2
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ MyOpenhabRule()
```

# Changelog
#### 24.XX.X (2024-XX-XX)
- Updated number parsing logic
- Updated dependencies

#### 24.02.0 (2024-02-14)
- For openHAB >= 4.1 it's possible to wait for a minimum openHAB uptime before connecting (defaults to 60s)
- Renamed config entry mqtt.connection.client_id to identifier (backwards compatible)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Packages for source formatting
# -----------------------------------------------------------------------------
pre-commit == 3.5.0 # 3.6.0 requires python >= 3.10
ruff == 0.2.1
ruff == 0.3.7

# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
12 changes: 7 additions & 5 deletions requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
aiohttp == 3.9.3
pydantic == 2.6.1
aiohttp == 3.9.4
pydantic == 2.7.0
msgspec == 0.18.6
bidict == 0.22.1
bidict == 0.23.1
watchdog == 4.0.0
ujson == 5.9.0
aiomqtt == 2.0.0
aiomqtt == 2.0.1

immutables == 0.20
eascheduler == 0.1.11
easyconfig == 0.3.2
pendulum == 2.1.2
stack_data == 0.6.3
colorama == 0.4.6
fastnumbers == 5.1.0


voluptuous == 0.14.2

typing-extensions == 4.9.0
typing-extensions == 4.11.0

aiohttp-sse-client == 0.2.1

Expand Down
4 changes: 2 additions & 2 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# -----------------------------------------------------------------------------
# Packages to run source tests
# -----------------------------------------------------------------------------
packaging == 23.2
packaging == 24.0
pytest == 7.4.4
pytest-asyncio == 0.23.4
pytest-asyncio == 0.23.6
1 change: 1 addition & 0 deletions src/HABApp/__check_dependency_packages__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_dependencies() -> list[str]:
'colorama',
'eascheduler',
'easyconfig',
'fastnumbers',
'pydantic',
'stack_data',
'voluptuous',
Expand Down
2 changes: 1 addition & 1 deletion src/HABApp/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# Development versions contain the DEV-COUNTER postfix:
# - 24.01.0.DEV-1

__version__ = '24.02.1.DEV-1'
__version__ = '24.04.1.DEV-1'
16 changes: 3 additions & 13 deletions src/HABApp/openhab/definitions/helpers/persistence_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime
from typing import Optional, Union

from fastnumbers import try_real

from HABApp.openhab.definitions.rest import ItemHistoryResp


Expand All @@ -18,19 +20,7 @@ def from_resp(cls, data: ItemHistoryResp) -> 'OpenhabPersistenceData':
for entry in data.data:
# calc as timestamp
time = entry.time / 1000
state = entry.state
if '.' in state:
try:
state = float(state)
except ValueError:
pass
else:
try:
state = int(state)
except ValueError:
pass

c.data[time] = state
c.data[time] = try_real(entry.state)
return c

def get_data(self, start_date: OPTIONAL_DT = None, end_date: OPTIONAL_DT = None):
Expand Down
9 changes: 4 additions & 5 deletions src/HABApp/openhab/definitions/values.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from base64 import b64decode
from typing import Tuple, Union
from typing import Tuple

from fastnumbers import real

from HABApp.core.events import ComplexEventValue

Expand Down Expand Up @@ -92,10 +94,7 @@ def split_unit(value: str) -> Tuple[str, str]:

def __init__(self, value: str):
value, unit = QuantityValue.split_unit(value)
try:
val: Union[int, float] = int(value)
except ValueError:
val = float(value)
val = real(value)
super().__init__(val)
self.unit = unit

Expand Down
7 changes: 3 additions & 4 deletions src/HABApp/openhab/items/dimmer_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING, FrozenSet, Mapping, Optional, Union

from fastnumbers import real

from HABApp.openhab.items.base_item import MetaData, OpenhabItem
from HABApp.openhab.items.commands import OnOffCommand, PercentCommand

Expand Down Expand Up @@ -29,10 +31,7 @@ class DimmerItem(OpenhabItem, OnOffCommand, PercentCommand):

@staticmethod
def _state_from_oh_str(state: str):
try:
return int(state)
except ValueError:
return float(state)
return real(state)

def set_value(self, new_value) -> bool:

Expand Down
7 changes: 3 additions & 4 deletions src/HABApp/openhab/items/number_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING, FrozenSet, Mapping, Optional, Union

from fastnumbers import real

from HABApp.core.errors import InvalidItemValue, ItemValueIsNoneError
from HABApp.openhab.definitions import QuantityValue
from HABApp.openhab.items.base_item import MetaData, OpenhabItem
Expand Down Expand Up @@ -33,10 +35,7 @@ def unit(self) -> Optional[str]:

@staticmethod
def _state_from_oh_str(state: str):
try:
return int(state)
except ValueError:
return float(state)
return real(state)

def set_value(self, new_value) -> bool:

Expand Down
7 changes: 3 additions & 4 deletions src/HABApp/openhab/items/rollershutter_item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING, FrozenSet, Mapping, Optional, Union

from fastnumbers import real

from HABApp.core.errors import InvalidItemValue
from HABApp.openhab.definitions import PercentValue, UpDownValue
from HABApp.openhab.items.base_item import MetaData, OpenhabItem
Expand Down Expand Up @@ -28,10 +30,7 @@ class RollershutterItem(OpenhabItem, UpDownCommand, PercentCommand):

@staticmethod
def _state_from_oh_str(state: str):
try:
return int(state)
except ValueError:
return float(state)
return real(state)

def set_value(self, new_value) -> bool:

Expand Down
18 changes: 12 additions & 6 deletions src/HABApp/openhab/map_values.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from datetime import datetime

from fastnumbers import real

from HABApp.core.const.const import PYTHON_311
from HABApp.openhab.definitions import HSBValue, OnOffValue, OpenClosedValue, PercentValue, QuantityValue, RawValue, \
UpDownValue
from HABApp.openhab.definitions import (
HSBValue,
OnOffValue,
OpenClosedValue,
PercentValue,
QuantityValue,
RawValue,
UpDownValue,
)
from HABApp.openhab.definitions.values import PointValue


Expand All @@ -17,10 +26,7 @@ def map_openhab_values(openhab_type: str, openhab_value: str):
return int(openhab_value)

if openhab_type == "Decimal":
try:
return int(openhab_value)
except ValueError:
return float(openhab_value)
return real(openhab_value)

if openhab_type == "String":
return openhab_value
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/log/log_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def assert_ok(self):
msg += '\n - ' + '\n - '.join(map(str, missing))
msg += '\nLog:\n' + '\n'.join(self.get_messages())

pytest.fail(msg=msg)
pytest.fail(reason=msg)

for rec in self.res_records:
if not self.is_expected_record(rec):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_openhab/test_items/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def test_OnOff(cls):
c = cls('item_name')
assert not c.is_on()
if not __version__.startswith('24.02.0'):
if not __version__.startswith('24.04.0'):
assert not c.is_off()

c.set_value(OnOffValue('ON'))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_openhab/test_openhab_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_type_number(value: str, target: int):


@pytest.mark.parametrize(
'value, target', (('0.0', 0.0), ('-99.99', -99.99), ('99.99', 99.99), ('0', 0), ('-15', -15), ('55', 55), )
'value, target', (('0.0', 0), ('-99.99', -99.99), ('99.99', 99.99), ('0', 0), ('-15', -15), ('55', 55), )
)
def test_type_decimal(value: str, target: int):
ret = NumberItem._state_from_oh_str(value)
Expand Down

0 comments on commit 17f880f

Please sign in to comment.