2 * Copyright (c) 2010-2024 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.magentatv.internal;
15 import static org.openhab.binding.magentatv.internal.MagentaTVBindingConstants.*;
17 import java.lang.reflect.Type;
18 import java.util.ArrayList;
20 import org.eclipse.jdt.annotation.Nullable;
22 import com.google.gson.InstanceCreator;
23 import com.google.gson.annotations.SerializedName;
26 * The {@link MagentaTVGsonDTO} class implements The MR returns event information every time the program changes. This
27 * information is mapped to various Thing channels and also used to catch the power down event for MR400 (there is no
28 * way to query power status). This class provides the mapping between event JSON and Java class using Gson.
30 * @author Markus Michels - Initial contribution
32 public class MagentaTVGsonDTO {
34 * Program information event is send by the MR when a channel is changed.
37 * {"type":"EVENT_EIT_CHANGE","instance_id":26,"channel_code":"54","channel_num":"11","mediaId":"1221",
38 * "program_info": [ {"start_time":"2018/10/14 10:21:59","event_id":"9581","duration":"00:26:47",
39 * "free_CA_mode":false,"running_status":4, "short_event": [{"event_name":"Mysticons","language_code":"DEU",
40 * "text_char":"Die Mysticons..." } ]},
41 * {"start_time":"2018/10/14 10:48:46","event_id":"12204","duration":"00:23:54","free_CA_mode":false,
42 * "running_status":1, "short_event": [ {"event_name":"Winx Club","language_code":"DEU", "text_char":"Daphnes Eltern
43 * veranstalten...!" }]} ] }
45 // The following classes are used to map the JSON data into objects using GSon.
46 public static class MRProgramInfoEvent {
47 @SerializedName("type")
48 public String type = "";
49 @SerializedName("instance_id")
50 public Integer instanceId = 0;
51 @SerializedName("channel_code")
52 public String channelCode = "";
53 @SerializedName("channel_num")
54 public String channelNum = "";
55 @SerializedName("mediaId")
56 public String mediaId = "";
57 @SerializedName("program_info")
58 public ArrayList<MRProgramStatus> programInfo = new ArrayList<>();
61 public static class MRProgramInfoEventInstanceCreator implements InstanceCreator<MRProgramInfoEvent> {
63 public MRProgramInfoEvent createInstance(@Nullable Type type) {
64 return new MRProgramInfoEvent();
68 public static class MRProgramStatus {
69 @SerializedName("start_time")
70 public String startTime = "";
71 @SerializedName("event_id")
72 public String eventId = "";
73 @SerializedName("duration")
74 public String duration = "";
75 @SerializedName("free_CA_mode")
76 public Boolean freeCAMmode = false;
77 @SerializedName("running_status")
78 public Integer runningStatus = EV_EITCHG_RUNNING_NONE;
79 @SerializedName("short_event")
80 public ArrayList<MRShortProgramInfo> shortEvent = new ArrayList<>();
83 public static class MRProgramStatusInstanceCreator implements InstanceCreator<MRProgramStatus> {
85 public MRProgramStatus createInstance(@Nullable Type type) {
86 return new MRProgramStatus();
90 public static class MRShortProgramInfo {
91 @SerializedName("event_name")
92 public String eventName = "";
93 @SerializedName("language_code")
94 public String languageCode = "";
95 @SerializedName("text_char")
96 public String textChar = "";
99 public static class MRShortProgramInfoInstanceCreator implements InstanceCreator<MRShortProgramInfo> {
101 public MRShortProgramInfo createInstance(@Nullable Type type) {
102 return new MRShortProgramInfo();
107 * playStatus event format (JSON) playContent event, for details see
108 * http://support.huawei.com/hedex/pages/DOC1100366313CEH0713H/01/DOC1100366313CEH0713H/01/resources/dsv_hdx_idp/DSV/en/en-us_topic_0094619231.html
110 * sample 1: {"new_play_mode":4,"duration":0,"playBackState":1,"mediaType":1,"mediaCode":"3733","playPostion":0}
111 * sample 2: {"new_play_mode":4, "playBackState":1,"mediaType":1,"mediaCode":"3479"}
113 public static class MRPayEvent {
114 @SerializedName("new_play_mode")
115 public Integer newPlayMode = EV_PLAYCHG_STOP;
116 public Integer duration = -1;
117 public Integer playBackState = EV_PLAYCHG_STOP;
118 public Integer mediaType = 0;
119 public String mediaCode = "";
120 public Integer playPostion = -1;
123 public static class MRPayEventInstanceCreator implements InstanceCreator<MRPayEvent> {
125 public MRPayEvent createInstance(@Nullable Type type) {
126 return new MRPayEvent();
131 * Deutsche Telekom uses an OAuth-based authentication to access the EPG portal.
132 * The binding automates the login incl. OAuth authentication. This class helps mapping the response to a Java
133 * object (using Gson)
136 * { "enctytoken":"7FA9A6C05EDD873799392BBDDC5B7F34","encryptiontype":"0002",
137 * "platformcode":"0200", "epgurl":"http://appepmfk20005.prod.sngtv.t-online.de:33200",
138 * "version":"MEM V200R008C15B070", "epghttpsurl":"https://appepmfk20005.prod.sngtv.t-online.de:33207",
139 * "rootCerAddr": "http://appepmfk20005.prod.sngtv.t-online.de:33200/EPG/CA/iptv_ca.der",
140 * "upgAddr4IPTV":"https://slbedifk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
141 * "upgAddr4OTT":"https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp,https://slbedmfk11100.prod.sngtv.t-online.de:33428/EDS/jsp/upgrade.jsp",
143 * {"key":"SAM3ServiceURL","value":"https://accounts.login.idm.telekom.com"},
144 * {"key":"OAuthClientSecret","value":"21EAB062-C4EE-489C-BC80-6A65397F3F96"},
145 * {"key":"OAuthScope","value":"ngtvepg"},
146 * {"key":"OAuthClientId","value":"10LIVESAM30000004901NGTV0000000000000000"} ]
149 public static class OauthCredentials {
150 public String epghttpsurl = "";
151 public ArrayList<OauthKeyValue> sam3Para = new ArrayList<OauthKeyValue>();
154 public static class OauthCredentialsInstanceCreator implements InstanceCreator<OauthCredentials> {
156 public OauthCredentials createInstance(@Nullable Type type) {
157 return new OauthCredentials();
161 public static class OauthKeyValue {
162 public String key = "";
163 public String value = "";
166 public static class OAuthTokenResponse {
167 @SerializedName("error_description")
168 public String errorDescription = "";
169 public String error = "";
170 @SerializedName("access_token")
171 public String accessToken = "";
174 public static class OAuthTokenResponseInstanceCreator implements InstanceCreator<OAuthTokenResponse> {
176 public OAuthTokenResponse createInstance(@Nullable Type type) {
177 return new OAuthTokenResponse();
181 public static class OAuthAuthenticateResponse {
182 public String retcode = "";
183 public String desc = "";
184 public String epgurl = "";
185 public String userID = "";
188 public static class OAuthAuthenticateResponseInstanceCreator implements InstanceCreator<OAuthAuthenticateResponse> {
190 public OAuthAuthenticateResponse createInstance(@Nullable Type type) {
191 return new OAuthAuthenticateResponse();