def test_down_signal_without_up_signal_within_threshold_should_dim_down_when_dimmed_up_before( self): """ When receiving a button down *not* followed by a button up signal within the first 600 milliseconds, should start dimming down when previously has been dimmed up. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) # Simulate the scheduled call: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) sut.button_up(timestamp=timeButtonDown + timedelta(milliseconds=700)) ctrl.reset_mock() sched.reset_mock() sut.button_down(timestamp=timeButtonDown + timedelta(seconds=4)) # Simulate the scheduled call: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) print(ctrl.start_dim.method_calls) ctrl.start_dim.assert_called_once_with(DimmerHandler.DIM_DOWN)
def create_handler(conf, scheduler, services): if conf != None: if conf['type'] == 'Dimmer': dpDim = [fun['dataPoints']['Shift'] for fun in conf['functions']] dpOnOff = [fun['dataPoints']['OnOff'] for fun in conf['functions']] return DimmerHandler( GiraDimmerController(services['gira'], dpDim, dpOnOff), scheduler) elif conf['type'] == "Scene": dpScene = [fun['dataPoints']['Scene'] for fun in conf['functions']] if "offAction" in conf: offActionDPs = [ value for (key, value) in conf['offAction']['dataPoints'].items() ] else: offActionDPs = None return SceneHandler( GiraValueController(services['gira'], dpScene, offActionDPs), conf['parameters']['Scene']) elif conf['type'] == 'Switch': dpOnOff = [fun['dataPoints']['OnOff'] for fun in conf['functions']] return SwitchHandler( GiraSwitchController(services['gira'], dpOnOff)) else: return None else: return None
def test_down_signal_without_up_signal_within_threshold_should_start_dim_up( self): """ When receiving a button down *not* followed by a button up signal within the first 600 milliseconds, should start dimming up. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) # Simulate the scheduled call: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) ctrl.start_dim.assert_called_once_with(DimmerHandler.DIM_UP)
def test_should_cancel_dimming_after_timeout(self): """ When not receiving a button up signal within timeout when dimming, should cancel dimming to prevent endless dimming disturbing other attempts to control the light. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) # Simulate the scheduled call to start dimming and cancel dimming: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) sched.call_at.call_args[0][1]() ctrl.start_dim.assert_called_once() ctrl.stop_dim.assert_called_once()
def test_short_press_should_toggle(self): """ When receiving a button down followed by a button up signal in under 600 milliseconds, should send a toggle signal. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) sut.button_up(timestamp=timeButtonDown + timedelta(milliseconds=400)) ctrl.toggle.assert_called_once()
def test_up_signal_while_dimming_should_stop_dimming(self): """ When currently dimming up or down, should stop dimming when button up signal has been received. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) # Simulate the scheduled call to start dimming: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) sut.button_up(timestamp=timeButtonDown + timedelta(milliseconds=700)) ctrl.start_dim.assert_called_once() ctrl.stop_dim.assert_called_once()
def test_long_press_should_start_dim_and_stop_dim_and_not_toggle(self): """ When receiving a button down followed by a button up signal in *more* than 600 milliseconds, should *not* send a toggle signal. """ ctrl = Mock() sched = Mock() sut = DimmerHandler(ctrl, sched) timeButtonDown = datetime.now() sut.button_down(timestamp=timeButtonDown) sut.button_up(timestamp=timeButtonDown + timedelta(milliseconds=700)) # Simulate the scheduled call: sched.call_at.call_args[0][1](sched.call_at.call_args[0][2], sched.call_at.call_args[0][3]) ctrl.toggle.assert_not_called() ctrl.start_dim.assert_called_once() ctrl.stop_dim.assert_called_once()