]> git.basschouten.com Git - openhab-addons.git/blob
a67fc8171217d231228e0e96af73cee4db53b2f8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.boschshc.internal.devices.bridge.dto;
14
15 import java.util.Arrays;
16
17 import org.openhab.binding.boschshc.internal.services.dto.BoschSHCServiceState;
18
19 /**
20  * A scenario as represented by the controller.
21  *
22  * Json example:
23  * {
24  * "@type": "scenarioTriggered",
25  * "name": "My scenario",
26  * "id": "509bd737-eed0-40b7-8caa-e8686a714399",
27  * "lastTimeTriggered": "1693758693032"
28  * }
29  *
30  * @author Patrick Gell - Initial contribution
31  */
32 public class Scenario extends BoschSHCServiceState {
33
34     public String name;
35     public String id;
36     public String lastTimeTriggered;
37
38     public Scenario() {
39         super("scenarioTriggered");
40     }
41
42     public static Scenario createScenario(final String id, final String name, final String lastTimeTriggered) {
43         final Scenario scenario = new Scenario();
44
45         scenario.id = id;
46         scenario.name = name;
47         scenario.lastTimeTriggered = lastTimeTriggered;
48         return scenario;
49     }
50
51     public static Boolean isValid(Scenario[] scenarios) {
52         return Arrays.stream(scenarios).allMatch(scenario -> (scenario.id != null));
53     }
54
55     @Override
56     public String toString() {
57         final StringBuilder sb = new StringBuilder("Scenario{");
58         sb.append("name='").append(name).append("'");
59         sb.append(", id='").append(id).append("'");
60         sb.append(", lastTimeTriggered='").append(lastTimeTriggered).append("'");
61         sb.append('}');
62         return sb.toString();
63     }
64 }