def tilt(self, direction: str, time: float) -> bool:
     self.time = time
     self.direction = direction
     self.tilt_counter = self.tilt_counter + 1
     self.position = 2
     self.blindstate = BlindState(self.position,
                                  Direction.from_name(direction))
     return True
 def move(self, pos: int) -> bool:
     self.move_counter = self.move_counter + 1
     if pos < self.position:
         self.blindstate = BlindState(pos, Direction.CLOSE)
     else:
         self.blindstate = BlindState(pos, Direction.OPEN)
     self.position = pos
     return True
class DeviceMock(Device):
    def __init__(self, name: str):
        self.name: str = name
        self.blindstate: Optional[BlindState] = None
        self.state = State.UNKNOWN
        self.time: float = -1
        self.direction: str = '­Ъци'
        self.position: int = 100
        self.close_counter: int = 0
        self.open_counter: int = 0
        self.move_counter: int = 0
        self.tilt_counter: int = 0

    def close(self) -> bool:
        self.close_counter = self.close_counter + 1
        self.position = 0
        self.blindstate = BlindState(self.position, Direction.CLOSE)
        return True

    def open(self) -> bool:
        self.open_counter = self.open_counter + 1
        self.position = 100
        self.blindstate = BlindState(self.position, Direction.OPEN)
        return True

    def move(self, pos: int) -> bool:
        self.move_counter = self.move_counter + 1
        if pos < self.position:
            self.blindstate = BlindState(pos, Direction.CLOSE)
        else:
            self.blindstate = BlindState(pos, Direction.OPEN)
        self.position = pos
        return True

    def tilt(self, direction: str, time: float) -> bool:
        self.time = time
        self.direction = direction
        self.tilt_counter = self.tilt_counter + 1
        self.position = 2
        self.blindstate = BlindState(self.position,
                                     Direction.from_name(direction))
        return True

    def stats(self) -> State:
        if self.blindstate:
            self.state = self.blindstate.state()
        return self.state

    def id(self) -> str:
        return self.name

    def __repr__(self):
        return 'DeviceMock: {name: %s, close: %s, open: %s, move: %s, tilt: %s}' % \
               (self.name, self.close_counter, self.open_counter, self.move_counter, self.tilt_counter)
 def open(self) -> bool:
     self.open_counter = self.open_counter + 1
     self.position = 100
     self.blindstate = BlindState(self.position, Direction.OPEN)
     return True
 def test_closed_state(self):
     state = BlindState(0, Direction.CLOSE)
     self.assertEqual(State.CLOSED, state.state())
 def close(self) -> bool:
     self.close_counter = self.close_counter + 1
     self.position = 0
     self.blindstate = BlindState(self.position, Direction.CLOSE)
     return True
 def test_tilt_open_str(self):
     state = BlindState(4, Direction.OPEN.value)
     self.assertEqual(State.TILT, state.state())
 def test_json(self):
     json = get_json()
     state = BlindState(json.get('current_pos'), json.get('last_direction'))
     self.assertEqual(State.CLOSED, state.state())
 def test_tilt_close_str(self):
     state = BlindState(1, Direction.CLOSE.value)
     self.assertEqual(State.TILT, state.state())
 def test_moved_zero_open_State(self):
     state = BlindState(0, Direction.OPEN)
     self.assertEqual(State.MOVED, state.state())
 def test_moved_min_close_state(self):
     state = BlindState(5, Direction.CLOSE)
     self.assertEqual(State.MOVED, state.state())
 def test_moved_min_open_state(self):
     state = BlindState(5, Direction.OPEN)
     self.assertEqual(State.MOVED, state.state())
 def test_open_min_state(self):
     state = BlindState(96, Direction.OPEN)
     self.assertEqual(State.OPEN, state.state())