def test_rules(fake_home: Home):
    with no_ssl_verification():
        rule = fake_home.search_rule_by_id("00000000-0000-0000-0000-000000000065")
        assert rule.active is True
        assert rule.label == "Alarmanlage"
        assert isinstance(rule, SimpleRule)
        assert rule.ruleErrorCategories == []
        assert rule.errorRuleTriggerItems == []
        assert rule.errorRuleConditionItems == []
        assert rule.errorRuleActionItems == []

        assert str(rule) == "SIMPLE Alarmanlage active(True)"

        # disable test
        rule.disable()
        rule.set_label("DISABLED_RULE")
        fake_home.get_current_state()
        rule = fake_home.search_rule_by_id("00000000-0000-0000-0000-000000000065")
        assert rule.active is False
        assert rule.label == "DISABLED_RULE"

        # endable test
        rule.enable()
        rule.set_label("ENABLED_RULE")
        fake_home.get_current_state()
        rule = fake_home.search_rule_by_id("00000000-0000-0000-0000-000000000065")
        assert rule.active is True
        assert rule.label == "ENABLED_RULE"

        rule.id = "INVALID_ID"
        result = rule.disable()
        assert result["errorCode"] == "INVALID_RULE"
        result = rule.set_label("NEW LABEL")
        assert result["errorCode"] == "INVALID_RULE"
예제 #2
0
def setup(hass, config):
    """Set up the HomematicIP component."""
    # pylint: disable=import-error, no-name-in-module
    from homematicip.home import Home

    hass.data.setdefault(DOMAIN, {})
    homes = hass.data[DOMAIN]
    accesspoints = config.get(DOMAIN, [])

    def _update_event(events):
        """Handle incoming HomeMaticIP events."""
        for event in events:
            etype = event['eventType']
            edata = event['data']
            if etype == 'DEVICE_CHANGED':
                dispatcher_send(hass, EVENT_DEVICE_CHANGED, edata.id)
            elif etype == 'GROUP_CHANGED':
                dispatcher_send(hass, EVENT_GROUP_CHANGED, edata.id)
            elif etype == 'HOME_CHANGED':
                dispatcher_send(hass, EVENT_HOME_CHANGED, edata.id)
            elif etype == 'JOURNAL_CHANGED':
                dispatcher_send(hass, EVENT_SECURITY_CHANGED, edata.id)
        return True

    for device in accesspoints:
        name = device.get(CONF_NAME)
        accesspoint = device.get(CONF_ACCESSPOINT)
        authtoken = device.get(CONF_AUTHTOKEN)

        home = Home()
        if name.lower() == 'none':
            name = ''
        home.label = name
        try:
            home.set_auth_token(authtoken)
            home.init(accesspoint)
            if home.get_current_state():
                _LOGGER.info("Connection to HMIP established")
            else:
                _LOGGER.warning("Connection to HMIP could not be established")
                return False
        except timeout:
            _LOGGER.warning("Connection to HMIP could not be established")
            return False
        homes[home.id] = home
        home.onEvent += _update_event
        home.enable_events()
        _LOGGER.info('HUB name: %s, id: %s', home.label, home.id)

        for component in ['sensor']:
            load_platform(hass, component, DOMAIN, {'homeid': home.id}, config)

    return True