Skip to content

Commit a998373

Browse files
committed
fix parsing and exposing unit of measure; fixes #26
1 parent 5eda6f0 commit a998373

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

openhab/client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import json
2323
import logging
2424
import pathlib
25-
import re
2625
import time
2726
import typing
2827
import warnings
@@ -269,12 +268,6 @@ def json_to_item(self, json_data: dict) -> openhab.items.Item:
269268
return openhab.items.ContactItem(self, json_data)
270269

271270
if _type.startswith('Number'):
272-
if _type.startswith('Number:'):
273-
m = re.match(r'''^([^\s]+)''', json_data['state'])
274-
275-
if m:
276-
json_data['state'] = m.group(1)
277-
278271
return openhab.items.NumberItem(self, json_data)
279272

280273
if _type == 'Dimmer':

openhab/items.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, openhab_conn: 'openhab.client.OpenHAB', json_data: dict) -> N
6464
self.group = False
6565
self.name = ''
6666
self._state = None # type: typing.Optional[typing.Any]
67+
self._unitOfMeasure = ''
6768
self._raw_state = None # type: typing.Optional[typing.Any] # raw state as returned by the server
6869
self._members = {} # type: typing.Dict[str, typing.Any] # group members (key = item name), for none-group items it's empty
6970
self.function_name: typing.Optional[str] = None
@@ -140,6 +141,11 @@ def state(self) -> typing.Any:
140141
def state(self, value: typing.Any) -> None:
141142
self.update(value)
142143

144+
@property
145+
def unit_of_measure(self) -> str:
146+
"""Return the unit of measure. Returns an empty string if there is none defined."""
147+
return self._unitOfMeasure
148+
143149
@property
144150
def members(self) -> typing.Dict[str, typing.Any]:
145151
"""If item is a type of Group, it will return all member items for this group.
@@ -583,10 +589,6 @@ def _rest_format(self, value: typing.Union[typing.Tuple[int, int, float], str, i
583589

584590
return value
585591

586-
@staticmethod
587-
def __extract_value_and_unitofmeasure(value: str) -> typing.Tuple[str, str]:
588-
return value, ''
589-
590592

591593
class RollershutterItem(Item):
592594
"""RollershutterItem item type."""

0 commit comments

Comments
 (0)