Skip to content

Commit

Permalink
Merge pull request #2 from ticed35/master
Browse files Browse the repository at this point in the history
Copy from master to generate v1.1
  • Loading branch information
ticed35 authored Nov 10, 2017
2 parents 6b52f93 + 9127cff commit c9318e5
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 57 deletions.
7 changes: 6 additions & 1 deletion core/class/sonybravia.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ public function preSave() {
$this->setId($actionInfo->getId());
}
}
/*if ($this->getLogicalId() == "turn_on" || $this->getLogicalId() == "turn_off" || $this->getLogicalId() == "volume_up" || $this->getLogicalId() == "volume_down" || $this->getLogicalId() == "mute_volume") {
$this->setConfiguration('param', '1');
}*/
}

public function postSave() {
Expand Down Expand Up @@ -343,7 +346,9 @@ public function execute($_options = null) {
$cmd .= ' --mac ' . $sonybravia->getLogicalId();
$cmd .= ' --psk ' . $sonybravia->getConfiguration('psk');
$cmd .= ' --command ' . $this->getLogicalId();
$cmd .= ' --commandparam ' . $this->getConfiguration('param');
if($this->getConfiguration('param') !== ""){
$cmd .= " --commandparam '" . $this->getConfiguration('param') . "'";
}
$result = exec($cmd . ' >> ' . log::getPathToLog('sonybravia') . ' 2>&1 &');
} catch (Exception $e) {
log::add('sonybravia', 'info', $e->getMessage());
Expand Down
20 changes: 17 additions & 3 deletions desktop/js/sonybravia.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,20 @@ $( ".deamoninfo" ).on('mouseenter', function() {
tr += '<input class="cmdAttr form-control type input-sm" data-l1key="type" value="info" disabled style="margin-bottom : 5px;" />';
tr += '<span class="subType" subType="' + init(_cmd.subType) + '"></span>';
tr += '</td>';
tr += '<td><select style="width : 140px;" class="cmdAttr form-control input-sm" data-l1key="logicalId">';
tr += '<td><select style="width : 200px;" class="cmdAttr form-control input-sm" data-l1key="logicalId">';
tr += '<option value="model">Model</option>';
tr += '<option value="status">Etat</option>';
tr += '<option value="volume">Volume</option>';
tr += '<option value="source">Source</option>';
tr += '<option value="chaine">Chaine</option>';
tr += '<option value="nom_chaine">Nom Chaine</option>';
tr += '<option value="program">Programme</option>';
tr += '<option value="debut">Début du programme</option>';
tr += '<option value="debut_p">Début du programme</option>';
tr += '<option value="fin_p">Fin du programme</option>';
tr += '<option value="pourcent_p">Pourcentage d\'achèvement</option>';
tr += '<option value="duree">Durée</option>';
tr += '<option value="sources">Liste des sources</option>';
tr += '<option value="apps">Liste des applications</option>';
tr += '</select></td>';
//tr += '<td><input class="cmdAttr form-control input-sm" data-l1key="logicalId" style="width : 140px;" placeholder="{{logicalId}}"></td>';
//tr += '<td><textarea class="cmdAttr form-control input-sm" data-l1key="configuration" data-l2key="calcul" style="height : 33px;" ' + disabled + ' placeholder="{{Calcul}}"></textarea>';
Expand Down Expand Up @@ -195,13 +199,23 @@ if (init(_cmd.type) == 'action') {
tr += '<span class="subType" subType="' + init(_cmd.subType) + '"></span>';
tr += '<input class="cmdAttr" data-l1key="configuration" data-l2key="sonybraviaAction" value="1" style="display:none;" >';
tr += '</td>';
tr += '<td><select id="select_actions" style="width : 140px;" class="cmdAttr form-control input-sm" data-l1key="logicalId">';
tr += '<td><select style="width : 200px;" class="cmdAttr form-control input-sm" data-l1key="logicalId">';
tr += '<option value="turn_on">Allumer</option>';
tr += '<option value="turn_off">Eteindre</option>';
tr += '<option value="volume_up">Vol haut</option>';
tr += '<option value="volume_down">Vol bas</option>';
tr += '<option value="mute_volume">Mute</option>';
tr += '<option value="select_source">Changer Source</option>';
tr += '<option value="start_app">Démarrer une application</option>';

tr += '<option value="play_content">Jouer un fichier</option>';
tr += '<option value="media_play">Lecture</option>';
tr += '<option value="media_pause">Pause</option>';
tr += '<option value="media_previous_track">Précédent</option>';
tr += '<option value="media_next_track">Suivant</option>';
tr += '<option value="start_app">Démarrer une application</option>';


tr += '<option value="ircc">RAW</option>';
tr += '</select></td>';
tr += '<td>';
Expand Down
Binary file modified doc/images/sonybravia_screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/images/sonybravia_screenshot4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions resources/bravia.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ def connect(self, pin, clientid, nickname):
response = response.read()

except urllib.error.HTTPError as exception_instance:
Domoticz.Debug("[bravia_connect] HTTPError: " + str(exception_instance))
return False

except Exception as exception_instance: # pylint: disable=broad-except
Domoticz.Debug("[bravia_connect] Exception: " + str(exception_instance))
return False

else:
Domoticz.Debug(str(response))
#self._cookies = response.cookies
return True

Expand Down Expand Up @@ -385,7 +382,7 @@ def calc_time(self, *times):
if hr >= 24: #set 24:10 to 00:10
hr -= 24
return ("%02d:%02d" % (hr, min))

def playing_time(self, startDateTime, durationSec):
"""Give starttime, endtime and percentage played."""
#get starttime (2017-03-24T00:00:00+0100) and calculate endtime with duration (secs)
Expand Down
38 changes: 38 additions & 0 deletions resources/braviarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import socket
import struct
import requests
from datetime import datetime
import time
import sys

TIMEOUT = 10

Expand Down Expand Up @@ -390,3 +393,38 @@ def media_next_track(self):
def media_previous_track(self):
"""Send the previous track command."""
self.send_req_ircc(self.get_command_code('Prev'))

def calc_time(self, *times):
"""Calculate the sum of times, value is returned in HH:MM."""
totalSecs = 0
for tm in times:
timeParts = [int(s) for s in tm.split(':')]
totalSecs += (timeParts[0] * 60 + timeParts[1]) * 60 + timeParts[2]
totalSecs, sec = divmod(totalSecs, 60)
hr, min = divmod(totalSecs, 60)
if hr >= 24: #set 24:10 to 00:10
hr -= 24
return ("%02d:%02d" % (hr, min))

def playing_time(self, startDateTime, durationSec):
"""Give starttime, endtime and percentage played."""
#get starttime (2017-03-24T00:00:00+0100) and calculate endtime with duration (secs)
date_format = "%Y-%m-%dT%H:%M:%S"
try:
playingtime = datetime.now() - datetime.strptime(startDateTime[:-5], date_format)
except TypeError:
#https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
#playingtime = datetime.now() - datetime.fromtimestamp(time.mktime(time.strptime(startDateTime[:-5], date_format)))
playingtime = datetime.now() - datetime(*(time.strptime(startDateTime[:-5], date_format)[0:6]))
try:
starttime = datetime.time(datetime.strptime(startDateTime[:-5], date_format))
except TypeError:
#starttime = datetime.time(datetime.fromtimestamp(time.mktime(time.strptime(startDateTime[:-5], date_format))))
starttime = datetime.time(datetime(*(time.strptime(startDateTime[:-5], date_format)[0:6])))

duration = time.strftime('%H:%M:%S', time.gmtime(durationSec))
endtime = self.calc_time(str(starttime), str(duration))
starttime = starttime.strftime('%H:%M')
#print(playingtime.seconds, tvplaying['durationSec'])
perc_playingtime = int(round(((playingtime.seconds / durationSec) * 100),0))
return str(starttime), str(endtime), str(perc_playingtime)
35 changes: 24 additions & 11 deletions resources/sonybravia.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def run(self):
_SendData = ""
def target():
self.process = None
print (self.cmd + _SendData)
#logger.debug("Thread started, timeout = " + str(timeout)+", command : "+str(self.cmd))
self.process = subprocess.Popen(self.cmd + _SendData, shell=True)
#print(self.cmd + _SendData)
Expand Down Expand Up @@ -74,7 +73,6 @@ def timer_callback():
_tmp = ""
for cle, valeur in Apps.items():
_tmp += cle.replace(' ' , '%20') + "|"
print (_tmp)
_tmp = _tmp.replace('&', '%26')
_tmp = _tmp.replace('\'', '%27')
Donnees["apps"] = _tmp
Expand All @@ -92,11 +90,9 @@ def timer_callback():
try:
tvstatus = self._braviainstance.get_power_status()
Donnees["status"] = tvstatus
#print('Status TV:', tvstatus)
except KeyError:
print('TV not found')
sys.exit()

if tvstatus == 'active':
try:
tvinfo = self._braviainstance.get_system_info()
Expand All @@ -113,33 +109,50 @@ def timer_callback():
#print (tvPlaying)
if not tvPlaying:
Donnees["source"] = "Application"
Donnees["program"] = ""
Donnees["nom_chaine"] = ""
Donnees["debut"] = ""
Donnees["debut_p"] = ''
Donnees["fin_p"] = ''
Donnees["pourcent_p"] = '0
Donnees["duree"] = ""
Donnees["chaine"] = ""
else:
Donnees["source"] = ((tvPlaying['source'])[-4:]).upper() + (tvPlaying['uri'])[-1:]
try:
if tvPlaying['dispNum'] is not None :
Donnees["chaine"] = tvPlaying['dispNum']
except:
print('not found')
print('num chaine not found')
try:
if tvPlaying['programTitle'] is not None :
Donnees["program"] = tvPlaying['programTitle'].replace(' ','%20').replace('é','%C3%A9')
except:
print('not found')
print('program info not found')
try:
if tvPlaying['title'] is not None :
Donnees["nom_chaine"] = tvPlaying['title'].replace(' ','%20')
except:
print('not found')
print('nom chaine not found')
try:
if tvPlaying['startDateTime'] is not None :
Donnees["debut"] = tvPlaying['startDateTime']
if tvPlaying['startDateTime'] != '':
Donnees["debut"] = tvPlaying['startDateTime']
Donnees["debut_p"], Donnees["fin_p"], Donnees["pourcent_p"] = self._braviainstance.playing_time(tvPlaying['startDateTime'],tvPlaying['durationSec'])
else:
Donnees["debut_p"] = ''
Donnees["fin_p"] = ''
Donnees["pourcent_p"] = '0'
except:
print('not found')
print('start date not found')
try:
if tvPlaying['durationSec'] is not None :
Donnees["duree"] = str(tvPlaying['durationSec'])
if tvPlaying['durationSec'] != '':
Donnees["duree"] = str(tvPlaying['durationSec'])
else:
Donnees["duree"] = '0'
except:
print('not found')
print('duration not found')
except:
print('Playing Info not found')
self.cmd = "curl -L -s -G --max-time 15 " + self._jeedomadress + " -d 'apikey=" + self._apikey + "&mac=" + self._macadress
Expand Down
93 changes: 57 additions & 36 deletions resources/sonybravia_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,71 @@ def timer_callback():
try:
tvstatus = self._braviainstance.get_power_status()
Donnees["status"] = tvstatus
#print('Status TV:', tvstatus)
except KeyError:
print('TV not found')
sys.exit()
try:
if tvstatus == 'active':
try:
tvinfo = self._braviainstance.get_system_info()
Donnees["model"] = tvinfo['model']
except:
print('Model not found')
try:
vol = self._braviainstance.get_volume_info()
Donnees["volume"] = str(vol['volume'])
except:
print('Volume not found')
tvPlaying = self._braviainstance.get_playing_info()
#print (tvPlaying)
if not tvPlaying:
Donnees["source"] = "Application"
else:
Donnees["source"] = ((tvPlaying['source'])[-4:]).upper() + (tvPlaying['uri'])[-1:]
try:
if tvPlaying['dispNum'] is not None :
Donnees["chaine"] = tvPlaying['dispNum']
except:
print('not found')
try:
if tvPlaying['programTitle'] is not None :
Donnees["program"] = tvPlaying['programTitle'].replace(' ','%20').replace('é','%C3%A9')
except:
print('program not found')
try:
if tvPlaying['title'] is not None :
Donnees["nom_chaine"] = tvPlaying['title']
except:
print('not found')
try:
if tvPlaying['startDateTime'] is not None :
Donnees["debut"] = tvPlaying['startDateTime']
except:
print('not found')
try:
if tvPlaying['durationSec'] is not None :
Donnees["duree"] = str(tvPlaying['durationSec'])
except:
print('not found')
except:
print('Playing Info not found')
try:
tvPlaying = self._braviainstance.get_playing_info()
#print (tvPlaying)
if not tvPlaying:
Donnees["source"] = "Application"
Donnees["program"] = ""
Donnees["nom_chaine"] = ""
Donnees["debut"] = ""
Donnees["debut_p"] = ""
Donnees["fin_p"] = ''
Donnees["pourcent_p"] = '0'
Donnees["duree"] = ""
Donnees["chaine"] = ""
else:
Donnees["source"] = ((tvPlaying['source'])[-4:]).upper() + (tvPlaying['uri'])[-1:]
try:
if tvPlaying['dispNum'] is not None :
Donnees["chaine"] = tvPlaying['dispNum']
except:
print('not found')
try:
if tvPlaying['programTitle'] is not None :
Donnees["program"] = tvPlaying['programTitle'].replace(' ','%20').replace('é','%C3%A9')
except:
print('program not found')
try:
if tvPlaying['title'] is not None :
Donnees["nom_chaine"] = tvPlaying['title'].replace(' ','%20')
except:
print('not found')
try:
if tvPlaying['startDateTime'] is not None :
if tvPlaying['startDateTime'] != '':
Donnees["debut"] = tvPlaying['startDateTime']
Donnees["debut_p"], Donnees["fin_p"], Donnees["pourcent_p"] = self._braviainstance.playing_time(tvPlaying['startDateTime'],tvPlaying['durationSec'])
else:
Donnees["debut_p"] = ''
Donnees["fin_p"] = ''
Donnees["pourcent_p"] = '0'
except:
print('start date not found')
try:
if tvPlaying['durationSec'] is not None :
if tvPlaying['durationSec'] != '':
Donnees["duree"] = str(tvPlaying['durationSec'])
else:
Donnees["duree"] = '0'
except:
print('duration not found')
except:
print('Playing Info not found')
self.cmd = "curl -L -s -G --max-time 15 " + self._jeedomadress + " -d 'apikey=" + self._apikey + "&mac=" + self._macadress
for cle, valeur in Donnees.items():
if(cle in _Donnees):
Expand All @@ -155,7 +177,6 @@ def timer_callback():

def exit_handler(self, *args):
self.terminate()
#self._log.info("[exit_handler]")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions resources/sonybravia_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
parser.add_option("-m", "--mac", dest="mac", help="Mac de la tv")
parser.add_option("-s", "--psk", dest="psk", help="Cle")
parser.add_option("-c", "--command", dest="command_type", help="commande")
parser.add_option("-p", "--commandparam", dest="command_param", help="parametres")
parser.add_option("-p", "--commandparam", dest="command_param", help="parametres", default="1")
(options, args) = parser.parse_args()
if options.ip:
try:
Expand Down Expand Up @@ -56,7 +56,7 @@
_braviainstance.turn_on()
if command_type == 'turn_off':
_braviainstance.turn_off()
if command_type == 'set_source':
if command_type == 'select_source':
_braviainstance.select_source(command_param)
if command_type == 'set_volume':
_braviainstance.set_volume_level(command_param)
Expand Down

0 comments on commit c9318e5

Please sign in to comment.