Exemple #1
0
def smarthepia():

    # Class
    c_alarm = alarm.Alarm()
    c_automation = automation.Automation()
    c_measure = measure.Sensor()
    c_status = status_notifier.Status()

    # Process
    p_alarm = multiprocessing.Process(target=c_alarm.run)
    p_alarm.start()
    p_automation = multiprocessing.Process(target=c_automation.run)
    p_automation.start()
    p_measure = multiprocessing.Process(target=c_measure.run)
    p_measure.start()

    # Ensure all process have started
    time.sleep(1)
    p_status = multiprocessing.Process(target=c_status.run)
    p_status.start()

    # End process (or not)
    p_alarm.join()
    p_automation.join()
    p_measure.join()
    p_status.join()
    def test_invalid_json(self):
        """Invalid JSON/schema testcases."""

        with pytest.raises(json.decoder.JSONDecodeError):
            assert automation.Automation("x")

        with pytest.raises(jsonschema.exceptions.ValidationError):
            assert automation.Automation("{}")

        names = [
            "automation_invalid_rule_key.json",
            "automation_invalid_action_name.json",
            "automation_invalid_action_args.json",
        ]
        for name in names:
            with pytest.raises(jsonschema.exceptions.ValidationError):
                assert automation.Automation(
                    TestAutomation.get_json_path(name))
    def test_rules(self):
        expected_actions = [["button", 2, True], ["button", 2, False],
                            ["setbool", "seen", True], ["exit"]]
        regexp_actions = [["exit"]]
        default_actions = [["setbool", "default_match", True]]

        auto = automation.Automation(
            TestAutomation.get_json_path("automation_valid.json"))
        assert auto.get_actions(b"Application", 0, 0) == default_actions
        assert auto.get_actions(b"Application", 35, 3) == expected_actions

        auto.set_bool("seen", True)
        assert auto.get_actions(b"Application", 35, 3) == default_actions

        auto.set_bool("seen", False)
        assert auto.get_actions(b"Application", 35, 3) == expected_actions

        assert auto.get_actions(b"1234", 35, 3) == regexp_actions
Exemple #4
0
import logging
from datetime import datetime
import sys
import automation

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG,
                        filename=f"logfiles/log-{datetime.now().timestamp()}",
                        filemode="a+",
                        format="%(asctime)-15s %(levelname)-8s %(message)s")
    logging.debug('Program Started')
    if len(sys.argv) > 1:
        if sys.argv[1] == 'reset':
            logging.debug('removing last update')
            automation.delete_last_comment_remove_tag()
        elif sys.argv[1] == 'review':
            logging.debug('review comments')
            automation.review_comments()
    else:
        logging.debug('running automation process')
        automation.Automation().start()
    logging.debug('Program Finished')
    def test_valid_json(self):
        """Valid JSON complying with the schema."""

        auto = automation.Automation('{"version": 1, "rules": []}')
        auto = automation.Automation(
            TestAutomation.get_json_path("automation_valid.json"))