2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.robonect.internal.model.cmd;
15 import java.net.URLEncoder;
16 import java.nio.charset.StandardCharsets;
18 import org.openhab.binding.robonect.internal.RobonectClient;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The command allows to set or retrieve the mower name.
25 * @author Marco Meyer - Initial contribution
27 public class NameCommand implements Command {
29 private final Logger logger = LoggerFactory.getLogger(NameCommand.class);
31 private String newName;
34 * sets the mower name.
36 * @param newName - the mower name.
37 * @return - the command instance.
39 public NameCommand withNewName(String newName) {
40 this.newName = newName != null ? newName : "";
45 * @param baseURL - will be passed by the {@link RobonectClient} in the form
46 * http://xxx.xxx.xxx/json?
50 public String toCommandURL(String baseURL) {
51 if (newName == null) {
52 return baseURL + "?cmd=name";
54 return baseURL + "?cmd=name&name=" + URLEncoder.encode(newName, StandardCharsets.ISO_8859_1);