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

Add AUTO mode to HVAC #66

Merged
merged 2 commits into from
Sep 25, 2017
Merged
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
5 changes: 4 additions & 1 deletion test/climate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def test_set_operation_mode_with_controller_status(self):
group_address_controller_status='1/2/4')

for operation_mode in HVACOperationMode:
if operation_mode == HVACOperationMode.AUTO: continue
self.loop.run_until_complete(asyncio.Task(climate.set_operation_mode(operation_mode)))
self.assertEqual(xknx.telegrams.qsize(), 1)
telegram = xknx.telegrams.get_nowait()
Expand Down Expand Up @@ -444,6 +445,7 @@ def test_process_operation_mode(self):
self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
self.assertEqual(climate.operation_mode, operation_mode)
for operation_mode in HVACOperationMode:
if operation_mode == HVACOperationMode.AUTO: continue
telegram = Telegram(Address('1/2/3'))
telegram.payload = DPTArray(DPTControllerStatus.to_knx(operation_mode))
self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
Expand Down Expand Up @@ -508,7 +510,8 @@ def test_supported_operation_modes(self):
group_address_operation_mode='1/2/5')
self.assertEqual(
climate.get_supported_operation_modes(),
[HVACOperationMode.COMFORT,
[HVACOperationMode.AUTO,
HVACOperationMode.COMFORT,
HVACOperationMode.STANDBY,
HVACOperationMode.NIGHT,
HVACOperationMode.FROST_PROTECTION])
Expand Down
4 changes: 4 additions & 0 deletions test/dpt_hvac_mode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ class TestDPTControllerStatus(unittest.TestCase):

def test_mode_to_knx(self):
"""Test parsing DPTHVACMode to KNX."""
self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.AUTO), (0x00,))
self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.COMFORT), (0x01,))
self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.STANDBY), (0x02,))
self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.NIGHT), (0x03,))
self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.FROST_PROTECTION), (0x04,))

def test_mode_from_knx(self):
"""Test parsing DPTHVACMode from KNX."""
self.assertEqual(DPTHVACMode.from_knx((0x00,)), HVACOperationMode.AUTO)
self.assertEqual(DPTHVACMode.from_knx((0x01,)), HVACOperationMode.COMFORT)
self.assertEqual(DPTHVACMode.from_knx((0x02,)), HVACOperationMode.STANDBY)
self.assertEqual(DPTHVACMode.from_knx((0x03,)), HVACOperationMode.NIGHT)
self.assertEqual(DPTHVACMode.from_knx((0x04,)), HVACOperationMode.FROST_PROTECTION)

def test_controller_status_to_knx(self):
"""Test parsing DPTControllerStatus to KNX."""
with self.assertRaises(ConversionError):
DPTControllerStatus.to_knx(HVACOperationMode.AUTO)
self.assertEqual(DPTControllerStatus.to_knx(HVACOperationMode.COMFORT), (0x21,))
self.assertEqual(DPTControllerStatus.to_knx(HVACOperationMode.STANDBY), (0x22,))
self.assertEqual(DPTControllerStatus.to_knx(HVACOperationMode.NIGHT), (0x24,))
Expand Down
2 changes: 1 addition & 1 deletion xknx/devices/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def get_supported_operation_modes(self):
if self.group_address_operation_mode is not None:
return list(HVACOperationMode)
if self.group_address_controller_status is not None:
return list(HVACOperationMode)
return list( m for m in HVACOperationMode if m != HVACOperationMode.AUTO )

# Operation modes only supported partially
operation_modes = []
Expand Down
12 changes: 10 additions & 2 deletions xknx/knx/dpt_hvac_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class HVACOperationMode(Enum):
"""Enum for the different KNX HVAC operation modes."""

AUTO = "Auto"
COMFORT = "Comfort"
STANDBY = "Standby"
NIGHT = "Night"
Expand All @@ -32,11 +33,15 @@ def from_knx(cls, raw):
return HVACOperationMode.STANDBY
elif raw[0] == 0x01:
return HVACOperationMode.COMFORT
elif raw[0] == 0x00:
return HVACOperationMode.AUTO

@classmethod
def to_knx(cls, value):
"""Serialize to KNX/IP raw data."""
if value == HVACOperationMode.COMFORT:
if value == HVACOperationMode.AUTO:
return (0,)
elif value == HVACOperationMode.COMFORT:
return (1,)
elif value == HVACOperationMode.STANDBY:
return (2,)
Expand Down Expand Up @@ -73,7 +78,10 @@ def from_knx(cls, raw):
@classmethod
def to_knx(cls, value):
"""Serialize to KNX/IP raw data."""
if value == HVACOperationMode.COMFORT:
if value == HVACOperationMode.AUTO:
from xknx.exceptions import ConversionError
raise ConversionError(value)
elif value == HVACOperationMode.COMFORT:
return (0x21,)
elif value == HVACOperationMode.STANDBY:
return (0x22,)
Expand Down