Source:
<code>private void registerServices(Thing thing, ThingHandler thingHandler) { ThingUID thingUID = thing.getUID(); for (Class c : thingHandler.getServices()) { Object serviceInstance; try { serviceInstance = c.newInstance(); if (serviceInstance instanceof ThingHandlerService) { ThingHandlerService ths = (ThingHandlerService) serviceInstance; ths.setThingHandler(thingHandler); } else { logger.warn( "Should register service={} for thingUID={}, but it does not implement the interface ThingHandlerService.", c.getCanonicalName(), thingUID); continue; } Dictionary<String, String> properties = new Hashtable<>(); <START> properties.put(ThingHandlerService.ACTION_THING_UID, thingUID.getAsString()); <END> Class[] interfaces = c.getInterfaces(); LinkedList<String> serviceNames = new LinkedList<>(); if (interfaces != null) { for (Class i : interfaces) { serviceNames.add(i.getCanonicalName()); } } String[] serviceNamesArray = serviceNames.toArray(new String[serviceNames.size()]); ServiceRegistration<?> serviceReg = this.bundleContext.registerService(serviceNamesArray, serviceInstance, properties); if (serviceReg != null) { Set<ServiceRegistration<?>> serviceRegs = this.thingHandlerServices.get(thingUID); if (serviceRegs == null) { HashSet<ServiceRegistration<?>> set = new HashSet<>(); set.add(serviceReg); this.thingHandlerServices.put(thingUID, set); } else { serviceRegs.add(serviceReg); } } } catch (InstantiationException | IllegalAccessException e) { logger.warn("Could not register service for class={}", c, e); } } }</code><technical_language>calculating properties responsibility of handler? define another method ThingHandler Dictionary<String, String> getThingHandlerServiceProperties(ThingHandlerService ths) ThingHandler decide properties necessary. THS ACTION_THING_UID property for it</technical_language>

Target:
private void registerServices(Thing thing, ThingHandler thingHandler) { ThingUID thingUID = thing.getUID(); for (Class c : thingHandler.getServices()) { Object serviceInstance; try { serviceInstance = c.newInstance(); ThingHandlerService ths = null; if (serviceInstance instanceof ThingHandlerService) { ths = (ThingHandlerService) serviceInstance; ths.setThingHandler(thingHandler); } else { logger.warn( "Should register service={} for thingUID={}, but it does not implement the interface ThingHandlerService.", c.getCanonicalName(), thingUID); continue; } Class[] interfaces = c.getInterfaces(); LinkedList<String> serviceNames = new LinkedList<>(); if (interfaces != null) { for (Class i : interfaces) { String className = i.getCanonicalName(); if (!ThingHandlerService.class.getCanonicalName().equals(className)) { serviceNames.add(className); } } } if (serviceNames.size() > 0) { String[] serviceNamesArray = serviceNames.toArray(new String[serviceNames.size()]); ServiceRegistration<?> serviceReg = this.bundleContext.registerService(serviceNamesArray, serviceInstance, null); if (serviceReg != null) { Set<ServiceRegistration<?>> serviceRegs = this.thingHandlerServices.get(thingUID); if (serviceRegs == null) { HashSet<ServiceRegistration<?>> set = new HashSet<>(); set.add(serviceReg); this.thingHandlerServices.put(thingUID, set); } else { serviceRegs.add(serviceReg); } ths.activate(); } } } catch (InstantiationException | IllegalAccessException e) { logger.warn("Could not register service for class={}", c, e); } } }