예제 #1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Monoprice 6-zone amplifier platform."""
    port = config.get(CONF_PORT)

    from serial import SerialException
    from pymonoprice import get_monoprice

    try:
        monoprice = get_monoprice(port)
    except SerialException:
        _LOGGER.error("Error connecting to Monoprice controller")
        return

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

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

    add_entities(hass.data[DATA_MONOPRICE], True)

    def service_handle(service):
        """Handle for services."""
        entity_ids = service.data.get(ATTR_ENTITY_ID)

        if entity_ids:
            devices = [
                device for device in hass.data[DATA_MONOPRICE]
                if device.entity_id in entity_ids
            ]
        else:
            devices = hass.data[DATA_MONOPRICE]

        for device in devices:
            if service.service == SERVICE_SNAPSHOT:
                device.snapshot()
            elif service.service == SERVICE_RESTORE:
                device.restore()

    hass.services.register(DOMAIN,
                           SERVICE_SNAPSHOT,
                           service_handle,
                           schema=MEDIA_PLAYER_SCHEMA)

    hass.services.register(DOMAIN,
                           SERVICE_RESTORE,
                           service_handle,
                           schema=MEDIA_PLAYER_SCHEMA)
예제 #2
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Monoprice 6-zone amplifier platform."""
    port = config.get(CONF_PORT)

    from serial import SerialException
    from pymonoprice import get_monoprice
    try:
        monoprice = get_monoprice(port)
    except SerialException:
        _LOGGER.error("Error connecting to Monoprice controller")
        return

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

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

    add_devices(hass.data[DATA_MONOPRICE], True)

    def service_handle(service):
        """Handle for services."""
        entity_ids = service.data.get(ATTR_ENTITY_ID)

        if entity_ids:
            devices = [device for device in hass.data[DATA_MONOPRICE]
                       if device.entity_id in entity_ids]
        else:
            devices = hass.data[DATA_MONOPRICE]

        for device in devices:
            if service.service == SERVICE_SNAPSHOT:
                device.snapshot()
            elif service.service == SERVICE_RESTORE:
                device.restore()

    hass.services.register(
        DOMAIN, SERVICE_SNAPSHOT, service_handle, schema=MEDIA_PLAYER_SCHEMA)

    hass.services.register(
        DOMAIN, SERVICE_RESTORE, service_handle, schema=MEDIA_PLAYER_SCHEMA)
예제 #3
0
 def setUp(self):
     self.responses = {}
     self.monoprice = get_monoprice(create_dummy_port(self.responses))