コード例 #1
0
ファイル: devices_test.py プロジェクト: twistermcneal/xknx
    def test_iter(self):
        xknx = XKNX(self.loop, start=False)
        devices = Devices()

        light1 = Light(xknx,
                       'Living-Room.Light_1',
                       group_address_switch='1/6/7')
        devices.add(light1)

        sensor1 = Sensor(xknx,
                         'DiningRoom.Motion.Sensor',
                         group_address='3/0/1',
                         value_type='binary',
                         significant_bit=2)
        devices.add(sensor1)

        sensor2 = Sensor(xknx,
                         'DiningRoom.Motion.Sensor',
                         group_address='3/0/1',
                         value_type='binary',
                         significant_bit=3)
        devices.add(sensor2)

        light2 = Light(xknx,
                       'Living-Room.Light_2',
                       group_address_switch='1/6/8')

        devices.add(light2)

        self.assertEqual(tuple(devices.__iter__()),
                         (light1, sensor1, sensor2, light2))
コード例 #2
0
    def test_process(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')

        telegram = Telegram(Address('1/2/3'))
        telegram.payload = DPTArray((0x01, 0x02, 0x03))
        sensor.process(telegram)

        self.assertEqual(sensor.state, DPTArray((0x01, 0x02, 0x03)))
コード例 #3
0
    def test_str_scaling(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address='1/2/3',
                        value_type="percent")
        sensor.state = DPTArray((0x40, ))

        self.assertEqual(sensor.resolve_state(), "25")
        self.assertEqual(sensor.unit_of_measurement(), "%")
コード例 #4
0
    def test_sync_state(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')

        sensor.sync_state()

        self.assertEqual(xknx.telegrams.qsize(), 1)

        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(telegram,
                         Telegram(Address('1/2/3'), TelegramType.GROUP_READ))
コード例 #5
0
    def test_process_callback(self):
        # pylint: disable=no-self-use
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')

        after_update_callback = Mock()
        sensor.after_update_callback = after_update_callback

        telegram = Telegram(Address('1/2/3'))
        telegram.payload = DPTArray((0x01, 0x02, 0x03))
        sensor.process(telegram)

        after_update_callback.assert_called_with(sensor)
コード例 #6
0
ファイル: config_test.py プロジェクト: twistermcneal/xknx
 def test_config_sensor_percent(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['Heating.Valve1'],
         Sensor(xknx,
                'Heating.Valve1',
                group_address='2/0/0',
                value_type='percent'))
コード例 #7
0
ファイル: config_test.py プロジェクト: twistermcneal/xknx
 def test_config_sensor_binary_significant_bit(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['Kitchen.Thermostat.Presence'],
         Sensor(xknx,
                'Kitchen.Thermostat.Presence',
                group_address='3/0/2',
                value_type='binary',
                significant_bit=2))
コード例 #8
0
ファイル: config_test.py プロジェクト: twistermcneal/xknx
 def test_config_sensor_binary_sensor_class(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['DiningRoom.Motion.Sensor'],
         Sensor(xknx,
                'DiningRoom.Motion.Sensor',
                group_address='3/0/1',
                value_type='binary',
                sensor_class='motion'))
コード例 #9
0
 def test_not_binary(self):
     xknx = XKNX(self.loop, start=False)
     sensor = Sensor(xknx,
                     'TestSensor',
                     group_address='1/2/3',
                     value_type="percent")
     self.assertFalse(sensor.is_binary())
     self.assertFalse(sensor.binary_state())
     # Even after setting a binary value,
     # binary state should not return true
     sensor.state = DPTBinary(5)
     self.assertFalse(sensor.binary_state())
コード例 #10
0
ファイル: config_test.py プロジェクト: twistermcneal/xknx
 def test_config_sensor_no_value_type(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['Some.Other.Value'],
         Sensor(xknx, 'Some.Other.Value', group_address='2/0/2'))
コード例 #11
0
    def test_binary(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx,
                        'DiningRoom.Motion.Sensor',
                        group_address='3/0/1',
                        value_type='binary',
                        sensor_class='motion')
        self.assertEqual(sensor.significant_bit, 1)
        self.assertTrue(sensor.is_binary())

        # No sensor set, binary_state should resolve to False
        self.assertFalse(sensor.binary_state())

        # First bit is set
        sensor.state = DPTBinary(5)
        self.assertTrue(sensor.binary_state())

        # State with the wrong bit set
        sensor.state = DPTBinary(8)
        self.assertFalse(sensor.binary_state())

        # Shifting significant bit to 4th position
        sensor.significant_bit = 4
        sensor.state = DPTBinary(8)
        self.assertTrue(sensor.binary_state())
        sensor.state = DPTBinary(7)
        self.assertFalse(sensor.binary_state())
コード例 #12
0
    def test_str_binary(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')
        sensor.state = DPTBinary(5)

        self.assertEqual(sensor.resolve_state(), "101")
コード例 #13
0
    def test_str_array(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3')
        sensor.state = DPTArray((0x01, 0x02, 0x03))

        self.assertEqual(sensor.resolve_state(), "0x01,0x02,0x03")