@Deactivate
    public void deactivate() {
        cfgService.removeListener(cfgListener);
        componentConfigService.unregisterProperties(getClass(), false);
        deviceService.removeListener(deviceListener);
        active = false;
        controller.getNetconfDevices().forEach(id -> {
            deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(id.toString()));
            controller.disconnectDevice(id, true);
        });
        controller.removeDeviceListener(innerNodeListener);
        providerRegistry.unregister(this);
        providerService = null;
        retriedPortDiscoveryMap.clear();
        cfgService.unregisterConfigFactory(factory);
        scheduledTask.cancel(true);
        connectionExecutor.shutdown();
        pollingExecutor.shutdown();
        reconnectionExecutor.shutdown();
        log.info("Stopped");
    }
@Test
    public void deactivate() throws Exception {
        provider.deactivate();
        assertNull("Device listener should be removed", deviceService.listener);
        assertFalse("Provider should not be registered", deviceRegistry.getProviders().contains(provider.id()));
        assertTrue("Thread to connect device should be shutdown", provider.connectionExecutor.isShutdown());
        assertTrue("Scheduled task to update device should be shutdown", provider.scheduledTask.isCancelled());
        assertNull("Provider service should be null", provider.providerService);
        assertTrue("Network config factories not removed", cfgFactories.isEmpty());
        assertEquals("Controller listener should be removed", 0, netconfDeviceListeners.size());
    }