コード例 #1
0
ファイル: media_player.py プロジェクト: MumiLila/gittest4
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Monoprice Blackbird 4k 8x8 HDBaseT Matrix platform."""
    if DATA_BLACKBIRD not in hass.data:
        hass.data[DATA_BLACKBIRD] = {}

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

    connection = None
    if port is not None:
        try:
            blackbird = get_blackbird(port)
            connection = port
        except SerialException:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    if host is not None:
        try:
            blackbird = get_blackbird(host, False)
            connection = host
        except socket.timeout:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    sources = {
        source_id: extra[CONF_NAME] for source_id, extra in config[CONF_SOURCES].items()
    }

    devices = []
    for zone_id, extra in config[CONF_ZONES].items():
        _LOGGER.info("Adding zone %d - %s", zone_id, extra[CONF_NAME])
        unique_id = f"{connection}-{zone_id}"
        device = BlackbirdZone(blackbird, sources, zone_id, extra[CONF_NAME])
        hass.data[DATA_BLACKBIRD][unique_id] = device
        devices.append(device)

    add_entities(devices, True)

    def service_handle(service):
        """Handle for services."""
        entity_ids = service.data.get(ATTR_ENTITY_ID)
        source = service.data.get(ATTR_SOURCE)
        if entity_ids:
            devices = [
                device
                for device in hass.data[DATA_BLACKBIRD].values()
                if device.entity_id in entity_ids
            ]

        else:
            devices = hass.data[DATA_BLACKBIRD].values()

        for device in devices:
            if service.service == SERVICE_SETALLZONES:
                device.set_all_zones(source)

    hass.services.register(
        DOMAIN, SERVICE_SETALLZONES, service_handle, schema=BLACKBIRD_SETALLZONES_SCHEMA
    )
コード例 #2
0
ファイル: blackbird.py プロジェクト: arsaboo/home-assistant
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Monoprice Blackbird 4k 8x8 HDBaseT Matrix platform."""
    if DATA_BLACKBIRD not in hass.data:
        hass.data[DATA_BLACKBIRD] = {}

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

    from pyblackbird import get_blackbird
    from serial import SerialException

    connection = None
    if port is not None:
        try:
            blackbird = get_blackbird(port)
            connection = port
        except SerialException:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    if host is not None:
        try:
            blackbird = get_blackbird(host, False)
            connection = host
        except socket.timeout:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    sources = {source_id: extra[CONF_NAME] for source_id, extra
               in config[CONF_SOURCES].items()}

    devices = []
    for zone_id, extra in config[CONF_ZONES].items():
        _LOGGER.info("Adding zone %d - %s", zone_id, extra[CONF_NAME])
        unique_id = "{}-{}".format(connection, zone_id)
        device = BlackbirdZone(blackbird, sources, zone_id, extra[CONF_NAME])
        hass.data[DATA_BLACKBIRD][unique_id] = device
        devices.append(device)

    add_entities(devices, True)

    def service_handle(service):
        """Handle for services."""
        entity_ids = service.data.get(ATTR_ENTITY_ID)
        source = service.data.get(ATTR_SOURCE)
        if entity_ids:
            devices = [device for device in hass.data[DATA_BLACKBIRD].values()
                       if device.entity_id in entity_ids]

        else:
            devices = hass.data[DATA_BLACKBIRD].values()

        for device in devices:
            if service.service == SERVICE_SETALLZONES:
                device.set_all_zones(source)

    hass.services.register(DOMAIN, SERVICE_SETALLZONES, service_handle,
                           schema=BLACKBIRD_SETALLZONES_SCHEMA)
コード例 #3
0
 def setUp(self):
     self.responses = {}
     self.blackbird = get_blackbird(create_dummy_port(self.responses))
コード例 #4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Monoprice Blackbird 4k 8x8 HDBaseT Matrix platform."""
    port = config.get(CONF_PORT)
    host = config.get(CONF_HOST)
    device_type = config.get(CONF_TYPE)

    import socket
    from pyblackbird import get_blackbird
    from serial import SerialException

    if device_type == 'serial':
        if port is None:
            _LOGGER.error("No port configured")
            return
        try:
            blackbird = get_blackbird(port)
        except SerialException:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    elif device_type == 'socket':
        try:
            if host is None:
                _LOGGER.error("No host configured")
                return
            blackbird = get_blackbird(host, False)
        except socket.timeout:
            _LOGGER.error("Error connecting to the Blackbird controller")
            return

    else:
        _LOGGER.error("Incorrect device type specified")
        return

    sources = {source_id: extra[CONF_NAME] for source_id, extra
               in config[CONF_SOURCES].items()}

    hass.data[DATA_BLACKBIRD] = []
    for zone_id, extra in config[CONF_ZONES].items():
        _LOGGER.info("Adding zone %d - %s", zone_id, extra[CONF_NAME])
        hass.data[DATA_BLACKBIRD].append(BlackbirdZone(
            blackbird, sources, zone_id, extra[CONF_NAME]))

    add_devices(hass.data[DATA_BLACKBIRD], True)

    def service_handle(service):
        """Handle for services."""
        entity_ids = service.data.get(ATTR_ENTITY_ID)
        source = service.data.get(ATTR_SOURCE)
        if entity_ids:
            devices = [device for device in hass.data[DATA_BLACKBIRD]
                       if device.entity_id in entity_ids]

        else:
            devices = hass.data[DATA_BLACKBIRD]

        for device in devices:
            if service.service == SERVICE_SETALLZONES:
                device.set_all_zones(source)

    hass.services.register(DOMAIN, SERVICE_SETALLZONES, service_handle,
                           schema=BLACKBIRD_SETALLZONES_SCHEMA)