How to use the homeassistant.const.CONF_PORT function in homeassistant

To help you get started, we’ve selected a few homeassistant examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / soma / __init__.py View on Github external
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType

from .const import API, DOMAIN, HOST, PORT

DEVICES = "devices"

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = vol.Schema(
    {
        DOMAIN: vol.Schema(
            {vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PORT): cv.string}
        )
    },
    extra=vol.ALLOW_EXTRA,
)

SOMA_COMPONENTS = ["cover"]


async def async_setup(hass, config):
    """Set up the Soma component."""
    if DOMAIN not in config:
        return True

    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN,
github home-assistant / home-assistant / homeassistant / components / russound_rio / media_player.py View on Github external
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
    """Set up the Russound RIO platform."""
    from russound_rio import Russound

    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)

    russ = Russound(hass.loop, host, port)

    await russ.connect()

    # Discover sources and zones
    sources = await russ.enumerate_sources()
    valid_zones = await russ.enumerate_zones()

    devices = []
    for zone_id, name in valid_zones:
        await russ.watch_zone(zone_id)
        dev = RussoundZoneDevice(russ, zone_id, name, sources)
        devices.append(dev)

    @callback
github home-assistant / home-assistant / homeassistant / components / russound_rnet / media_player.py View on Github external
SUPPORT_VOLUME_MUTE
    | SUPPORT_VOLUME_SET
    | SUPPORT_TURN_ON
    | SUPPORT_TURN_OFF
    | SUPPORT_SELECT_SOURCE
)

ZONE_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})

SOURCE_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_HOST): cv.string,
        vol.Required(CONF_NAME): cv.string,
        vol.Required(CONF_PORT): cv.port,
        vol.Required(CONF_ZONES): vol.Schema({cv.positive_int: ZONE_SCHEMA}),
        vol.Required(CONF_SOURCES): vol.All(cv.ensure_list, [SOURCE_SCHEMA]),
    }
)


def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Russound RNET platform."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)

    if host is None or port is None:
        _LOGGER.error("Invalid config. Expected %s and %s", CONF_HOST, CONF_PORT)
        return False

    russ = russound.Russound(host, port)
github pschmitt / hass-config / config / hass / custom_components / media_player / sonyavr.py View on Github external
_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Sony SRS Speaker'
DEFAULT_PORT = 54480

SUPPORT_SONYAVR = SUPPORT_TURN_OFF | SUPPORT_TURN_ON | \
    SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE | SUPPORT_SELECT_SOURCE | \
    SUPPORT_VOLUME_SET

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST): cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
})


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Orange Livebox Play TV platform."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    name = config.get(CONF_NAME)

    sonyavr_devices = []

    try:
        device = SonyAvrDevice(host, port, name)
        sonyavr_devices.append(device)
github home-assistant / home-assistant / homeassistant / components / mfi / sensor.py View on Github external
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up mFi sensors."""
    host = config.get(CONF_HOST)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    use_tls = config.get(CONF_SSL)
    verify_tls = config.get(CONF_VERIFY_SSL)
    default_port = 6443 if use_tls else 6080
    port = int(config.get(CONF_PORT, default_port))

    try:
        client = MFiClient(
            host, username, password, port=port, use_tls=use_tls, verify=verify_tls
        )
    except (FailedToLogin, requests.exceptions.ConnectionError) as ex:
        _LOGGER.error("Unable to connect to mFi: %s", str(ex))
        return False

    add_entities(
        MfiSensor(port, hass)
        for device in client.get_devices()
        for port in device.ports.values()
        if port.model in SENSOR_MODELS
    )
github home-assistant / home-assistant / homeassistant / components / tomato / device_tracker.py View on Github external
CONF_PASSWORD,
    CONF_PORT,
    CONF_SSL,
    CONF_USERNAME,
    CONF_VERIFY_SSL,
)
import homeassistant.helpers.config_validation as cv

CONF_HTTP_ID = "http_id"

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_HOST): cv.string,
        vol.Optional(CONF_PORT): cv.port,
        vol.Optional(CONF_SSL, default=False): cv.boolean,
        vol.Optional(CONF_VERIFY_SSL, default=True): vol.Any(cv.boolean, cv.isfile),
        vol.Required(CONF_PASSWORD): cv.string,
        vol.Required(CONF_USERNAME): cv.string,
        vol.Required(CONF_HTTP_ID): cv.string,
    }
)


def get_scanner(hass, config):
    """Validate the configuration and returns a Tomato scanner."""
    return TomatoDeviceScanner(config[DOMAIN])


class TomatoDeviceScanner(DeviceScanner):
    """This class queries a wireless router running Tomato firmware."""
github home-assistant / home-assistant / homeassistant / components / mqtt / __init__.py View on Github external
def setup(hass, config):
    """Start the MQTT protocol service."""
    conf = config.get(DOMAIN, {})

    client_id = conf.get(CONF_CLIENT_ID)
    keepalive = conf.get(CONF_KEEPALIVE)

    broker_config = _setup_server(hass, config)

    if CONF_BROKER in conf:
        broker = conf[CONF_BROKER]
        port = conf[CONF_PORT]
        username = conf.get(CONF_USERNAME)
        password = conf.get(CONF_PASSWORD)
        certificate = conf.get(CONF_CERTIFICATE)
        client_key = conf.get(CONF_CLIENT_KEY)
        client_cert = conf.get(CONF_CLIENT_CERT)
        tls_insecure = conf.get(CONF_TLS_INSECURE)
        protocol = conf[CONF_PROTOCOL]
    elif broker_config:
        # If no broker passed in, auto config to internal server
        broker, port, username, password, certificate, protocol = broker_config
        # Embedded broker doesn't have some ssl variables
        client_key, client_cert, tls_insecure = None, None, None
    else:
        err = "Unable to start MQTT broker."
        if conf.get(CONF_EMBEDDED) is not None:
            # Explicit embedded config, requires explicit broker config
github home-assistant / home-assistant / homeassistant / components / sensor / glances.py View on Github external
'swap_free': ['Swap free', 'GiB', 'mdi:memory'],
    'processor_load': ['CPU load', '15 min', 'mdi:memory'],
    'process_running': ['Running', 'Count', 'mdi:memory'],
    'process_total': ['Total', 'Count', 'mdi:memory'],
    'process_thread': ['Thread', 'Count', 'mdi:memory'],
    'process_sleeping': ['Sleeping', 'Count', 'mdi:memory'],
    'cpu_use_percent': ['CPU used', '%', 'mdi:memory'],
    'cpu_temp': ['CPU Temp', TEMP_CELSIUS, 'mdi:thermometer'],
    'docker_active': ['Containers active', '', 'mdi:docker'],
    'docker_cpu_use': ['Containers CPU used', '%', 'mdi:docker'],
    'docker_memory_use': ['Containers RAM used', 'MiB', 'mdi:docker'],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Optional(CONF_USERNAME): cv.string,
    vol.Optional(CONF_PASSWORD): cv.string,
    vol.Optional(CONF_SSL, default=False): cv.boolean,
    vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
    vol.Optional(CONF_RESOURCES, default=['disk_use']):
        vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
    vol.Optional(CONF_VERSION, default=DEFAULT_VERSION): vol.In([2, 3]),
})


async def async_setup_platform(
        hass, config, async_add_entities, discovery_info=None):
    """Set up the Glances sensors."""
    from glances_api import Glances
github home-assistant / home-assistant / homeassistant / components / rainmachine / config_flow.py View on Github external
def __init__(self):
        """Initialize the config flow."""
        self.data_schema = OrderedDict()
        self.data_schema[vol.Required(CONF_IP_ADDRESS)] = str
        self.data_schema[vol.Required(CONF_PASSWORD)] = str
        self.data_schema[vol.Optional(CONF_PORT, default=DEFAULT_PORT)] = int
github home-assistant / home-assistant / homeassistant / components / mochad.py View on Github external
REQUIREMENTS = ['pymochad==0.2.0']

_LOGGER = logging.getLogger(__name__)

CONTROLLER = None

CONF_COMM_TYPE = 'comm_type'

DOMAIN = 'mochad'

REQ_LOCK = threading.Lock()

CONFIG_SCHEMA = vol.Schema({
    DOMAIN: vol.Schema({
        vol.Optional(CONF_HOST, default='localhost'): cv.string,
        vol.Optional(CONF_PORT, default=1099): cv.port,
    })
}, extra=vol.ALLOW_EXTRA)


def setup(hass, config):
    """Set up the mochad component."""
    conf = config[DOMAIN]
    host = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)

    from pymochad import exceptions

    global CONTROLLER
    try:
        CONTROLLER = MochadCtrl(host, port)
    except exceptions.ConfigurationError: