def test_activate_scene(self): """Test active scene.""" assert setup_component( self.hass, scene.DOMAIN, { "scene": [{ "name": "test", "entities": { self.light_1.entity_id: "on", self.light_2.entity_id: { "state": "on", "brightness": 100 }, }, }] }, ) common.activate(self.hass, "scene.test") self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call("turn_on")[1].get("brightness")
def test_config_yaml_alias_anchor(self): """Test the usage of YAML aliases and anchors. The following test scene configuration is equivalent to: scene: - name: test entities: light_1: &light_1_state state: 'on' brightness: 100 light_2: *light_1_state When encountering a YAML alias/anchor, the PyYAML parser will use a reference to the original dictionary, instead of creating a copy, so care needs to be taken to not modify the original. """ entity_state = {"state": "on", "brightness": 100} assert setup_component( self.hass, scene.DOMAIN, { "scene": [ { "name": "test", "entities": { self.light_1.entity_id: entity_state, self.light_2.entity_id: entity_state, }, } ] }, ) self.hass.block_till_done() common.activate(self.hass, "scene.test") self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_1.last_call("turn_on")[1].get("brightness") assert 100 == self.light_2.last_call("turn_on")[1].get("brightness")
def test_config_yaml_bool(self): """Test parsing of booleans in yaml config.""" config = ("scene:\n" " - name: test\n" " entities:\n" f" {self.light_1.entity_id}: on\n" f" {self.light_2.entity_id}:\n" " state: on\n" " brightness: 100\n") with io.StringIO(config) as file: doc = yaml_loader.yaml.safe_load(file) assert setup_component(self.hass, scene.DOMAIN, doc) common.activate(self.hass, "scene.test") self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call("turn_on")[1].get("brightness")
def test_config_yaml_bool(self): """Test parsing of booleans in yaml config.""" config = ('scene:\n' ' - name: test\n' ' entities:\n' ' {0}: on\n' ' {1}:\n' ' state: on\n' ' brightness: 100\n').format(self.light_1.entity_id, self.light_2.entity_id) with io.StringIO(config) as file: doc = yaml_loader.yaml.load(file) assert setup_component(self.hass, scene.DOMAIN, doc) common.activate(self.hass, 'scene.test') self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
def test_activate_scene(self): """Test active scene.""" assert setup_component(self.hass, scene.DOMAIN, { 'scene': [{ 'name': 'test', 'entities': { self.light_1.entity_id: 'on', self.light_2.entity_id: { 'state': 'on', 'brightness': 100, } } }] }) common.activate(self.hass, 'scene.test') self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
def test_config_yaml_alias_anchor(self): """Test the usage of YAML aliases and anchors. The following test scene configuration is equivalent to: scene: - name: test entities: light_1: &light_1_state state: 'on' brightness: 100 light_2: *light_1_state When encountering a YAML alias/anchor, the PyYAML parser will use a reference to the original dictionary, instead of creating a copy, so care needs to be taken to not modify the original. """ entity_state = { 'state': 'on', 'brightness': 100, } self.assertTrue(setup_component(self.hass, scene.DOMAIN, { 'scene': [{ 'name': 'test', 'entities': { self.light_1.entity_id: entity_state, self.light_2.entity_id: entity_state, } }] })) common.activate(self.hass, 'scene.test') self.hass.block_till_done() self.assertTrue(self.light_1.is_on) self.assertTrue(self.light_2.is_on) self.assertEqual( 100, self.light_1.last_call('turn_on')[1].get('brightness')) self.assertEqual( 100, self.light_2.last_call('turn_on')[1].get('brightness'))
def test_activate_scene(self): """Test active scene.""" assert setup_component( self.hass, scene.DOMAIN, { "scene": [{ "name": "test", "entities": { self.light_1.entity_id: "on", self.light_2.entity_id: { "state": "on", "brightness": 100 }, }, }] }, ) self.hass.block_till_done() common.activate(self.hass, "scene.test") self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert self.light_2.last_call("turn_on")[1].get("brightness") == 100 turn_on_calls = mock_service(self.hass, "light", "turn_on") self.hass.services.call(scene.DOMAIN, "turn_on", { "transition": 42, "entity_id": "scene.test" }) self.hass.block_till_done() assert len(turn_on_calls) == 1 assert turn_on_calls[0].domain == "light" assert turn_on_calls[0].service == "turn_on" assert turn_on_calls[0].data.get("transition") == 42
def test_activate_scene(self): """Test active scene.""" assert setup_component( self.hass, scene.DOMAIN, { 'scene': [{ 'name': 'test', 'entities': { self.light_1.entity_id: 'on', self.light_2.entity_id: { 'state': 'on', 'brightness': 100, } } }] }) common.activate(self.hass, 'scene.test') self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
def test_config_yaml_bool(self): """Test parsing of booleans in yaml config.""" config = ( 'scene:\n' ' - name: test\n' ' entities:\n' ' {0}: on\n' ' {1}:\n' ' state: on\n' ' brightness: 100\n').format( self.light_1.entity_id, self.light_2.entity_id) with io.StringIO(config) as file: doc = yaml.yaml.safe_load(file) assert setup_component(self.hass, scene.DOMAIN, doc) common.activate(self.hass, 'scene.test') self.hass.block_till_done() assert self.light_1.is_on assert self.light_2.is_on assert 100 == self.light_2.last_call('turn_on')[1].get('brightness')
def test_activate(self): """Test activating the scene.""" common.activate(self.hass, ENTITY_SCENE) self.hass.block_till_done() self.mock_lj.activate_scene.assert_called_once_with( ENTITY_SCENE_NUMBER)
def test_activate(self): """Test activating the scene.""" common.activate(self.hass, ENTITY_SCENE) self.hass.block_till_done() self.mock_lj.activate_scene.assert_called_once_with( ENTITY_SCENE_NUMBER)