'Test publishing of MQTT messages when state changes.'

def test_state_changes_are_published_to_mqtt(self):

    assert setup_component(self.hass, alarm_control_panel.DOMAIN, {alarm_control_panel.DOMAIN: {'platform': 'manual_mqtt', 'name': 'test', 'pending_time': 1, 'trigger_time': 1, 'state_topic': 'alarm/state', 'command_topic': 'alarm/command'}})
    self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_DISARMED, 0, True), self.mock_publish.mock_calls[(-2)][1])
    alarm_control_panel.alarm_arm_home(self.hass)
    self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_PENDING, 0, True), self.mock_publish.mock_calls[(-2)][1])
    future = (dt_util.utcnow() + timedelta(seconds=1))
    with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_ARMED_HOME, 0, True), self.mock_publish.mock_calls[(-2)][1])
    alarm_control_panel.alarm_arm_away(self.hass)
    self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_PENDING, 0, True), self.mock_publish.mock_calls[(-2)][1])
    future = (dt_util.utcnow() + timedelta(seconds=1))
    with patch('homeassistant.components.alarm_control_panel.manual_mqtt.dt_util.utcnow', return_value=future):
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_ARMED_AWAY, 0, True), self.mock_publish.mock_calls[(-2)][1])
    alarm_control_panel.alarm_disarm(self.hass)
    self.hass.block_till_done()
    self.assertEqual(('alarm/state', STATE_ALARM_DISARMED, 0, True), self.mock_publish.mock_calls[(-2)][1])
