'Test event listener.'

@MockDependency('datadog')
def test_logbook_entry(self, mock_datadog):

    self.hass.bus.listen = mock.MagicMock()
    mock_client = mock_datadog.statsd
    assert setup_component(self.hass, datadog.DOMAIN, {datadog.DOMAIN: {'host': 'host', 'rate': datadog.DEFAULT_RATE}})
    self.assertTrue(self.hass.bus.listen.called)
    handler_method = self.hass.bus.listen.call_args_list[0][0][1]
    event = {'domain': 'automation', 'entity_id': 'sensor.foo.bar', 'message': 'foo    bar    biz', 'name': 'triggered    something'}
    handler_method(mock.MagicMock(data=event))
    self.assertEqual(mock_client.event.call_count, 1)
    self.assertEqual(mock_client.event.call_args, mock.call(title='Home    Assistant', text='%%%    \n    **{}**    {}    \n    %%%'.format(event['name'], event['message']), tags=['entity:sensor.foo.bar', 'domain:automation']))
    mock_client.event.reset_mock()
