15
15
import static org .openhab .binding .fmiweather .internal .BindingConstants .*;
16
16
import static org .openhab .binding .fmiweather .internal .discovery .CitiesOfFinland .CITIES_OF_FINLAND ;
17
17
18
+ import java .text .Normalizer ;
18
19
import java .util .Collections ;
19
20
import java .util .LinkedList ;
20
21
import java .util .List ;
@@ -140,9 +141,9 @@ public void createResults(@Nullable PointType location) {
140
141
private void createForecastForCurrentLocation (@ Nullable PointType currentLocation ) {
141
142
if (currentLocation != null ) {
142
143
DiscoveryResult discoveryResult = DiscoveryResultBuilder .create (UID_LOCAL_FORECAST )
143
- .withLabel (String . format ( "FMI local weather forecast" ) )
144
+ .withLabel ("FMI local weather forecast" )
144
145
.withProperty (LOCATION ,
145
- String . format ( "%s,%s" , currentLocation .getLatitude (), currentLocation .getLongitude ()))
146
+ "%s,%s" . formatted ( currentLocation .getLatitude (), currentLocation .getLongitude ()))
146
147
.withRepresentationProperty (LOCATION ).build ();
147
148
thingDiscovered (discoveryResult );
148
149
}
@@ -151,11 +152,11 @@ private void createForecastForCurrentLocation(@Nullable PointType currentLocatio
151
152
private void createForecastsForCities (@ Nullable PointType currentLocation ) {
152
153
CITIES_OF_FINLAND .stream ().filter (location2 -> isClose (currentLocation , location2 )).forEach (city -> {
153
154
DiscoveryResult discoveryResult = DiscoveryResultBuilder
154
- .create (new ThingUID (THING_TYPE_FORECAST , cleanId (String . format ( "city_%s" , city .name ))))
155
+ .create (new ThingUID (THING_TYPE_FORECAST , cleanId ("city_%s" . formatted ( city .name ))))
155
156
.withProperty (LOCATION ,
156
- String . format ( "%s,%s" , city .latitude .toPlainString (), city .longitude .toPlainString ()))
157
- .withLabel (String . format ( "FMI weather forecast for %s" , city .name ))
158
- .withRepresentationProperty ( LOCATION ). build ();
157
+ "%s,%s" . formatted ( city .latitude .toPlainString (), city .longitude .toPlainString ()))
158
+ .withLabel ("FMI weather forecast for %s" . formatted ( city .name )). withRepresentationProperty ( LOCATION )
159
+ .build ();
159
160
thingDiscovered (discoveryResult );
160
161
});
161
162
}
@@ -174,25 +175,24 @@ private void createObservationsForStations(@Nullable PointType location) {
174
175
}).forEach (station -> {
175
176
DiscoveryResult discoveryResult = DiscoveryResultBuilder
176
177
.create (new ThingUID (THING_TYPE_OBSERVATION ,
177
- cleanId (String . format ( "station_%s_%s" , station .id , station .name ))))
178
- .withLabel (String . format ( "FMI weather observation for %s" , station .name ))
178
+ cleanId ("station_%s_%s" . formatted ( station .id , station .name ))))
179
+ .withLabel ("FMI weather observation for %s" . formatted ( station .name ))
179
180
.withProperty (BindingConstants .FMISID , station .id )
180
181
.withRepresentationProperty (BindingConstants .FMISID ).build ();
181
182
thingDiscovered (discoveryResult );
182
183
});
183
184
if (logger .isDebugEnabled ()) {
184
185
logger .debug ("Candidate stations: {}" ,
185
- candidateStations .stream ().map (station -> String . format ( "%s (%s)" , station .name , station .id ))
186
+ candidateStations .stream ().map (station -> "%s (%s)" . formatted ( station .name , station .id ))
186
187
.collect (Collectors .toCollection (TreeSet <String >::new )));
187
188
logger .debug ("Filtered stations: {}" ,
188
- filteredStations .stream ().map (station -> String . format ( "%s (%s)" , station .name , station .id ))
189
+ filteredStations .stream ().map (station -> "%s (%s)" . formatted ( station .name , station .id ))
189
190
.collect (Collectors .toCollection (TreeSet <String >::new )));
190
191
}
191
192
}
192
193
193
194
private static String cleanId (String id ) {
194
- return id .replace ("ä" , "a" ).replace ("ö" , "o" ).replace ("å" , "a" ).replace ("Ä" , "A" ).replace ("Ö" , "O" )
195
- .replace ("Å" , "a" ).replaceAll ("[^a-zA-Z0-9_]" , "_" );
195
+ return Normalizer .normalize (id , Normalizer .Form .NFKD ).replaceAll ("\\ p{M}" , "" ).replaceAll ("[^a-zA-Z0-9_]" , "_" );
196
196
}
197
197
198
198
private static boolean isClose (@ Nullable PointType location , Location location2 ) {
0 commit comments