コード例 #1
0
def test_change_something_true():
    """Test hange_something_true."""
    from sampleclient.client import Client

    client = Client(USERNAME, PASSWORD)
    print(client.something)
    client.change_something(False)
    print(client.something)
コード例 #2
0
ファイル: config_flow.py プロジェクト: magyari44/api-sensor
 async def _test_credentials(self, username, password):
     """Return true if credentials is valid."""
     try:
         client = Client(username, password)
         client.get_data()
         return True
     except Exception:  # pylint: disable=broad-except
         pass
     return False
コード例 #3
0
ファイル: __init__.py プロジェクト: KTibow/ha-blueprint
    def __init__(self, hass, username, password):
        """Initialize."""
        self.api = Client(username, password)
        self.platforms = []

        super().__init__(hass,
                         _LOGGER,
                         name=DOMAIN,
                         update_interval=SCAN_INTERVAL)
コード例 #4
0
async def async_setup(hass, config):
    """Set up this component using YAML."""
    if config.get(DOMAIN) is None:
        # We get here if the integration is set up using config flow
        return True

    # Print startup message
    _LOGGER.info(
        CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
    )

    # Check that all required files are present
    file_check = await check_files(hass)
    if not file_check:
        return False

    # Create DATA dict
    hass.data[DOMAIN_DATA] = {}

    # Get "global" configuration.
    hostname = config[DOMAIN].get(CONF_HOSTNAME)
    port = config[DOMAIN].get(CONF_PORT)

    # Configure the client.
    client = Client(hostname, port)
    hass.data[DOMAIN_DATA]["client"] = HDMIMatrixData(hass, client)

    # Load platforms
    for platform in PLATFORMS:
        # Get platform specific configuration
        platform_config = config[DOMAIN].get(platform, {})

        # If platform is not enabled, skip.
        if not platform_config:
            continue

        for entry in platform_config:
            entry_config = entry

            # If entry is not enabled, skip.
            if not entry_config[CONF_ENABLED]:
                continue

            hass.async_create_task(
                discovery.async_load_platform(
                    hass, platform, DOMAIN, entry_config, config
                )
            )
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
        )
    )
    return True
コード例 #5
0
async def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    conf = hass.data.get(DOMAIN_DATA)
    if config_entry.source == config_entries.SOURCE_IMPORT:
        if conf is None:
            hass.async_create_task(
                hass.config_entries.async_remove(config_entry.entry_id)
            )
        return False

    # Print startup message
    _LOGGER.info(
        CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
    )

    # Check that all required files are present
    file_check = await check_files(hass)
    if not file_check:
        return False

    # Create DATA dict
    hass.data[DOMAIN_DATA] = {}

    # Get "global" configuration.
    hostname = config_entry.data.get(CONF_HOSTNAME)
    port = config_entry.data.get(CONF_PORT)

    # Configure the client.
    client = Client(hostname, port)
    hass.data[DOMAIN_DATA]["client"] = HDMIMatrixData(hass, client)

    # Add binary_sensor
    hass.async_add_job(
        hass.config_entries.async_forward_entry_setup(config_entry, "binary_sensor")
    )

    # Add sensor
    hass.async_add_job(
        hass.config_entries.async_forward_entry_setup(config_entry, "sensor")
    )

    # Add switch
    hass.async_add_job(
        hass.config_entries.async_forward_entry_setup(config_entry, "switch")
    )

    return True
コード例 #6
0
async def async_setup(hass, config):
    """Set up this component."""
    # Import client from a external python package hosted on PyPi
    from sampleclient.client import Client

    # Print startup message
    startup = STARTUP.format(name=DOMAIN, version=VERSION, issueurl=ISSUE_URL)
    _LOGGER.info(startup)

    # Check that all required files are present
    file_check = await check_files(hass)
    if not file_check:
        return False

    # Create DATA dict
    hass.data[DOMAIN_DATA] = {}

    # Get "global" configuration.
    username = config[DOMAIN].get(CONF_USERNAME)
    password = config[DOMAIN].get(CONF_PASSWORD)

    # Configure the client.
    client = Client(username, password)
    hass.data[DOMAIN_DATA]["client"] = BlueprintData(hass, client)

    # Load platforms
    for platform in PLATFORMS:
        # Get platform specific configuration
        platform_config = config[DOMAIN].get(platform, {})

        # If platform is not enabled, skip.
        if not platform_config:
            continue

        for entry in platform_config:
            entry_config = entry

            # If entry is not enabled, skip.
            if not entry_config[CONF_ENABLED]:
                continue

            hass.async_create_task(
                discovery.async_load_platform(
                    hass, platform, DOMAIN, entry_config, config
                )
            )
    return True
コード例 #7
0
def test_get_data():
    """Test get_data."""
    from sampleclient.client import Client

    client = Client(USERNAME, PASSWORD)
    print(client.get_data())