Skip to content

Commit

Permalink
Merge pull request #39 from andreasnanko/dev
Browse files Browse the repository at this point in the history
Merge dev from fork back to xknx
  • Loading branch information
Julius2342 authored May 16, 2017
2 parents 720aca0 + 3096e46 commit c984453
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion xknx/knx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .telegram import Telegram, TelegramDirection, TelegramType
from .dpt import DPTBase, DPTBinary, DPTArray, ConversionError,\
DPTComparator
from .dpt_float import DPTFloat, DPTLux, DPTTemperature, DPTHumidity
from .dpt_float import DPTFloat, DPTLux, DPTTemperature, DPTHumidity, DPTWsp
from .dpt_scaling import DPTScaling
from .dpt_time import DPTTime, DPTWeekday
11 changes: 11 additions & 0 deletions xknx/knx/dpt_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class DPTLux(DPTFloat):
unit = "Lux"
resolution = 1

class DPTWsp(DPTFloat):
"""
Abstraction for KNX 2 Octet Floating Point Numbers
DPT 9.005
"""

value_min = 0
value_max = 670760
unit = "m/s"
resolution = 1

class DPTHumidity(DPTFloat):
"""
Abstraction for KNX 2 Octet Floating Point Numbers
Expand Down
16 changes: 10 additions & 6 deletions xknx/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from xknx.knx import Address, Telegram, TelegramType, DPTBinary, DPTArray, \
DPTScaling, DPTTemperature
DPTScaling, DPTTemperature, DPTLux, DPTWsp
from .device import Device

class Sensor(Device):
Expand Down Expand Up @@ -80,6 +80,10 @@ def unit_of_measurement(self):
return "%"
elif self.value_type == 'temperature':
return "°C"
elif self.value_type == 'brightness':
return "lx"
elif self.value_type == 'speed_ms':
return "m/s"
else:
return None

Expand All @@ -93,14 +97,14 @@ def resolve_state(self):
len(self.state.value) == 1:
# TODO: Instanciate DPTScaling object with DPTArray class
return "{0}".format(DPTScaling().from_knx(self.state.value))


elif self.value_type == 'binary':
return self.binary_state()

elif self.value_type == 'temperature':
return DPTTemperature().from_knx(self.state.value)

return DPTTemperature().from_knx(self.state.value)
elif self.value_type == 'brightness':
return DPTLux().from_knx(self.state.value)
elif self.value_type == 'speed_ms':
return DPTWsp().from_knx(self.state.value)
elif isinstance(self.state, DPTArray):
return ','.join('0x%02x'%i for i in self.state.value)

Expand Down

0 comments on commit c984453

Please sign in to comment.