Example #1
0
    def test_config(self):
        """Test config."""
        self.assertFalse(
            input_boolean.setup(self.hass, {'input_boolean': None}))

        self.assertFalse(input_boolean.setup(self.hass, {'input_boolean': {}}))

        self.assertFalse(
            input_boolean.setup(self.hass,
                                {'input_boolean': {
                                    'name with space': None
                                }}))
Example #2
0
    def test_config_options(self):
        count_start = len(self.hass.states.entity_ids())

        self.assertTrue(
            input_boolean.setup(
                self.hass, {
                    'input_boolean': {
                        'test_1': None,
                        'test_2': {
                            'name': 'Hello World',
                            'icon': 'work',
                            'initial': True,
                        },
                    },
                }))

        self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))

        state_1 = self.hass.states.get('input_boolean.test_1')
        state_2 = self.hass.states.get('input_boolean.test_2')

        self.assertIsNotNone(state_1)
        self.assertIsNotNone(state_2)

        self.assertEqual(STATE_OFF, state_1.state)
        self.assertNotIn(ATTR_ICON, state_1.attributes)
        self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)

        self.assertEqual(STATE_ON, state_2.state)
        self.assertEqual('Hello World',
                         state_2.attributes.get(ATTR_FRIENDLY_NAME))
        self.assertEqual('work', state_2.attributes.get(ATTR_ICON))
    def test_config_options(self):
        count_start = len(self.hass.states.entity_ids())

        self.assertTrue(input_boolean.setup(self.hass, {
            'input_boolean': {
                'test_1': None,
                'test_2': {
                    'name': 'Hello World',
                    'icon': 'work',
                    'initial': True,
                },
            },
        }))

        self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))

        state_1 = self.hass.states.get('input_boolean.test_1')
        state_2 = self.hass.states.get('input_boolean.test_2')

        self.assertIsNotNone(state_1)
        self.assertIsNotNone(state_2)

        self.assertEqual(STATE_OFF, state_1.state)
        self.assertNotIn(ATTR_ICON, state_1.attributes)
        self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)

        self.assertEqual(STATE_ON, state_2.state)
        self.assertEqual('Hello World',
                         state_2.attributes.get(ATTR_FRIENDLY_NAME))
        self.assertEqual('work', state_2.attributes.get(ATTR_ICON))
    def test_methods(self):
        """ Test is_on, turn_on, turn_off methods. """
        self.assertTrue(input_boolean.setup(self.hass, {
            'input_boolean': {
                'test_1': None,
            }
        }))
        entity_id = 'input_boolean.test_1'

        self.assertFalse(
            input_boolean.is_on(self.hass, entity_id))

        input_boolean.turn_on(self.hass, entity_id)

        self.hass.pool.block_till_done()

        self.assertTrue(
            input_boolean.is_on(self.hass, entity_id))

        input_boolean.turn_off(self.hass, entity_id)

        self.hass.pool.block_till_done()

        self.assertFalse(
            input_boolean.is_on(self.hass, entity_id))
    def test_config(self):
        """Test config."""
        self.assertFalse(input_boolean.setup(self.hass, {
            'input_boolean': None
        }))

        self.assertFalse(input_boolean.setup(self.hass, {
            'input_boolean': {
            }
        }))

        self.assertFalse(input_boolean.setup(self.hass, {
            'input_boolean': {
                'name with space': None
            }
        }))
Example #6
0
def setup(hass, config):
    """Setup example component."""
    target_entity =  config[DOMAIN].get('target')
    name =  config[DOMAIN].get('name', DOMAIN + ' ' + target_entity)

    object_id_enable = DOMAIN + '_' + target_entity + '_enable'
    object_id_hour = DOMAIN + '_' + target_entity + '_hour'
    object_id_temp = DOMAIN + '_' + target_entity + '_temp'

    def activate(now):
        if hass.states.get('input_boolean.' + object_id_enable).state == 'off':
            return
        if not str(now.hour) == str(int(float(hass.states.get('input_slider.' + object_id_hour).state))):
            return

        climate.set_temperature(hass, hass.states.get('input_slider.' + object_id_temp).state, entity_id='climate.'+target_entity)
        hass.states.set('input_boolean.' + object_id_enable, 'off')
        
    _config = config['input_boolean']
    _config[object_id_enable] = {'name': 'Enable', 'initial': False}
    config['input_boolean'] = _config
    input_boolean.setup(hass, config)

    _config = config['input_slider']
    _config[object_id_hour] = {'name': 'Hour', 'initial': 15, 'min': 7, 'max': 23, 'step': 1}
    _config[object_id_temp] = {'name': 'Temp', 'initial': 20, 'min': 17, 'max': 22, 'step': 0.5}
    config['input_slider'] = _config
    input_slider.setup(hass, config)

    #_config = {'platform': 'template', 'sensors': { object_id_hour: {'value_template': '{{ states("input_slider.' + object_id_hour + '") | round(0) }}'}}}
    #config['sensor'] = _config
    #sensor.setup(hass, config)

    group.Group(hass,name, ['input_boolean.' + object_id_enable, 'input_slider.' + object_id_hour, 'input_slider.' + object_id_temp])

    track_time_change(hass, activate, minute=0, second=2)

    def enable(entity_id, old_state, new_state):
        hass.states.set('input_boolean.' + object_id_enable, 'on')

    track_state_change(hass, ['input_slider.' + object_id_hour, 'input_slider.' + object_id_temp], enable)

    return True
Example #7
0
    def test_methods(self):
        """ Test is_on, turn_on, turn_off methods. """
        self.assertTrue(
            input_boolean.setup(self.hass,
                                {'input_boolean': {
                                    'test_1': None,
                                }}))
        entity_id = 'input_boolean.test_1'

        self.assertFalse(input_boolean.is_on(self.hass, entity_id))

        input_boolean.turn_on(self.hass, entity_id)

        self.hass.pool.block_till_done()

        self.assertTrue(input_boolean.is_on(self.hass, entity_id))

        input_boolean.turn_off(self.hass, entity_id)

        self.hass.pool.block_till_done()

        self.assertFalse(input_boolean.is_on(self.hass, entity_id))