def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the SyncThru component.""" from pysyncthru import SyncThru, test_syncthru if discovery_info is not None: host = discovery_info.get(CONF_HOST) name = discovery_info.get(CONF_NAME, DEFAULT_NAME) _LOGGER.debug("Discovered a new Samsung Printer: %s", discovery_info) # Test if the discovered device actually is a syncthru printer if not test_syncthru(host): _LOGGER.error("No SyncThru Printer found at %s", host) return monitored = DEFAULT_MONITORED_CONDITIONS else: host = config.get(CONF_RESOURCE) name = config.get(CONF_NAME) monitored = config.get(CONF_MONITORED_CONDITIONS) # Main device, always added try: printer = SyncThru(host) except TypeError: # if an exception is thrown, printer cannot be set up return printer.update() devices = [SyncThruMainSensor(printer, name)] for key in printer.toner_status(filter_supported=True): if 'toner_{}'.format(key) in monitored: devices.append(SyncThruTonerSensor(printer, name, key)) for key in printer.drum_status(filter_supported=True): if 'drum_{}'.format(key) in monitored: devices.append(SyncThruDrumSensor(printer, name, key)) for key in printer.input_tray_status(filter_supported=True): if 'tray_{}'.format(key) in monitored: devices.append(SyncThruInputTraySensor(printer, name, key)) for key in printer.output_tray_status(): if 'output_tray_{}'.format(key) in monitored: devices.append(SyncThruOutputTraySensor(printer, name, key)) add_devices(devices, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the SyncThru component.""" from pysyncthru import SyncThru, test_syncthru if discovery_info is not None: host = discovery_info.get(CONF_HOST) name = discovery_info.get(CONF_NAME, DEFAULT_NAME) _LOGGER.debug("Discovered a new Samsung Printer: %s", discovery_info) # Test if the discovered device actually is a syncthru printer if not test_syncthru(host): _LOGGER.error("No SyncThru Printer found at %s", host) return monitored = DEFAULT_MONITORED_CONDITIONS else: host = config.get(CONF_RESOURCE) name = config.get(CONF_NAME) monitored = config.get(CONF_MONITORED_CONDITIONS) # Main device, always added try: printer = SyncThru(host) except TypeError: # if an exception is thrown, printer cannot be set up return printer.update() devices = [SyncThruMainSensor(printer, name)] for key in printer.toner_status(filter_supported=True): if 'toner_{}'.format(key) in monitored: devices.append(SyncThruTonerSensor(printer, name, key)) for key in printer.drum_status(filter_supported=True): if 'drum_{}'.format(key) in monitored: devices.append(SyncThruDrumSensor(printer, name, key)) for key in printer.input_tray_status(filter_supported=True): if 'tray_{}'.format(key) in monitored: devices.append(SyncThruInputTraySensor(printer, name, key)) for key in printer.output_tray_status(): if 'output_tray_{}'.format(key) in monitored: devices.append(SyncThruOutputTraySensor(printer, name, key)) add_entities(devices, True)