Можно добавить пару API функций в модуль.
- определение состояния ТВ (вкл/выкл)
- включение через API, а не через IRCC функции
- определение текущего уровня громкости и режима "без звука"
- информация о просматриваемом канале и проигрываемой программе (название канала, название текущей программы, дата начала, продолжительность)
Для себя пока что написал "костыльный" сценарий, который обновляет свойства объекта ТВ.
Если будет желание прикрутить к модулю - было бы не плохо.
Код: Выделить всё
$tvip = gg('SonyKD85.ipaddress');
$ch = curl_init($tvip.'/sony/audio/');
$data_string = '{"method": "getVolumeInformation", "params": [""], "id": 1, "version": "1.0"}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
sg('SonyKD85.volumeResponseText',$result);
$volumelevel = json_decode($result,true);
$vol = $volumelevel['result'][0][0]['volume'];
$muted = $volumelevel['result'][0][0]['mute'];
sg('SonyKD85.volumeLevel',$vol);
if ($muted == 0) {
sg('SonyKD85.mutedState',0);
} else {
sg('SonyKD85.mutedState',1);
}
$ch = curl_init($tvip.'/sony/system/');
$data_string = '{"method": "getPowerStatus", "params": [""], "id": 1, "version": "1.0"}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
sg('SonyKD85.systemResponseText',$result);
$currentState = json_decode($result,true);
$status = $currentState['result'][0]['status'];
if ($status == 'active') {
sg('SonyKD85.powerState',1);
} else {
sg('SonyKD85.powerState',0);
}
$ch = curl_init($tvip.'/sony/accessControl');
$data_string = '{"id":7,"method":"actRegister","version":"1.0","params":[{"clientid":"MajorDoMo:7","nickname":"MajorDoMo"},[{"clientid":"MajorDoMo:7","value":"yes","nickname":"MajorDoMo","function":"WOL"}]]}';
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
$tmpfname = ROOT . 'cached/sony/sonytv_1.txt';
$ch = curl_init($tvip.'/sony/avContent/');
$data_string = '{"method": "getPlayingContentInfo", "params": [""], "id": 1, "version": "1.0"}';
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
sg('SonyKD85.getPlayingContentInfo',$result);
$getPlayingContentInfo = json_decode($result,true);
$contentTitle = $getPlayingContentInfo['result'][0]['title'];
$contentSource = $getPlayingContentInfo['result'][0]['source'];
if ($contentSource=='tv:dvbt') {$contentSource = 'Воля кабель';}
$contentDisplayNumber = $getPlayingContentInfo['result'][0]['dispNum'];
$contentProgramTitle = $getPlayingContentInfo['result'][0]['programTitle'];
$contentStartDateTime = $getPlayingContentInfo['result'][0]['startDateTime'];
$contentDuration = $getPlayingContentInfo['result'][0]['durationSec'];
$DateArray = explode('+', $contentStartDateTime);
$DateTZArray = date_create_from_format('Y-m-d\TH:i:s', $DateArray[0]);
$contentStartDateTime = date_format($DateTZArray, 'd.m.Y H:i:s');
$DateTZArray = $DateTZArray->modify('+'.$contentDuration.' seconds');
$contentEndDateTime = date_format($DateTZArray, 'd.m.Y H:i:s');
sg('SonyKD85.contentTitle',$contentTitle);
sg('SonyKD85.contentSource',$contentSource);
sg('SonyKD85.contentDisplayNumber', $contentDisplayNumber);
sg('SonyKD85.contentProgramTitle', $contentProgramTitle);
sg('SonyKD85.contentStartDateTime', $contentStartDateTime);
sg('SonyKD85.contentDuration', $contentDuration);
sg('SonyKD85.contentEndDateTime', $contentEndDateTime);