Пример #1
0
    def __init__(self, client_name):
        self.host = ''
        self.port = 12345
        self.client_name = client_name

        self._log = logging.getLogger('my_perfect_project')
        self._log.setLevel(logging.DEBUG)
        fh = logging.FileHandler('my_perfect_project.log')
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s :: '+self.client_name+' :: %(levelname)s :: %(funcName)s(%(lineno)d) :: %(message)s')
        fh.setFormatter(formatter)
        self._log.addHandler(fh)
        self._log.info('Started')

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect((self.host, self.port))

        self.mqtt_topic = mqtt_topic_ifd()

        self.mqtt_topic.simulation.connected.publish(self.client_name)

        self.calback_dictonary = dict()

        self.subscribe_with_method_name = True
Пример #2
0
def test_mqtt_topic():
    ifd = mqtt_topic_ifd()
    assert ifd.simulation.idle == "simulation/idle"

    assert ifd.environment.date_time == "environment/date_time"

    assert ifd.environment.date_time == ifd.environment.date_time
    assert ifd.environment.date_time != ifd.simulation.idle
Пример #3
0
def test_mqtt_topic_publish():
    ifd = mqtt_topic_ifd()
    ifd.simulation.idle.publish("Kalle")

    ifd.simulation.verbose.publish()

    message_to_send = ifd.get_message_to_send()
    assert 2 == len(message_to_send)
    assert message_to_send[0] == "021simulation/idle:Kalle"

    assert message_to_send[1] == "019simulation/verbose:"
Пример #4
0
def test_mqtt_topic_subscribe():
    ifd = mqtt_topic_ifd()
    ifd.simulation.idle.subscribe()

    message_to_send = ifd.get_message_to_send()
    assert 1 == len(message_to_send)
    assert message_to_send[0] == "025subscribe:simulation/idle"

    ifd.simulation.started.subscribe()
    assert 2 == len(message_to_send)
    assert message_to_send[1] == "028subscribe:simulation/started"
Пример #5
0
def test_mqtt_topic_publish_date_time():
    NYC = tz.gettz('Europe/Stockholm')
    ifd = mqtt_topic_ifd()
    t = datetime(2019, 9, 23, 18,
                 22, 23, 34, tzinfo=NYC)
    ifd.environment.date_time.publish(t)
    message_to_send = ifd.get_message_to_send()
    assert message_to_send[0] == "048environment/date_time:2019-09-23 18:22:23.000034"

    topic = ifd.get_message("environment/date_time")

    topic.payload = "2019-09-23 18:22:23.000034"
Пример #6
0
def test_mqtt_topic_publish_bool():
    ifd = mqtt_topic_ifd()
    topic = ifd.get_message("simulation/started")

    topic.payload = "True"

    data = topic.get_status()
    assert data == True

    topic.payload = "False"

    data = topic.get_status()
    assert data == False
Пример #7
0
def test_daylight_model():
    client = sensor_daylight()
    mqtt_topic = mqtt_topic_ifd()

    mqtt_topic.environment.date_time.set_time(
        string_to_time("2020-03-07 08:00:00.000000"))
Пример #8
0
def test_mqtt_topic_enumerate_all():
    ifd = mqtt_topic_ifd()
    for name in ifd.message_dictonary:
        print("name = {}".format(name.replace("/", "_")))
        ifd.message_dictonary[name].subscribe()