Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
 def test_set_brightness(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_dimm='1/2/4',
                   group_address_brightness='1/2/5')
     light.set_brightness(23)
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(Address('1/2/5'), payload=DPTArray(23)))
Ejemplo n.º 3
0
    def test_process_dimm(self):
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.brightness, 0)

        telegram = Telegram(Address('1/2/5'), payload=DPTArray(23))
        light.process(telegram)
        self.assertEqual(light.brightness, 23)
Ejemplo n.º 4
0
    def test_process_switch_callback(self):
        # pylint: disable=no-self-use
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')

        after_update_callback = Mock()
        light.after_update_callback = after_update_callback

        telegram = Telegram(Address('1/2/3'), payload=DPTBinary(1))
        light.process(telegram)

        after_update_callback.assert_called_with(light)
Ejemplo n.º 5
0
    def test_modification_of_device(self):
        """ This test should verify that devices only
        stores the references of an object and all
        accessing functions only return referecenes of
        the same object"""

        xknx = XKNX(self.loop, start=False)
        devices = Devices()

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

        for device in devices:
            device.set_on()

        self.assertTrue(light1.state)

        device2 = devices["Living-Room.Light_1"]
        device2.set_off()

        self.assertFalse(light1.state)

        for device in devices.devices_by_group_address(Address('1/6/7')):
            device.set_on()

        self.assertTrue(light1.state)
Ejemplo n.º 6
0
 def test_supports_dimm_yes(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx,
                   'Diningroom.Light_1',
                   group_address_switch='1/6/4',
                   group_address_dimm='1/6/5',
                   group_address_brightness='1/6/6')
     self.assertTrue(light.supports_dimming)
Ejemplo n.º 7
0
    def test_sync_state(self):
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')
        light.sync_state()

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

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(telegram1,
                         Telegram(Address('1/2/3'), TelegramType.GROUP_READ))

        telegram2 = xknx.telegrams.get_nowait()
        self.assertEqual(telegram2,
                         Telegram(Address('1/2/5'), TelegramType.GROUP_READ))
Ejemplo n.º 8
0
 def test_config_ligh_dimm(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['Diningroom.Light_1'],
         Light(xknx,
               'Diningroom.Light_1',
               group_address_switch='1/6/4',
               group_address_dimm='1/6/5',
               group_address_brightness='1/6/6'))
Ejemplo n.º 9
0
 def test_do(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_dimm='1/2/4',
                   group_address_brightness='1/2/5')
     light.do("on")
     self.assertTrue(light.state)
     light.do("brightness:80")
     self.assertEqual(light.brightness, 80)
     light.do("off")
     self.assertFalse(light.state)
Ejemplo n.º 10
0
    def test_get_item(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)

        outlet1 = Outlet(xknx, "TestOutlet_1", group_address='1/2/3')
        devices.add(outlet1)

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

        outlet2 = Outlet(xknx, "TestOutlet_2", group_address='1/2/4')
        devices.add(outlet2)

        self.assertEqual(devices["Living-Room.Light_1"], light1)
        self.assertEqual(devices["Living-Room.Light_2"], light2)
        self.assertEqual(devices["TestOutlet_1"], outlet1)
        self.assertEqual(devices["TestOutlet_2"], outlet2)
Ejemplo n.º 11
0
    def test_process_switch(self):
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.state, False)

        telegram = Telegram(Address('1/2/3'), payload=DPTBinary(1))
        light.process(telegram)
        self.assertEqual(light.state, True)

        telegram = Telegram(Address('1/2/3'), payload=DPTBinary(0))
        light.process(telegram)
        self.assertEqual(light.state, False)
Ejemplo n.º 12
0
 def test_supports_dimm_no(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx, 'Diningroom.Light_1', group_address_switch='1/6/4')
     self.assertFalse(light.supports_dimming)
Ejemplo n.º 13
0
 def test_config_light(self):
     xknx = XKNX(self.loop, start=False)
     Config(xknx).read('../xknx.yaml')
     self.assertEqual(
         xknx.devices['Living-Room.Light_1'],
         Light(xknx, 'Living-Room.Light_1', group_address_switch='1/6/7'))