def test_state_addresses(self): """Test state_addresses of Climate and ClimateMode.""" xknx = XKNX(loop=self.loop) climate_mode = ClimateMode( xknx, name=None, group_address_operation_mode='1/2/5', group_address_operation_mode_state='1/2/13', group_address_operation_mode_protection='1/2/6', group_address_operation_mode_night='1/2/7', group_address_operation_mode_comfort='1/2/8', group_address_controller_mode='1/2/9', group_address_controller_mode_state='1/2/10') climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4', group_address_on_off='1/2/11', group_address_on_off_state='1/2/12', mode=climate_mode) self.assertEqual(climate.state_addresses(), [ GroupAddress("1/2/1"), GroupAddress("1/2/4"), GroupAddress("1/2/12"), GroupAddress("1/2/13"), GroupAddress("1/2/10") ])
def test_process_callback(self): """Test if after_update_callback is called after update of Climate object was changed.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) climate.register_device_updated_cb(async_after_update_callback) self.loop.run_until_complete( asyncio.Task(climate.target_temperature.set(23.00))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock() self.loop.run_until_complete( asyncio.Task(climate.set_setpoint_shift(-2))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock()
def test_process_callback(self): """Test if after_update_callback is called after update of Climate object was changed.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) climate.register_device_updated_cb(async_after_update_callback) self.loop.run_until_complete(asyncio.Task( climate.target_temperature.set(23.00))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock() self.loop.run_until_complete(asyncio.Task( climate.setpoint_shift.set(-2))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock()
def test_set_operation_mode_with_separate_addresses(self): """Test set_operation_mode with combined and separated group adddresses defined.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_operation_mode='1/2/4', group_address_operation_mode_protection='1/2/5', group_address_operation_mode_night='1/2/6', group_address_operation_mode_comfort='1/2/7') self.loop.run_until_complete( asyncio.Task(climate.set_operation_mode( HVACOperationMode.COMFORT))) self.assertEqual(xknx.telegrams.qsize(), 4) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/4'), payload=DPTArray(1))) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/5'), payload=DPTBinary(0))) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/6'), payload=DPTBinary(0))) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/7'), payload=DPTBinary(1)))
def test_state_addresses(self): """Test state_addresses of Climate and ClimateMode.""" xknx = XKNX(loop=self.loop) climate_mode = ClimateMode( xknx, name=None, group_address_operation_mode='1/2/5', group_address_operation_mode_protection='1/2/6', group_address_operation_mode_night='1/2/7', group_address_operation_mode_comfort='1/2/8', group_address_controller_mode='1/2/9', group_address_controller_mode_state='1/2/10') climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4', group_address_on_off='1/2/11', group_address_on_off_state='1/2/12', mode=climate_mode) self.assertEqual( climate.state_addresses(), [GroupAddress("1/2/1"), GroupAddress("1/2/4"), GroupAddress("1/2/12"), GroupAddress("1/2/5"), GroupAddress("1/2/10")])
def test_supported_operation_modes_no_mode(self): """Test get_supported_operation_modes no operation_modes supported.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1') self.assertEqual(climate.get_supported_operation_modes(), [])
def test_initialized_for_setpoint_shift_calculations(self): """Test initialized_for_setpoint_shift_calculations method.""" xknx = XKNX(loop=self.loop) climate1 = Climate( xknx, 'TestClimate') self.assertFalse(climate1.initialized_for_setpoint_shift_calculations) climate2 = Climate( xknx, 'TestClimate', group_address_setpoint_shift='1/2/3') self.assertFalse(climate2.initialized_for_setpoint_shift_calculations) self.loop.run_until_complete(asyncio.Task(climate2.setpoint_shift.set(4))) self.assertFalse(climate2.initialized_for_setpoint_shift_calculations) climate3 = Climate( xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3') self.loop.run_until_complete(asyncio.Task(climate3.setpoint_shift.set(4))) self.assertFalse(climate3.initialized_for_setpoint_shift_calculations) self.loop.run_until_complete(asyncio.Task(climate3.target_temperature.set(23.00))) self.assertTrue(climate3.initialized_for_setpoint_shift_calculations)
def test_process_power_status(self): """Test process / reading telegrams from telegram queue. Test if DPT20.105 controller mode is set correctly.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_on_off='1/2/2') telegram = Telegram(GroupAddress('1/2/2')) telegram.payload = DPTBinary(1) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) self.assertEqual(climate.is_on, True)
def test_power_on_off(self): """Test turn_on and turn_off functions.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_on_off='1/2/2') self.loop.run_until_complete(asyncio.Task(climate.turn_on())) self.assertEqual(climate.is_on, True) self.loop.run_until_complete(asyncio.Task(climate.turn_off())) self.assertEqual(climate.is_on, False)
def test_supported_operation_modes_only_night(self): """Test get_supported_operation_modes with only night mode supported.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_operation_mode_night='1/2/7') self.assertEqual(climate.get_supported_operation_modes(), [HVACOperationMode.STANDBY, HVACOperationMode.NIGHT])
def test_target_temperature_down(self): """Test decrease target temperature.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3') self.loop.run_until_complete( asyncio.Task(climate.setpoint_shift.set(1))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual(xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(1))) self.loop.run_until_complete( asyncio.Task(climate.target_temperature.set(23.00))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(23.00)))) # First change self.loop.run_until_complete( asyncio.Task(climate.set_target_temperature(21.00))) self.assertEqual(xknx.telegrams.qsize(), 2) self.assertEqual(xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(0xFD))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(21.00)))) self.assertEqual(climate.target_temperature.value, 21.00) # Second change self.loop.run_until_complete( asyncio.Task(climate.set_target_temperature(19.50))) self.assertEqual(xknx.telegrams.qsize(), 2) self.assertEqual(xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(0xFA))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(19.50)))) self.assertEqual(climate.target_temperature.value, 19.50) # Test min target temperature self.assertEqual(climate.target_temperature_min, 19.50) # third change - limit exceeded, setting to max with self.assertRaises(DeviceIllegalValue): self.loop.run_until_complete( asyncio.Task(climate.set_target_temperature(19.00)))
def test_set_operation_mode_not_supported(self): """Test set_operation_mode but not supported.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1') with self.assertRaises(DeviceIllegalValue): self.loop.run_until_complete( asyncio.Task(climate.set_operation_mode( HVACOperationMode.AUTO)))
def test_custom_supported_operation_modes(self): """Test get_supported_operation_modes with custom mode override.""" modes = [HVACOperationMode.STANDBY, HVACOperationMode.NIGHT] xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_operation_mode='1/2/7', override_supported_operation_modes=modes) self.assertEqual(climate.get_supported_operation_modes(), modes)
def test_has_group_address(self): """Test if has_group_address function works.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4', group_address_operation_mode='1/2/5', group_address_operation_mode_protection='1/2/6', group_address_operation_mode_night='1/2/7', group_address_operation_mode_comfort='1/2/8', group_address_controller_mode='1/2/9', group_address_controller_mode_state='1/2/10', group_address_on_off='1/2/11', group_address_on_off_state='1/2/12') self.assertTrue(climate.has_group_address(GroupAddress('1/2/1'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/2'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/4'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/5'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/6'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/7'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/8'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/9'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/10'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/11'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/12'))) self.assertFalse(climate.has_group_address(GroupAddress('1/2/99')))
def test_process_operation_mode_payload_invalid_length(self): """Test process wrong telegram for operation mode (wrong payload length).""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_operation_mode='1/2/5', group_address_controller_status='1/2/3') telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23, 24))) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete( asyncio.Task(climate.process(telegram)))
def test_process_controller_status_wrong_payload(self): """Test process wrong telegram for controller status (wrong payload type).""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_operation_mode='1/2/5', group_address_controller_status='1/2/3') telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1)) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete( asyncio.Task(climate.process(telegram)))
def test_process_temperature(self): """Test process / reading telegrams from telegram queue. Test if temperature is processed correctly.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/3') telegram = Telegram(GroupAddress('1/2/3')) telegram.payload = DPTArray(DPTTemperature().to_knx(21.34)) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) self.assertEqual(climate.temperature.value, 21.34)
def test_custom_supported_operation_modes_as_str(self): """Test get_supported_operation_modes with custom mode override as str list.""" str_modes = ['STANDBY', 'FROST_PROTECTION'] modes = [HVACOperationMode.STANDBY, HVACOperationMode.FROST_PROTECTION] xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_operation_mode='1/2/7', override_supported_operation_modes=str_modes) self.assertEqual(climate.get_supported_operation_modes(), modes)
def test_power_on_off(self): """Test turn_on and turn_off functions.""" xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_on_off='1/2/2') self.loop.run_until_complete(asyncio.Task(climate.turn_on())) self.assertEqual(climate.is_on, True) self.loop.run_until_complete(asyncio.Task(climate.turn_off())) self.assertEqual(climate.is_on, False)
def test_process_power_status(self): """Test process / reading telegrams from telegram queue. Test if DPT20.105 controller mode is set correctly.""" xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_on_off='1/2/2') telegram = Telegram(GroupAddress('1/2/2')) telegram.payload = DPTBinary(1) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) self.assertEqual(climate.is_on, True)
def test_supported_operation_modes_controller_status(self): """Test get_supported_operation_modes with combined group address.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_controller_status='1/2/5') self.assertEqual(climate.get_supported_operation_modes(), [ HVACOperationMode.COMFORT, HVACOperationMode.STANDBY, HVACOperationMode.NIGHT, HVACOperationMode.FROST_PROTECTION ])
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/3') self.loop.run_until_complete(asyncio.Task(climate.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram1 = xknx.telegrams.get_nowait() self.assertEqual( telegram1, Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))
def test_process_temperature(self): """Test process / reading telegrams from telegram queue. Test if temperature is processed correctly.""" xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/3') telegram = Telegram(GroupAddress('1/2/3')) telegram.payload = DPTArray(DPTTemperature().to_knx(21.34)) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) self.assertEqual(climate.temperature.value, 21.34)
def test_process_controller_mode(self): """Test process / reading telegrams from telegram queue. Test if DPT20.105 controller mode is set correctly.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_controller_mode='1/2/5') for _v, operation_mode in DPTHVACContrMode.SUPPORTED_MODES.items(): telegram = Telegram(GroupAddress('1/2/5')) telegram.payload = DPTArray( DPTHVACContrMode.to_knx(operation_mode)) self.loop.run_until_complete( asyncio.Task(climate.process(telegram))) self.assertEqual(climate.operation_mode, operation_mode)
def test_supported_operation_modes_with_separate_addresses(self): """Test get_supported_operation_modes with separated group addresses.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_operation_mode_protection='1/2/5', group_address_operation_mode_night='1/2/6', group_address_operation_mode_comfort='1/2/7') self.assertEqual(climate.get_supported_operation_modes(), [ HVACOperationMode.COMFORT, HVACOperationMode.STANDBY, HVACOperationMode.NIGHT, HVACOperationMode.FROST_PROTECTION ])
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/3') self.loop.run_until_complete(asyncio.Task(climate.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram1 = xknx.telegrams.get_nowait() self.assertEqual( telegram1, Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))
def test_target_temperature_down(self): """Test decrease target temperature.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3') self.loop.run_until_complete(asyncio.Task(climate.setpoint_shift.set(1))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(1))) self.loop.run_until_complete(asyncio.Task(climate.target_temperature.set(23.00))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(23.00)))) # First change self.loop.run_until_complete(asyncio.Task(climate.set_target_temperature(21.00))) self.assertEqual(xknx.telegrams.qsize(), 2) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(0xFD))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(21.00)))) self.assertEqual(climate.target_temperature.value, 21.00) # Second change self.loop.run_until_complete(asyncio.Task(climate.set_target_temperature(19.50))) self.assertEqual(xknx.telegrams.qsize(), 2) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(0xFA))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(19.50)))) self.assertEqual(climate.target_temperature.value, 19.50) # Test min target temperature self.assertEqual(climate.target_temperature_min, 19.50) # third change - limit exceeded, setting to max with self.assertRaises(DeviceIllegalValue): self.loop.run_until_complete(asyncio.Task(climate.set_target_temperature(19.00)))
def test_power_on_off(self): """Test turn_on and turn_off functions.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_on_off='1/2/2') self.loop.run_until_complete(asyncio.Task(climate.turn_on())) self.assertEqual(climate.is_on, True) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTBinary(True))) self.loop.run_until_complete(asyncio.Task(climate.turn_off())) self.assertEqual(climate.is_on, False) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTBinary(False))) climate_inv = Climate(xknx, 'TestClimate', group_address_on_off='1/2/2', on_off_invert=True) self.loop.run_until_complete(asyncio.Task(climate_inv.turn_on())) self.assertEqual(climate_inv.is_on, True) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTBinary(False))) self.loop.run_until_complete(asyncio.Task(climate_inv.turn_off())) self.assertEqual(climate_inv.is_on, False) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTBinary(True)))
def test_climate(self): """Test string representation of climate object.""" xknx = XKNX() climate = Climate( xknx, name="Wohnzimmer", group_address_temperature="1/2/1", group_address_target_temperature="1/2/2", group_address_setpoint_shift="1/2/3", group_address_setpoint_shift_state="1/2/4", temperature_step=0.1, setpoint_shift_max=20, setpoint_shift_min=-20, group_address_on_off="1/2/14", group_address_on_off_state="1/2/15", ) assert ( str(climate) == '<Climate name="Wohnzimmer" ' "temperature=<None, 1/2/1, [], None /> " "target_temperature=<1/2/2, None, [], None /> " 'temperature_step="0.1" ' "setpoint_shift=<1/2/3, 1/2/4, [], None /> " 'setpoint_shift_max="20" setpoint_shift_min="-20" ' "group_address_on_off=<1/2/14, 1/2/15, [], None /> />" )
def test_climate(self): """Test string representation of climate object.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, name="Wohnzimmer", group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4', setpoint_shift_step=0.1, setpoint_shift_max=20, setpoint_shift_min=-20, group_address_operation_mode='1/2/5', group_address_operation_mode_state='1/2/6', group_address_operation_mode_protection='1/2/7', group_address_operation_mode_night='1/2/8', group_address_operation_mode_comfort='1/2/9', group_address_controller_status='1/2/10', group_address_controller_status_state='1/2/11', group_address_controller_mode='1/2/12', group_address_controller_mode_state='1/2/13', group_address_on_off='1/2/14', group_address_on_off_state='1/2/15') self.assertEqual( str(climate), '<Climate name="Wohnzimmer" temperature="GroupAddress("1/2/1")/None/None/None" target_temperature="GroupAddress("1/2/2")/None/None/' 'None" setpoint_shift="GroupAddress("1/2/3")/GroupAddress("1/2/4")/None/None" setpoint_shift_step="0.1" setpoint_shift_max="20" set' 'point_shift_min="-20" group_address_operation_mode="GroupAddress("1/2/5")" group_address_operation_mode_state="GroupAddress("1/2/6")' '" group_address_controller_status="GroupAddress("1/2/10")" group_address_controller_status_state="GroupAddress("1/2/11")" ' 'group_address_controller_mode="GroupAddress("1/2/12")" group_address_controller_mode_state="GroupAddress("1/2/13")" ' 'group_address_on_off="GroupAddress("1/2/14")/GroupAddress("1/2/15")/None/None" />' )
def test_uninitalized_for_target_temperature_min_max_can_be_overridden( self): """Test if target_temperature_min/target_temperature_max return overridden value if specified.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', min_temp='7', max_temp='35') self.assertEqual(climate.target_temperature_min, '7') self.assertEqual(climate.target_temperature_max, '35')
def parse_group_climate(self, entries): """Parse a climate section of xknx.yaml.""" for entry in entries: climate = Climate.from_config(self.xknx, entry, entries[entry]) self.xknx.devices.add(climate) if climate.mode is not None: self.xknx.devices.add(climate.mode)
def test_config_climate_temperature(self): """Test reading Climate object from config file.""" self.assertEqual( TestConfig.xknx.devices['Kitchen.Climate'], Climate(TestConfig.xknx, 'Kitchen.Climate', group_address_temperature='1/7/1', device_updated_cb=TestConfig.xknx.devices.device_updated))
async def main(): """Connect to KNX/IP and read the state of a Climate device.""" xknx = XKNX() async with xknx: climate = Climate(xknx, "Büro", group_address_temperature="1/4/121") await climate.sync(wait_for_result=True) # Will print out state of climate including current temperature: print(climate.temperature)
def test_config_climate_temperature(self): """Test reading Climate object from config file.""" self.assertEqual( TestConfig.xknx.devices["Kitchen.Climate"], Climate(TestConfig.xknx, "Kitchen.Climate", group_address_temperature="1/7/1"), )
def test_set_operation_mode(self): """Test set_operation_mode.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_operation_mode='1/2/4') for operation_mode in DPT_20102_MODES: self.loop.run_until_complete( asyncio.Task(climate.set_operation_mode(operation_mode))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram(GroupAddress('1/2/4'), payload=DPTArray(DPTHVACMode.to_knx(operation_mode))))
def test_sync_operation_mode(self): """Test sync function / sending group reads to KNX bus for operation mode.""" xknx = XKNX(loop=self.loop) climate = Climate(xknx, 'TestClimate', group_address_operation_mode='1/2/3', group_address_controller_status='1/2/4') self.loop.run_until_complete(asyncio.Task(climate.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 2) telegram1 = xknx.telegrams.get_nowait() self.assertEqual( telegram1, Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ)) telegram2 = xknx.telegrams.get_nowait() self.assertEqual( telegram2, Telegram(GroupAddress('1/2/4'), TelegramType.GROUP_READ))
def test_has_group_address(self): """Test if has_group_address function works.""" xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', group_address_setpoint_shift_state='1/2/4', group_address_on_off='1/2/11', group_address_on_off_state='1/2/12') self.assertTrue(climate.has_group_address(GroupAddress('1/2/1'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/2'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/4'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/11'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/12'))) self.assertFalse(climate.has_group_address(GroupAddress('1/2/99')))
def parse_group_climate(self, entries): """Parse a climate section of xknx.yaml.""" for entry in entries: climate = Climate.from_config( self.xknx, entry, entries[entry]) self.xknx.devices.add(climate) if climate.mode is not None: self.xknx.devices.add(climate.mode)
def test_process_callback_temp(self): """Test process / reading telegrams from telegram queue. Test if callback is executed when receiving temperature.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/3') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) climate.register_device_updated_cb(async_after_update_callback) telegram = Telegram(GroupAddress('1/2/3')) telegram.payload = DPTArray(DPTTemperature().to_knx(21.34)) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) after_update_callback.assert_called_with(climate)
def test_process_callback_updated_via_telegram(self): """Test if after_update_callback is called after update of Climate object.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_temperature='1/2/1', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) climate.register_device_updated_cb(async_after_update_callback) telegram = Telegram(GroupAddress('1/2/1'), payload=DPTArray(DPTTemperature.to_knx(23))) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock() telegram = Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPTTemperature.to_knx(23))) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock() telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray(DPTValue1Count.to_knx(-4))) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) after_update_callback.assert_called_with(climate) after_update_callback.reset_mock()
def test_target_temperature_modified_step(self): """Test increase target temperature with modified step size.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate = Climate( xknx, 'TestClimate', group_address_target_temperature='1/2/2', group_address_setpoint_shift='1/2/3', setpoint_shift_step=0.1, setpoint_shift_max=20, setpoint_shift_min=-20) self.loop.run_until_complete(asyncio.Task(climate.setpoint_shift.set(10))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(10))) self.loop.run_until_complete(asyncio.Task(climate.target_temperature.set(23.00))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(23.00)))) self.loop.run_until_complete(asyncio.Task(climate.set_target_temperature(24.00))) self.assertEqual(xknx.telegrams.qsize(), 2) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/3'), payload=DPTArray(20))) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(GroupAddress('1/2/2'), payload=DPTArray(DPT2ByteFloat().to_knx(24.00)))) self.assertEqual(climate.target_temperature.value, 24.00) # Test max/min target temperature self.assertEqual(climate.target_temperature_max, 24.00) self.assertEqual(climate.target_temperature_min, 20.00)
def test_climate_mode_process_callback_updated_via_telegram(self): """Test if after_update_callback is called after update of ClimateMode object.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) climate_mode = ClimateMode( xknx, 'TestClimateMode', group_address_operation_mode='1/2/4') after_update_callback = Mock() climate = Climate(xknx, 'TestClimate', mode=climate_mode) async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) climate_mode.register_device_updated_cb(async_after_update_callback) # Note: the climate object processes the telegram, but the cb # is called with the climate_mode object. telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(1)) self.loop.run_until_complete(asyncio.Task(climate.process(telegram))) after_update_callback.assert_called_with(climate_mode) after_update_callback.reset_mock()
def test_has_group_address_mode(self): """Test if has_group_address function works.""" xknx = XKNX(loop=self.loop) climate_mode = ClimateMode( xknx, name=None, group_address_operation_mode='1/2/5', group_address_operation_mode_protection='1/2/6', group_address_operation_mode_night='1/2/7', group_address_operation_mode_comfort='1/2/8', group_address_controller_mode='1/2/9', group_address_controller_mode_state='1/2/10') climate = Climate(xknx, name='TestClimate', mode=climate_mode) self.assertTrue(climate.has_group_address(GroupAddress('1/2/5'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/6'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/7'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/8'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/9'))) self.assertTrue(climate.has_group_address(GroupAddress('1/2/10'))) self.assertFalse(climate.has_group_address(GroupAddress('1/2/99')))