def test_services(self): """Test the automation services for turning entities on/off.""" entity_id = 'automation.hello' assert self.hass.states.get(entity_id) is None assert not automation.is_on(self.hass, entity_id) assert _setup_component( self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', } } }) assert self.hass.states.get(entity_id) is not None assert automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.pool.block_till_done() assert len(self.calls) == 1 automation.turn_off(self.hass, entity_id) self.hass.pool.block_till_done() assert not automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.pool.block_till_done() assert len(self.calls) == 1 automation.toggle(self.hass, entity_id) self.hass.pool.block_till_done() assert automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.pool.block_till_done() assert len(self.calls) == 2 automation.trigger(self.hass, entity_id) self.hass.pool.block_till_done() assert len(self.calls) == 3 automation.turn_off(self.hass, entity_id) self.hass.pool.block_till_done() automation.trigger(self.hass, entity_id) self.hass.pool.block_till_done() assert len(self.calls) == 4 automation.turn_on(self.hass, entity_id) self.hass.pool.block_till_done() assert automation.is_on(self.hass, entity_id)
def test_services(self): """Test the automation services for turning entities on/off.""" entity_id = 'automation.hello' assert self.hass.states.get(entity_id) is None assert not automation.is_on(self.hass, entity_id) assert setup_component(self.hass, automation.DOMAIN, { automation.DOMAIN: { 'alias': 'hello', 'trigger': { 'platform': 'event', 'event_type': 'test_event', }, 'action': { 'service': 'test.automation', } } }) assert self.hass.states.get(entity_id) is not None assert automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 automation.turn_off(self.hass, entity_id) self.hass.block_till_done() assert not automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 1 automation.toggle(self.hass, entity_id) self.hass.block_till_done() assert automation.is_on(self.hass, entity_id) self.hass.bus.fire('test_event') self.hass.block_till_done() assert len(self.calls) == 2 automation.trigger(self.hass, entity_id) self.hass.block_till_done() assert len(self.calls) == 3 automation.turn_off(self.hass, entity_id) self.hass.block_till_done() automation.trigger(self.hass, entity_id) self.hass.block_till_done() assert len(self.calls) == 4 automation.turn_on(self.hass, entity_id) self.hass.block_till_done() assert automation.is_on(self.hass, entity_id)