<s> """<STR_LIT>""" <EOL> import unittest <EOL> from homeassistant . bootstrap import _setup_component <EOL> from homeassistant . const import ( <EOL> STATE_ALARM_DISARMED , STATE_ALARM_ARMED_HOME , STATE_ALARM_ARMED_AWAY , <EOL> STATE_ALARM_PENDING , STATE_ALARM_TRIGGERED , STATE_UNKNOWN ) <EOL> from homeassistant . components import alarm_control_panel <EOL> from tests . common import ( <EOL> mock_mqtt_component , fire_mqtt_message , get_test_home_assistant ) <EOL> CODE = '<STR_LIT>' <EOL> class TestAlarmControlPanelMQTT ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass = get_test_home_assistant ( ) <EOL> self . mock_publish = mock_mqtt_component ( self . hass ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . stop ( ) <EOL> def test_fail_setup_without_state_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert not _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> def test_fail_setup_without_command_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert not _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> def test_update_state_via_state_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> entity_id = '<STR_LIT>' <EOL> self . assertEqual ( STATE_UNKNOWN , <EOL> self . hass . states . get ( entity_id ) . state ) <EOL> for state in ( STATE_ALARM_DISARMED , STATE_ALARM_ARMED_HOME , <EOL> STATE_ALARM_ARMED_AWAY , STATE_ALARM_PENDING , <EOL> STATE_ALARM_TRIGGERED ) : <EOL> fire_mqtt_message ( self . hass , '<STR_LIT>' , state ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( state , self . hass . states . get ( entity_id ) . state ) <EOL> def test_ignore_update_state_if_unknown_via_state_topic ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> entity_id = '<STR_LIT>' <EOL> self . assertEqual ( STATE_UNKNOWN , <EOL> self . hass . states . get ( entity_id ) . state ) <EOL> fire_mqtt_message ( self . hass , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( STATE_UNKNOWN , self . hass . states . get ( entity_id ) . state ) <EOL> def test_arm_home_publishes_mqtt ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> alarm_control_panel . alarm_arm_home ( self . hass ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , False ) , <EOL> self . mock_publish . mock_calls [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> def test_arm_home_not_publishes_mqtt_with_invalid_code ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> call_count = self . mock_publish . call_count <EOL> alarm_control_panel . alarm_arm_home ( self . hass , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( call_count , self . mock_publish . call_count ) <EOL> def test_arm_away_publishes_mqtt ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> alarm_control_panel . alarm_arm_away ( self . hass ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , False ) , <EOL> self . mock_publish . mock_calls [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> def test_arm_away_not_publishes_mqtt_with_invalid_code ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> call_count = self . mock_publish . call_count <EOL> alarm_control_panel . alarm_arm_away ( self . hass , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( call_count , self . mock_publish . call_count ) <EOL> def test_disarm_publishes_mqtt ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ) <EOL> alarm_control_panel . alarm_disarm ( self . hass ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , False ) , <EOL> self . mock_publish . mock_calls [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> def test_disarm_not_publishes_mqtt_with_invalid_code ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . config . components = [ '<STR_LIT>' ] <EOL> assert _setup_component ( self . hass , alarm_control_panel . DOMAIN , { <EOL> alarm_control_panel . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> call_count = self . mock_publish . call_count <EOL> alarm_control_panel . alarm_disarm ( self . hass , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( call_count , self . mock_publish . call_count ) </s>
