def test_set_light_baseline(self):
     self.device = Device.init_from_config(self.config)
     data = dict(value=True, brightness=100)
     message = OcfRequest(
         **dict(operation='update', uri_path=['light'], data=data))
     self.device.on_init()
     result = self.device.on_post_request(message)
     self.assertDictEqual(result, data)
    def test_get_light_brightness(self):
        self.device = Device.init_from_config(
            None, dict(handler=Device.__name__, data=self.config))
        message = OcfRequest(**dict(operation='get',
                                    uri='/light',
                                    query={'rt': ['oic.r.light.brightness']}))
        self.device.on_get_request(message)

        # self.devices.run()
        pass
 async def test_find_devices(self):
     modbus_device = ModbusDevice.init_from_config(self.modbus_config,
                                                   path=self.config_path)
     mobus_task = await wait_run_device(modbus_device)
     self.config['/oic/con']['master'] = modbus_device.link
     self.device = Device.init_from_config(self.config,
                                           path=self.config_path)
     device_task = await wait_run_device(self.device)
     res = await self.device.action_find_devices()
     pass
 async def test_power(self):
     value = True
     modbus_device = ModbusDevice.init_from_file('SerialServerHF511', '2')
     modbus_task = await wait_run_device(modbus_device)
     self.config['/oic/con']['master']['anchor'] = modbus_device.link[
         'anchor']
     self.config['/oic/con']['master']['eps'] = modbus_device.link['eps']
     self.device = Device.init_from_config(self.config,
                                           path=self.config_path)
     device_task = await wait_run_device(self.device)
     await self.power(True)
     await self.power(False)
 async def test_is_device(self):
     brightness = 60
     modbus_device = ModbusDevice.init_from_config(self.modbus_config,
                                                   path=self.config_path)
     mobus_task = await wait_run_device(modbus_device)
     self.config['/oic/con']['master'] = modbus_device.link
     self.device = Device.init_from_config(self.config,
                                           path=self.config_path)
     device_task = await wait_run_device(self.device)
     res = await self.device.modbus.is_device()
     self.assertTrue(res)
     pass
 async def test_update_switch(self):
     value = False
     modbus_device = ModbusDevice.init_from_config(self.modbus_config,
                                                   path=self.config_path)
     modbus_task = await wait_run_device(modbus_device)
     self.config['/oic/con']['master'] = modbus_device.link
     self.device = Device.init_from_config(self.config,
                                           path=self.config_path)
     device_task = await wait_run_device(self.device)
     message = OcfRequest(op='update',
                          to=dict(href='/power'),
                          cn=dict(value=value))
     result = await self.device.on_post_request(message)
     self.assertEqual(result['value'], value)
     modbus_task.cancel()
     device_task.cancel()
     pass
 async def test_update_brightness(self):
     brightness = 0
     modbus_device = ModbusDevice.init_from_config(self.modbus_config,
                                                   path=self.config_path)
     modbus_task = await wait_run_device(modbus_device)
     self.config['/oic/con']['master'] = modbus_device.link
     self.device = Device.init_from_config(self.config,
                                           path=self.config_path)
     device_task = await wait_run_device(self.device)
     message = OcfRequest(op='update',
                          to=dict(href='/brightness'),
                          cn=dict(brightness=brightness))
     result = await self.device.on_post_request(message)
     self.assertEqual(result['brightness'], brightness)
     modbus_task.cancel()
     device_task.cancel()
     pass
    async def test_retrieve_color(self):
        modbus_device = ModbusDevice.init_from_config(self.modbus_config,
                                                      path=self.config_path)
        modbus_task = await wait_run_device(modbus_device)
        self.config['/oic/con']['master'] = modbus_device.link
        self.device = Device.init_from_config(self.config,
                                              path=self.config_path)
        device_task = await wait_run_device(self.device)
        message = OcfRequest(op='retrieve', to=dict(href='/color'))
        result = await self.device.on_get_request(message)
        print(result)
        # self.assertEqual(result['color'], value)
        modbus_task.cancel()
        device_task.cancel()
        await modbus_task
        await device_task

        pass
 def test_get_light1_baseline(self):
     self.device = Device.init_from_config(
         None, dict(handler=Device.__name__, data=self.config))
     message = OcfRequest(**dict(operation='get', uri='/light'))
     result = self.device.on_get_request(message)
     pass