<s> """<STR_LIT>""" <EOL> import unittest <EOL> from homeassistant . bootstrap import _setup_component <EOL> import homeassistant . components . automation as automation <EOL> from tests . common import ( <EOL> mock_mqtt_component , fire_mqtt_message , get_test_home_assistant ) <EOL> class TestAutomationMQTT ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass = get_test_home_assistant ( ) <EOL> self . hass . config . components . append ( '<STR_LIT>' ) <EOL> mock_mqtt_component ( self . hass ) <EOL> self . calls = [ ] <EOL> def record_call ( service ) : <EOL> self . calls . append ( service ) <EOL> self . hass . services . register ( '<STR_LIT:test>' , '<STR_LIT>' , record_call ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . stop ( ) <EOL> def test_if_fires_on_topic_match ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> } , <EOL> } <EOL> } <EOL> } ) <EOL> fire_mqtt_message ( self . hass , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> self . assertEqual ( '<STR_LIT>' , <EOL> self . calls [ <NUM_LIT:0> ] . data [ '<STR_LIT>' ] ) <EOL> def test_if_fires_on_topic_and_payload_match ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:hello>' <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> fire_mqtt_message ( self . hass , '<STR_LIT>' , '<STR_LIT:hello>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . calls ) ) <EOL> def test_if_not_fires_on_topic_but_no_payload_match ( self ) : <EOL> """<STR_LIT>""" <EOL> assert _setup_component ( self . hass , automation . DOMAIN , { <EOL> automation . DOMAIN : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:hello>' <EOL> } , <EOL> '<STR_LIT:action>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } ) <EOL> fire_mqtt_message ( self . hass , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . hass . pool . block_till_done ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( self . calls ) ) </s>
