async def test_is_on(self): """Test is_on() and is_off() of a BinarySensor with state 'on'.""" xknx = XKNX() binaryinput = BinarySensor(xknx, "TestInput", "1/2/3") assert not binaryinput.is_on() assert binaryinput.is_off() await binaryinput._set_internal_state(True) assert binaryinput.is_on() assert not binaryinput.is_off()
def test_is_on(self): """Test is_on() and is_off() of a BinarySensor with state 'on'.""" xknx = XKNX() binaryinput = BinarySensor(xknx, "TestInput", "1/2/3") self.assertFalse(binaryinput.is_on()) self.assertTrue(binaryinput.is_off()) # pylint: disable=protected-access self.loop.run_until_complete(binaryinput._set_internal_state(True)) self.assertTrue(binaryinput.is_on()) self.assertFalse(binaryinput.is_off())
def test_is_off(self): """Test is_on() and is_off() of a BinarySensor with state 'off'.""" xknx = XKNX(loop=self.loop) binaryinput = BinarySensor(xknx, 'TestInput', '1/2/3') # pylint: disable=protected-access self.loop.run_until_complete(asyncio.Task(binaryinput._set_internal_state(BinarySensorState.OFF))) self.assertFalse(binaryinput.is_on()) self.assertTrue(binaryinput.is_off())
def test_binary_sensor_loop(self): """Test binary_sensor and expose_sensor with binary values.""" test_cases = [ ("binary", DPTBinary(0), False), ("binary", DPTBinary(1), True), ] for value_type, test_payload, test_value in test_cases: with self.subTest(value_type=value_type): xknx = XKNX(loop=self.loop) sensor = BinarySensor( xknx, "TestSensor_%s" % value_type, group_address_state="1/1/1" ) expose = ExposeSensor( xknx, "TestExpose_%s" % value_type, group_address="2/2/2", value_type=value_type, ) incoming_telegram = Telegram( GroupAddress("1/1/1"), TelegramType.GROUP_WRITE, direction=TelegramDirection.INCOMING, payload=test_payload, ) self.loop.run_until_complete(sensor.process(incoming_telegram)) incoming_value = sensor.is_on() self.assertEqual(incoming_value, test_value) self.loop.run_until_complete(expose.set(test_value)) self.assertEqual(xknx.telegrams.qsize(), 1) outgoing_telegram = xknx.telegrams.get_nowait() self.assertEqual( outgoing_telegram, Telegram( GroupAddress("2/2/2"), TelegramType.GROUP_WRITE, direction=TelegramDirection.OUTGOING, payload=test_payload, ), )
def test_binary_sensor_loop(self): """Test binary_sensor and expose_sensor with binary values.""" test_cases = [ ('binary', DPTBinary(0), False), ('binary', DPTBinary(1), True), ] for value_type, test_payload, test_value in test_cases: with self.subTest(value_type=value_type): xknx = XKNX(loop=self.loop) sensor = BinarySensor( xknx, 'TestSensor_%s' % value_type, group_address_state='1/1/1' ) expose = ExposeSensor( xknx, 'TestExpose_%s' % value_type, group_address='2/2/2', value_type=value_type ) incoming_telegram = Telegram(GroupAddress('1/1/1'), TelegramType.GROUP_WRITE, direction=TelegramDirection.INCOMING, payload=test_payload) self.loop.run_until_complete(asyncio.Task(sensor.process(incoming_telegram))) incoming_value = sensor.is_on() self.assertEqual(incoming_value, test_value) self.loop.run_until_complete(asyncio.Task(expose.set(test_value))) self.assertEqual(xknx.telegrams.qsize(), 1) outgoing_telegram = xknx.telegrams.get_nowait() self.assertEqual( outgoing_telegram, Telegram( GroupAddress('2/2/2'), TelegramType.GROUP_WRITE, direction=TelegramDirection.OUTGOING, payload=test_payload))