def test_execute_action_callback(self): """Test if execute method of ActionCallback calls correct callback method.""" xknx = XKNX(loop=self.loop) callback = Mock() async def async_callback(): """Async callback.""" callback() action = ActionCallback(xknx, async_callback) self.loop.run_until_complete(asyncio.Task(action.execute())) callback.assert_called_with()
def __init__(self, hass, device, hook, action, counter=1): """Initialize Automation class.""" self.hass = hass self.device = device script_name = "{} turn ON script".format(device.get_name()) self.script = Script(hass, action, script_name) self.action = ActionCallback( hass.data[DATA_KNX].xknx, self.script.async_run, hook=hook, counter=counter ) device.actions.append(self.action)
def test_action_callback(self): """Test string representation of action callback.""" xknx = XKNX(loop=self.loop) def cb(): # noqa: D401 """Callback.""" action = ActionCallback(xknx, callback=cb, hook="on", counter=2) self.assertEqual( str(action), '<ActionCallback callback="cb" <ActionBase hook="on" counter="2"/>/>' )