]> git.basschouten.com Git - openhab-addons.git/blob
b09c7c0921d269b62fe59db73fe1408210c674d1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.robonect.internal.model.cmd;
14
15 import java.net.URLEncoder;
16 import java.nio.charset.StandardCharsets;
17
18 import org.openhab.binding.robonect.internal.RobonectClient;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * The command allows to set or retrieve the mower name.
24  *
25  * @author Marco Meyer - Initial contribution
26  */
27 public class NameCommand implements Command {
28
29     private final Logger logger = LoggerFactory.getLogger(NameCommand.class);
30
31     private String newName;
32
33     /**
34      * sets the mower name.
35      *
36      * @param newName - the mower name.
37      * @return - the command instance.
38      */
39     public NameCommand withNewName(String newName) {
40         this.newName = newName != null ? newName : "";
41         return this;
42     }
43
44     /**
45      * @param baseURL - will be passed by the {@link RobonectClient} in the form
46      *            http://xxx.xxx.xxx/json?
47      * @return
48      */
49     @Override
50     public String toCommandURL(String baseURL) {
51         if (newName == null) {
52             return baseURL + "?cmd=name";
53         } else {
54             return baseURL + "?cmd=name&name=" + URLEncoder.encode(newName, StandardCharsets.ISO_8859_1);
55         }
56     }
57 }