# Path: test/mock_device/mock_data.py
# def generate():
# 
# Path: test/mock_device/iec104device.py
# class IEC104Device:
#     def __init__(self, device, reader, writer):
#     async def receive(self):
#     def connection_lost(self):
#     def inc_ssn(self):
#     def inc_rsn(self):
#     def start_timer(self, timer_id):
#     def stop_timer(self, timer_id):
#     def on_timer0(self):
#     def on_timer1(self):
#     def on_timer2(self):
#     def on_timer3(self):
#     async def handle_u(self, frame):
#     async def handle_i(self, frame):
#     async def send_frame(self, frame, check=True):
#     async def check_to_send(self, frame):
#     def save_frame(self, frame, send=True):
#     async def generate_call_all_data(self):
#     def generate_call_power_data(self):
# def create_servers(io_loop):
# def run_server():
# 
# Path: pydatacoll/api_server.py
# HANDLER_TIME_OUT = config.getint('SERVER', 'web_timeout', fallback=10)
# class APIServer(ParamFunctionContainer):
#     def __init__(self, port: int = None, production: bool = None, io_loop: asyncio.AbstractEventLoop = None):
#     def _add_router(self):
#     def _install_plugins(self):
#     def _uninstall_plugins(self):
#     def stop_server(self):
#     def found_and_delete(self, match: str):
#     async def _read_data(request):
#     async def get_index(self, request):
#     async def get_redis_key(self, _):
#     async def get_device_protocol_list(self, _):
#     async def get_term_protocol_list(self, _):
#     async def get_formula_list(self, _):
#     async def get_formula(self, request):
#     async def get_device_list(self, _):
#     async def get_device(self, request):
#     async def get_term_list(self, _):
#     async def get_term(self, request):
#     async def get_item_list(self, _):
#     async def get_item(self, request):
#     async def get_device_term_list(self, request):
#     async def get_term_item_list(self, request):
#     async def get_term_item(self, request):
#     async def get_data_list(self, request):
#     async def get_data(self, request):
#     async def create_formula(self, request):
#     async def create_formula_batch(self, request):
#     async def update_formula(self, request):
#     async def del_formula(self, request):
#     async def del_formula_batch(self, request):
#     async def create_device(self, request):
#     async def create_device_batch(self, request):
#     async def update_device(self, request):
#     async def del_device(self, request):
#     async def del_device_batch(self, request):
#     async def create_term(self, request):
#     async def create_term_batch(self, request):
#     async def update_term(self, request):
#     async def del_term(self, request):
#     async def del_term_batch(self, request):
#     async def create_item(self, request):
#     async def create_item_batch(self, request):
#     async def update_item(self, request):
#     async def del_item(self, request):
#     async def del_item_batch(self, request):
#     async def create_term_item(self, request):
#     async def create_term_item_batch(self, request):
#     async def update_term_item(self, request):
#     async def del_term_item(self, request):
#     async def del_term_item_batch(self, request):
#     async def device_call(self, request):
#             async def reader(ch):
#     async def device_ctrl(self, request):
#             async def reader(ch):
#     async def formula_check(self, request):
#             async def reader(ch):
#     async def sql_check(self, request):
#             async def reader(ch):
# def main():


import asyncio
import aiohttp
import aioredis
import asynctest
import redis
    import ujson as json
    import json
import pydatacoll.utils.logger as my_logger
from pydatacoll.resources.protocol import *
from pydatacoll.resources.redis_key import *
from test.mock_device import mock_data, iec104device
from pydatacoll import api_server
from pydatacoll.utils.read_config import *
                                                  config.getint('REDIS', 'port', fallback=6379)),
                                                 db=config.getint('REDIS', 'db', fallback=1))
        res = await sub_client.subscribe('channel:foo')
        ch1 = res[0]

        async def reader(ch):
            while await ch.wait_message():
                msg = await ch.get_json()
                logger.debug("channel[%s] Got Message:%s", ch.name.decode(), msg)
            logger.debug('quit reader!')

        tsk = asyncio.ensure_future(reader(ch1))

        res = await pub_client.publish_json('channel:foo', ["Hello", "world"])
        self.assertEqual(res, 1)

        await sub_client.unsubscribe('channel:foo')
        await tsk
        sub_client.close()
        pub_client.close()


class InterfaceTest(asynctest.TestCase):
    loop = None  # make pycharm happy

    def setUp(self):
        self.redis_client = redis.StrictRedis(db=1, decode_responses=True)
        mock_data.generate()
        self.server_list = list()
        self.server_list = iec104device.create_servers(self.loop)

# Path: test/mock_device/mock_data.py
# def generate():
# 
# Path: test/mock_device/iec104device.py
# class IEC104Device:
#     def __init__(self, device, reader, writer):
#     async def receive(self):
#     def connection_lost(self):
#     def inc_ssn(self):
#     def inc_rsn(self):
#     def start_timer(self, timer_id):
#     def stop_timer(self, timer_id):
#     def on_timer0(self):
#     def on_timer1(self):
#     def on_timer2(self):
#     def on_timer3(self):
#     async def handle_u(self, frame):
#     async def handle_i(self, frame):
#     async def send_frame(self, frame, check=True):
#     async def check_to_send(self, frame):
#     def save_frame(self, frame, send=True):
#     async def generate_call_all_data(self):
#     def generate_call_power_data(self):
# def create_servers(io_loop):
# def run_server():
# 
# Path: pydatacoll/api_server.py
# HANDLER_TIME_OUT = config.getint('SERVER', 'web_timeout', fallback=10)
# class APIServer(ParamFunctionContainer):
#     def __init__(self, port: int = None, production: bool = None, io_loop: asyncio.AbstractEventLoop = None):
#     def _add_router(self):
#     def _install_plugins(self):
#     def _uninstall_plugins(self):
#     def stop_server(self):
#     def found_and_delete(self, match: str):
#     async def _read_data(request):
#     async def get_index(self, request):
#     async def get_redis_key(self, _):
#     async def get_device_protocol_list(self, _):
#     async def get_term_protocol_list(self, _):
#     async def get_formula_list(self, _):
#     async def get_formula(self, request):
#     async def get_device_list(self, _):
#     async def get_device(self, request):
#     async def get_term_list(self, _):
#     async def get_term(self, request):
#     async def get_item_list(self, _):
#     async def get_item(self, request):
#     async def get_device_term_list(self, request):
#     async def get_term_item_list(self, request):
#     async def get_term_item(self, request):
#     async def get_data_list(self, request):
#     async def get_data(self, request):
#     async def create_formula(self, request):
#     async def create_formula_batch(self, request):
#     async def update_formula(self, request):
#     async def del_formula(self, request):
#     async def del_formula_batch(self, request):
#     async def create_device(self, request):
#     async def create_device_batch(self, request):
#     async def update_device(self, request):
#     async def del_device(self, request):
#     async def del_device_batch(self, request):
#     async def create_term(self, request):
#     async def create_term_batch(self, request):
#     async def update_term(self, request):
#     async def del_term(self, request):
#     async def del_term_batch(self, request):
#     async def create_item(self, request):
#     async def create_item_batch(self, request):
#     async def update_item(self, request):
#     async def del_item(self, request):
#     async def del_item_batch(self, request):
#     async def create_term_item(self, request):
#     async def create_term_item_batch(self, request):
#     async def update_term_item(self, request):
#     async def del_term_item(self, request):
#     async def del_term_item_batch(self, request):
#     async def device_call(self, request):
#             async def reader(ch):
#     async def device_ctrl(self, request):
#             async def reader(ch):
#     async def formula_check(self, request):
#             async def reader(ch):
#     async def sql_check(self, request):
#             async def reader(ch):
# def main():


# Path: test/test_interface.py
import asyncio
import aiohttp
import aioredis
import asynctest
import redis
    import ujson as json
    import json
import pydatacoll.utils.logger as my_logger
from pydatacoll.resources.protocol import *
from pydatacoll.resources.redis_key import *
from test.mock_device import mock_data, iec104device
from pydatacoll import api_server
from pydatacoll.utils.read_config import *

                                                  config.getint('REDIS', 'port', fallback=6379)),
                                                 db=config.getint('REDIS', 'db', fallback=1))
        res = await sub_client.subscribe('channel:foo')
        ch1 = res[0]

        async def reader(ch):
            while await ch.wait_message():
                msg = await ch.get_json()
                logger.debug("channel[%s] Got Message:%s", ch.name.decode(), msg)
            logger.debug('quit reader!')

        tsk = asyncio.ensure_future(reader(ch1))

        res = await pub_client.publish_json('channel:foo', ["Hello", "world"])
        self.assertEqual(res, 1)

        await sub_client.unsubscribe('channel:foo')
        await tsk
        sub_client.close()
        pub_client.close()


class InterfaceTest(asynctest.TestCase):
    loop = None  # make pycharm happy

    def setUp(self):
        self.redis_client = redis.StrictRedis(db=1, decode_responses=True)
        mock_data.generate()
        self.server_list = list()
        self.server_list = iec104device.create_servers(self.loop)

        self.api_server = api_server.APIServer(io_loop=self.loop, port=8080)