Пример #1
0
 def _call_service(self, action, variables):
     """Call the service specified in the action."""
     self.last_action = action.get(CONF_ALIAS, 'call service')
     self._log("Executing step %s" % self.last_action)
     service.call_from_config(self.hass,
                              action,
                              True,
                              variables,
                              validate_config=False)
Пример #2
0
 def test_split_entity_string(self):
     """Test splitting of entity string."""
     service.call_from_config(self.hass, {
         'service': 'test_domain.test_service',
         'entity_id': 'hello.world, sensor.beer'
     })
     self.hass.pool.block_till_done()
     self.assertEqual(['hello.world', 'sensor.beer'],
                      self.calls[-1].data.get('entity_id'))
Пример #3
0
 def test_split_entity_string(self):
     """Test splitting of entity string."""
     service.call_from_config(
         self.hass, {
             'service': 'test_domain.test_service',
             'entity_id': 'hello.world, sensor.beer'
         })
     self.hass.pool.block_till_done()
     self.assertEqual(['hello.world', 'sensor.beer'],
                      self.calls[-1].data.get('entity_id'))
Пример #4
0
    def _call_service(self, service_name, service_data=None,
                      allow_override=False):
        """Call either a specified or active child's service."""
        if allow_override and service_name in self._cmds:
            call_from_config(
                self.hass, self._cmds[service_name], blocking=True)
            return

        if service_data is None:
            service_data = {}

        active_child = self._child_state
        service_data[ATTR_ENTITY_ID] = active_child.entity_id

        self.hass.services.call(DOMAIN, service_name, service_data,
                                blocking=True)
Пример #5
0
    def test_template_service_call(self):
        """Test service call with tempating."""
        config = {
            'service_template': '{{ \'test_domain.test_service\' }}',
            'entity_id': 'hello.world',
            'data_template': {
                'hello': '{{ \'goodbye\' }}',
            },
        }
        runs = []

        decor = service.service('test_domain', 'test_service')
        decor(lambda x, y: runs.append(y))

        service.call_from_config(self.hass, config)
        self.hass.pool.block_till_done()

        self.assertEqual('goodbye', runs[0].data['hello'])
Пример #6
0
 def test_not_mutate_input(self):
     """Test for immutable input."""
     orig = {
         'service': 'test_domain.test_service',
         'entity_id': 'hello.world, sensor.beer',
         'data': {
             'hello': 1,
         },
     }
     service.call_from_config(self.hass, orig)
     self.hass.pool.block_till_done()
     self.assertEqual({
         'service': 'test_domain.test_service',
         'entity_id': 'hello.world, sensor.beer',
         'data': {
             'hello': 1,
         },
     }, orig)
Пример #7
0
    def test_template_service_call(self):
        """Test service call with tempating."""
        config = {
            'service_template': '{{ \'test_domain.test_service\' }}',
            'entity_id': 'hello.world',
            'data_template': {
                'hello': '{{ \'goodbye\' }}',
            },
        }
        runs = []

        decor = service.service('test_domain', 'test_service')
        decor(lambda x, y: runs.append(y))

        service.call_from_config(self.hass, config)
        self.hass.pool.block_till_done()

        self.assertEqual('goodbye', runs[0].data['hello'])
Пример #8
0
 def test_not_mutate_input(self):
     """Test for immutable input."""
     orig = {
         'service': 'test_domain.test_service',
         'entity_id': 'hello.world, sensor.beer',
         'data': {
             'hello': 1,
         },
     }
     service.call_from_config(self.hass, orig)
     self.hass.pool.block_till_done()
     self.assertEqual(
         {
             'service': 'test_domain.test_service',
             'entity_id': 'hello.world, sensor.beer',
             'data': {
                 'hello': 1,
             },
         }, orig)
Пример #9
0
    def _call_service(self,
                      service_name,
                      service_data=None,
                      allow_override=False):
        """Call either a specified or active child's service."""
        if allow_override and service_name in self._cmds:
            call_from_config(self.hass,
                             self._cmds[service_name],
                             blocking=True)
            return

        if service_data is None:
            service_data = {}

        active_child = self._child_state
        service_data[ATTR_ENTITY_ID] = active_child.entity_id

        self.hass.services.call(DOMAIN,
                                service_name,
                                service_data,
                                blocking=True)
Пример #10
0
    def test_passing_variables_to_templates(self):
        """Test passing variables to templates."""
        config = {
            'service_template': '{{ var_service }}',
            'entity_id': 'hello.world',
            'data_template': {
                'hello': '{{ var_data }}',
            },
        }
        runs = []

        decor = service.service('test_domain', 'test_service')
        decor(lambda x, y: runs.append(y))

        service.call_from_config(self.hass, config, variables={
            'var_service': 'test_domain.test_service',
            'var_data': 'goodbye',
        })
        self.hass.pool.block_till_done()

        self.assertEqual('goodbye', runs[0].data['hello'])
Пример #11
0
    def test_passing_variables_to_templates(self):
        """Test passing variables to templates."""
        config = {
            'service_template': '{{ var_service }}',
            'entity_id': 'hello.world',
            'data_template': {
                'hello': '{{ var_data }}',
            },
        }
        runs = []

        decor = service.service('test_domain', 'test_service')
        decor(lambda x, y: runs.append(y))

        service.call_from_config(self.hass,
                                 config,
                                 variables={
                                     'var_service': 'test_domain.test_service',
                                     'var_data': 'goodbye',
                                 })
        self.hass.pool.block_till_done()

        self.assertEqual('goodbye', runs[0].data['hello'])
Пример #12
0
    def test_fail_silently_if_no_service(self, mock_log):
        """Test failling if service is missing."""
        service.call_from_config(self.hass, None)
        self.assertEqual(1, mock_log.call_count)

        service.call_from_config(self.hass, {})
        self.assertEqual(2, mock_log.call_count)

        service.call_from_config(self.hass, {'service': 'invalid'})
        self.assertEqual(3, mock_log.call_count)
Пример #13
0
    def test_fail_silently_if_no_service(self, mock_log):
        """Test failling if service is missing."""
        service.call_from_config(self.hass, None)
        self.assertEqual(1, mock_log.call_count)

        service.call_from_config(self.hass, {})
        self.assertEqual(2, mock_log.call_count)

        service.call_from_config(self.hass, {
            'service': 'invalid'
        })
        self.assertEqual(3, mock_log.call_count)
Пример #14
0
 def _call_service(self, action, variables):
     """Call the service specified in the action."""
     self.last_action = action.get(CONF_ALIAS, 'call service')
     self._log("Executing step %s" % self.last_action)
     service.call_from_config(self.hass, action, True, variables,
                              validate_config=False)