def test_reload_config_when_invalid_config(self, mock_load_yaml): """Test the reload config service handling invalid config.""" assert _setup_component( self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.pool.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' automation.reload(self.hass) self.hass.pool.block_till_done() assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.pool.block_till_done() assert len(self.calls) == 2
def test_reload_config_when_invalid_config(self, mock_load_yaml): """Test the reload config service handling invalid config.""" with assert_setup_component(1): assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' automation.reload(self.hass) self.hass.block_till_done() assert self.hass.states.get('automation.hello') is None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1
def test_reload_config_handles_load_fails(self): """Test the reload config service.""" assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' with patch('homeassistant.config.load_yaml_config_file', side_effect=HomeAssistantError('bla')): automation.reload(self.hass) self.hass.block_till_done() assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 2
def test_reload_config_service(self, mock_load_yaml): """Test the reload config service.""" assert setup_component( self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None assert self.hass.states.get('automation.bye') is None listeners = self.hass.bus.listeners assert listeners.get('test_event') == 1 assert listeners.get('test_event2') is None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' automation.reload(self.hass) self.hass.block_till_done() # De-flake ?! self.hass.block_till_done() assert self.hass.states.get('automation.hello') is None assert self.hass.states.get('automation.bye') is not None listeners = self.hass.bus.listeners assert listeners.get('test_event') is None assert listeners.get('test_event2') == 1 self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 self.hass.bus.fire('test_event2') self.hass.block_till_done() assert len(self.calls) == 2 assert self.calls[1].data.get('event') == 'test_event2'
def test_reload_config_service(self, mock_load_yaml): """Test the reload config service.""" assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None assert self.hass.states.get('automation.bye') is None listeners = self.hass.bus.listeners assert listeners.get('test_event') == 1 assert listeners.get('test_event2') is None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' automation.reload(self.hass) self.hass.block_till_done() # De-flake ?! self.hass.block_till_done() assert self.hass.states.get('automation.hello') is None assert self.hass.states.get('automation.bye') is not None listeners = self.hass.bus.listeners assert listeners.get('test_event') is None assert listeners.get('test_event2') == 1 self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 self.hass.bus.fire('test_event2') self.hass.block_till_done() assert len(self.calls) == 2 assert self.calls[1].data.get('event') == 'test_event2'
def test_reload_config_when_invalid_config(self): """Test the reload config service handling invalid config.""" with assert_setup_component(1, automation.DOMAIN): assert setup_component( self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' with patch('homeassistant.config.load_yaml_config_file', autospec=True, return_value={automation.DOMAIN: 'not valid'}): with patch('homeassistant.config.find_config_file', return_value=''): automation.reload(self.hass) self.hass.block_till_done() assert self.hass.states.get('automation.hello') is None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1
def test_reload_config_when_invalid_config(self): """Test the reload config service handling invalid config.""" with assert_setup_component(1, automation.DOMAIN): assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', 'data_template': { 'event': '{{ trigger.event.event_type }}' } } } }) assert self.hass.states.get('automation.hello') is not None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 assert self.calls[0].data.get('event') == 'test_event' with patch('homeassistant.config.load_yaml_config_file', autospec=True, return_value={automation.DOMAIN: 'not valid'}): with patch('homeassistant.config.find_config_file', return_value=''): automation.reload(self.hass) self.hass.block_till_done() assert self.hass.states.get('automation.hello') is None self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1