Skip to content

Commit

Permalink
repo cleaning and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guirem committed Apr 24, 2018
1 parent bea29d0 commit 472a4ab
Show file tree
Hide file tree
Showing 17 changed files with 631 additions and 466 deletions.
43 changes: 43 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.js]
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.css]
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.py]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.sh]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
matrix:
include:
- language: php
php: 5.6
before_script:
- find . -type f -name *.php | xargs -n1 php -l
script:
- cd ${TRAVIS_BUILD_DIR}
- pwd
after_success:
- cd ${TRAVIS_BUILD_DIR}
- ls -latr
after_failure:
- cd ${TRAVIS_BUILD_DIR}
- ls -latr

- language: python
python: 2.7
install:
- pip install pylint
script:
- cd ${TRAVIS_BUILD_DIR}
- ./tests/tools/lintAllPythonFiles.sh
- language: markdown
addons:
apt:
packages:
- aspell
- aspell-fr
script:
- gem install mdl
- cd ${TRAVIS_BUILD_DIR}
- ./tests/tools/setCustomMDWarnings.sh
- mdl -r $MDLWAR *.md docs/fr_FR/*.md
- ./tests/tools/spellCheckMD.sh
18 changes: 18 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Description

## Etapes à reproduire (pour les bugs)

1.
2.
3.
4.

## Contexte:

## Proposition de solution (optionnel):

## Environnement:

* **Version Jeedom**:
* **Plateforme**:
* **Version du Plugin**:
2 changes: 1 addition & 1 deletion core/php/googlecast.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
throw new Exception(__('Aucune methode correspondante à : ', __FILE__) . init('action'));
/* * *********Catch exeption*************** */
} catch (Exception $e) {
ajax::error(displayExeption($e), $e->getCode());
ajax::error(displayException($e), $e->getCode());
}
2 changes: 1 addition & 1 deletion resources/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
DISCOVERY_FREQUENCY = 14400 # every 4 hours
DISCOVERY_LAST = int(time.time()) # when last started

LOSTDEVICE_RESENDNOTIFDELAY = 60*5 # not used yet
LOSTDEVICE_RESENDNOTIFDELAY = 60*15 # Resent offline msg after 15 minutes

IFACE_DEVICE = 0

Expand Down
123 changes: 71 additions & 52 deletions resources/googlecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
#
# You should have received a copy of the GNU General Public License
# along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
#
# pylint: disable=C
# pylint: disable=R
# pylint: disable=W
# pylint: disable=E

import subprocess
import os,re
import logging
import sys
Expand All @@ -23,41 +27,54 @@
import signal
import json
import traceback
import select
import _thread as thread

import globals
from threading import Timer
import _thread as thread

# check imports
try:
import pychromecast.pychromecast as pychromecast
except ImportError:
logging.error("ERROR: Main pychromecast module not loaded !")
logging.error(traceback.format_exc())
sys.exit(1)

try:
import pychromecast.pychromecast.controllers.dashcast as dashcast
import pychromecast.pychromecast.controllers.youtube as youtube
import pychromecast.pychromecast.controllers.plex as plex
import pychromecast.pychromecast.controllers.spotify as Spotify
except ImportError:
print("Error: importing pychromecast module")
sys.exit(1)
logging.error("ERROR: One or several pychromecast controllers are not loaded !")
print(traceback.format_exc())
pass

try:
import pychromecast.pychromecast.customcontrollers.youtube as youtube
except ImportError:
logging.error("ERROR: Custom controller not loaded !")
logging.error(traceback.format_exc())
pass

try:
from jeedom.jeedom import *
except ImportError:
print("Error: importing module from jeedom folder")
sys.exit(1)

# ------------------------

# class JeedomChromeCast
class JeedomChromeCast :
def __init__(self, gcast, options=None, scan_mode=False):
self.uuid = str(gcast.device.uuid)
self.friendly_name = gcast.device.friendly_name
self.gcast = gcast
self.previous_status = {"uuid" : self.uuid, "online" : False}
self.now_playing = False
self.now_playing_thread = False
self.online = True
self.being_shutdown = False
self.scan_mode = scan_mode
if scan_mode == False :
self.being_shutdown = False
self.customplayer = None
self.customplayername = ""
self.nowplaying_lastupdated = 0
Expand All @@ -83,9 +100,10 @@ def device(self):
return self.gcast.device

def startNowPlaying(self):
if self.now_playing == False and self.online == True and self.now_playing_thread == False:
if self.now_playing == False and self.online == True :
logging.debug("JEEDOMCHROMECAST------ Starting monitoring of " + self.uuid)
self.now_playing = True
self.sendNowPlaying(force=True)

def stopNowPlaying(self):
logging.debug("JEEDOMCHROMECAST------ Stopping monitoring of " + self.uuid)
Expand Down Expand Up @@ -129,8 +147,8 @@ def sendDeviceStatusIfNew(self):
self.sendDeviceStatus(False)

def disconnect(self):
self.being_shutdown = True
if self.scan_mode==False :
self.being_shutdown = True
self._internal_refresh_status(True)
if self.now_playing == True :
self._internal_send_now_playing()
Expand All @@ -147,28 +165,32 @@ def loadPlayer(self, playername, params=None, token=None) :
if params and 'forcereload' in params :
forceReload = True
if not self.customplayer or self.customplayername != playername or forceReload==True :
if playername == 'web' :
player = dashcast.DashCastController()
self.gcast.register_handler(player)
elif playername == 'youtube' :
player = youtube.YouTubeController()
self.gcast.register_handler(player)
elif playername == 'spotify' :
player = spotify.SpotifyController(token)
self.gcast.register_handler(player)
elif playername == 'plex' :
player = plex.PlexController()
else :
player = self.gcast.media_controller
logging.debug("JEEDOMCHROMECAST------ Initiating player " + str(player.namespace))
self.customplayer = player
self.customplayername = playername
if params and 'waitbeforequit' in params :
time.sleep(params['waitbeforequit'])
if params and 'quitapp' in params :
self.gcast.quit_app()
if params and 'wait' in params :
time.sleep(params['wait'])
try:
if playername == 'web' :
player = dashcast.DashCastController()
self.gcast.register_handler(player)
elif playername == 'youtube' :
player = youtube.YouTubeController()
self.gcast.register_handler(player)
elif playername == 'spotify' :
player = spotify.SpotifyController(token)
self.gcast.register_handler(player)
elif playername == 'plex' :
player = plex.PlexController()
else :
player = self.gcast.media_controller
logging.debug("JEEDOMCHROMECAST------ Initiating player " + str(player.namespace))
self.customplayer = player
self.customplayername = playername
if params and 'waitbeforequit' in params :
time.sleep(params['waitbeforequit'])
if params and 'quitapp' in params :
self.gcast.quit_app()
if params and 'wait' in params :
time.sleep(params['wait'])
except Exception :
player = None
pass
self.sendNowPlaying(force=True)
return self.customplayer
return None
Expand Down Expand Up @@ -263,14 +285,14 @@ def sendNowPlaying(self, force=False):
if force==True :
self._internal_send_now_playing()
elif self.now_playing==True:
logging.debug("JEEDOMCHROMECAST------ NOW PLAYGIN " + str(int(time.time())-self.nowplaying_lastupdated))
logging.debug("JEEDOMCHROMECAST------ NOW PLAYING " + str(int(time.time())-self.nowplaying_lastupdated))
if (int(time.time())-self.nowplaying_lastupdated)>=globals.NOWPLAYING_FREQUENCY :
self._internal_trigger_now_playing_update()

def sendNowPlaying_heartbeat(self):
if self.now_playing==True:
if (int(datetime.utcnow().timestamp())-self.nowplaying_lastupdated)>=globals.NOWPLAYING_FREQUENCY :
logging.debug("JEEDOMCHROMECAST------ NOW PLAYGIN heartbeat " + str(int(datetime.utcnow().timestamp())-self.nowplaying_lastupdated))
logging.debug("JEEDOMCHROMECAST------ NOW PLAYING heartbeat " + str(int(datetime.utcnow().timestamp())-self.nowplaying_lastupdated))
self._internal_trigger_now_playing_update()

def _internal_send_now_playing(self):
Expand Down Expand Up @@ -652,7 +674,6 @@ def scanner(name):
uuid = cast.uuid
current_time = int(time.time())

# starting event thread
if uuid in globals.KNOWN_DEVICES :
globals.KNOWN_DEVICES[uuid]['online'] = True
globals.KNOWN_DEVICES[uuid]['lastScan'] = current_time
Expand Down Expand Up @@ -702,32 +723,30 @@ def scanner(name):
globals.KNOWN_DEVICES[known]['online'] = False
globals.KNOWN_DEVICES[known]['lastOfflineSent'] = current_time
globals.KNOWN_DEVICES[known]['status'] = status = {
"uuid" : known,
"friendly_name" : "",
"is_stand_by" : False,
"app_id" : "",
"display_name" : "",
"status_text" : "",
"idle" : False,
"uuid" : known, "friendly_name" : "",
"is_stand_by" : False, "is_active_input" : False,
"app_id" : "", "display_name" : "", "status_text" : "",
"is_busy" : False,
}
#globals.JEEDOM_COM.add_changes('devices::'+known, globals.KNOWN_DEVICES[known])
globals.JEEDOM_COM.send_change_immediate_device(known, globals.KNOWN_DEVICES[known])
globals.KNOWN_DEVICES[known]['lastSent'] = current_time
if known in globals.NOWPLAYING_DEVICES:
del globals.NOWPLAYING_DEVICES[known]
data = {
"uuid" : known,
"online" : False, "friendly_name" : "",
"is_active_input" : False, "is_stand_by" : False,
"is_active_input" : False, "is_stand_by" : False,
"app_id" : "", "display_name" : "", "status_text" : "",
"idle" : False, "title" : "",
"album_artist" : "","metadata_type" : "",
"album_name" : "", "current_time" : 0,
"artist" : "", "image" : None,
'series_title': "", 'season': "", 'episode': "",
"is_busy" : False, "title" : "",
"album_artist" : "", "metadata_type" : "",
"album_name" : "", "current_time" : 0,
"artist" : "", "image" : None,
'series_title': "", 'season': "", 'episode': "",
"stream_type" : "", "track" : "",
"player_state" : "","supported_media_commands" : 0,
"supports_pause" : "", 'duration': 0,
'content_type': "", 'idle_reason': ""
"player_state" : "", "supported_media_commands" : 0,
"supports_pause" : "", "duration": 0,
"content_type": "", "idle_reason": ""
}
globals.JEEDOM_COM.send_change_immediate({'uuid' : known, 'nowplaying':data});

Expand Down
6 changes: 2 additions & 4 deletions resources/install_check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
rm -f /tmp/dependancycheck_googlecast
if ! python3 -V 2>&1 | grep -q "Python 3"; then
echo "nok"
exit 0
Expand All @@ -8,18 +7,17 @@ pip3cmd=$(compgen -ac | grep -E '^pip-?3' | sort -r | head -1)
if [[ ! -z $pip3cmd ]]; then # pip3 found
$(sudo $pip3cmd list 2>/dev/null | grep -E "zeroconf|requests|protobuf" | wc -l > /tmp/dependancycheck_googlecast)
content=$(cat /tmp/dependancycheck_googlecast 2>/dev/null)
rm -f /tmp/dependancycheck_googlecast
if [[ -z $content ]]; then
$content = 0
content=0
fi
if [ "$content" -lt 3 ];then
echo "nok"
rm -f /tmp/dependancycheck_googlecast
exit 0
fi
else
echo "nok"
exit 0
fi
echo "ok"
rm -f /tmp/dependancycheck_googlecast
exit 0
4 changes: 0 additions & 4 deletions resources/jeedom/jeedom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
from datetime import datetime
import collections
import os
from os.path import join
import socket
from multiprocessing import Queue
import socketserver as SocketServer
from socketserver import (TCPServer, StreamRequestHandler)
import signal
import unicodedata


# ------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 472a4ab

Please sign in to comment.