# Path: backend/components/element.py
# class Element(BaseComponent):
# 
#     table_name = "elements"
#     COL_MODULE_ID, COL_REG,  = 3, 4,
#     column_headers_and_types = BaseComponent.column_headers_and_types + [['module_id', 'integer'], ['register', 'integer']]
# 
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(args[0], Et(args[1]), args[2])  # inicjalizuj id type, name
#         Element.items[self.id] = self        
#         self.value = None
#         self.module_id = args[Element.COL_MODULE_ID]
#         self.reg_id = args[Element.COL_REG]
#         self.objects_to_notify = set()
#         self.new_val_flag = False
# 
#     def subscribe(self, who):
#         self.objects_to_notify.add(who)
# 
#     def notify_objects(self, ):
#         for _object in self.objects_to_notify:
#             _object.notify(self.value)
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tvalue: ", str(self.value)])
# 
# class OutputElement(Element):
#  
#     types = {Et.led, Et.heater, Et.ventilator, Et.blind}
# 
#     defualt_priority = 15
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args)
#         OutputElement.items[self.id] = self
#         self.desired_value = 0
#         self.setter_priority = OutputElement.defualt_priority  # Default priority can be overriden by everybody
# 
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if priority <= self.setter_priority:
#             self.desired_value = value
# 
#             if set_flag:
#                 self.setter_priority = priority
#             else: 
#                 self.setter_priority = self.defualt_priority
# 
#             return True
# 
#         else:
#             return False
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tdesired_value: ", str(self.desired_value)])
# 
#     @staticmethod
#     def str():
#         string = "\n"
#         for element in OutputElement.items.values():
#             el_str = str(element) 
#             string += el_str + "\n"
# 
#         return string
# 
# class Blind(OutputElement):
#     table_name = "blinds"
#     column_headers_and_types = Element.column_headers_and_types + [['direction', 'text'], ['other_blind', 'integer']] 
# 
#     COL_DIRECTION, COL_OTHER_BLIND = 5, 6
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args[0:self.COL_DIRECTION])
#         Blind.items[self.id] = self
#         self.direction = args[self.COL_DIRECTION]
#         self.other_blind = args[self.COL_OTHER_BLIND]  # if blind is up then it is down and the other way around
#     
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if super().set_desired_value(value, priority, set_flag=False):
#             self.other_blind.desired_value = 0
# 
# Path: backend/components/tests/helper_classes.py
# class Notifiable:
# 
#     def __init__(self):
# 
#         self.val = None
# 
#     def notify(self, val):
# 
#         self.val = val


import unittest
from backend.components.element import Element, OutputElement, Blind
from backend.components.tests.helper_classes import Notifiable
        self.priority = 20

        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.desired_value, 0)

    def test_set_priority_when_set_flag_true(self):
        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.setter_priority, self.priority)

    def test_reset_setter_priority_when_set_flag_false(self):
        #given
        self.set_flag = False

        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.setter_priority, self.output_element.defualt_priority)

    def test_set_other_blind_desired_value_to_0(self):

        # given
        id, type, name, module_id, reg_id, = 0, 1, '', 0, 0
        blind_up = Blind(0, type, name, module_id, reg_id, 'up', None)

# Path: backend/components/element.py
# class Element(BaseComponent):
# 
#     table_name = "elements"
#     COL_MODULE_ID, COL_REG,  = 3, 4,
#     column_headers_and_types = BaseComponent.column_headers_and_types + [['module_id', 'integer'], ['register', 'integer']]
# 
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(args[0], Et(args[1]), args[2])  # inicjalizuj id type, name
#         Element.items[self.id] = self        
#         self.value = None
#         self.module_id = args[Element.COL_MODULE_ID]
#         self.reg_id = args[Element.COL_REG]
#         self.objects_to_notify = set()
#         self.new_val_flag = False
# 
#     def subscribe(self, who):
#         self.objects_to_notify.add(who)
# 
#     def notify_objects(self, ):
#         for _object in self.objects_to_notify:
#             _object.notify(self.value)
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tvalue: ", str(self.value)])
# 
# class OutputElement(Element):
#  
#     types = {Et.led, Et.heater, Et.ventilator, Et.blind}
# 
#     defualt_priority = 15
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args)
#         OutputElement.items[self.id] = self
#         self.desired_value = 0
#         self.setter_priority = OutputElement.defualt_priority  # Default priority can be overriden by everybody
# 
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if priority <= self.setter_priority:
#             self.desired_value = value
# 
#             if set_flag:
#                 self.setter_priority = priority
#             else: 
#                 self.setter_priority = self.defualt_priority
# 
#             return True
# 
#         else:
#             return False
# 
#     def __str__(self, ):
#         return "".join([super().__str__(), "\tdesired_value: ", str(self.desired_value)])
# 
#     @staticmethod
#     def str():
#         string = "\n"
#         for element in OutputElement.items.values():
#             el_str = str(element) 
#             string += el_str + "\n"
# 
#         return string
# 
# class Blind(OutputElement):
#     table_name = "blinds"
#     column_headers_and_types = Element.column_headers_and_types + [['direction', 'text'], ['other_blind', 'integer']] 
# 
#     COL_DIRECTION, COL_OTHER_BLIND = 5, 6
#     items = {}
# 
#     def __init__(self, *args):
#         super().__init__(*args[0:self.COL_DIRECTION])
#         Blind.items[self.id] = self
#         self.direction = args[self.COL_DIRECTION]
#         self.other_blind = args[self.COL_OTHER_BLIND]  # if blind is up then it is down and the other way around
#     
#     def set_desired_value(self, value, priority, set_flag=False):
# 
#         if super().set_desired_value(value, priority, set_flag=False):
#             self.other_blind.desired_value = 0
# 
# Path: backend/components/tests/helper_classes.py
# class Notifiable:
# 
#     def __init__(self):
# 
#         self.val = None
# 
#     def notify(self, val):
# 
#         self.val = val


# Path: backend/components/tests/test_element.py
import unittest
from backend.components.element import Element, OutputElement, Blind
from backend.components.tests.helper_classes import Notifiable

        self.priority = 20

        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.desired_value, 0)

    def test_set_priority_when_set_flag_true(self):
        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.setter_priority, self.priority)

    def test_reset_setter_priority_when_set_flag_false(self):
        #given
        self.set_flag = False

        # when
        self.output_element.set_desired_value(self.value, self.priority, self.set_flag)

        # then
        self.assertEqual(self.output_element.setter_priority, self.output_element.defualt_priority)

    def test_set_other_blind_desired_value_to_0(self):

        # given
        id, type, name, module_id, reg_id, = 0, 1, '', 0, 0
        blind_up = Blind(0, type, name, module_id, reg_id, 'up', None)

        blind_down = Blind(1, type, name, module_id, reg_id, 'down', blind_up)