Skip to content

Commit

Permalink
Merge branch 'release-0.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisNT committed Mar 21, 2020
2 parents 404fb7f + 5e3b1fd commit ca7fe9a
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 171 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
@@ -1,16 +1,19 @@
language: python
sudo: true
os: linux
dist: bionic

python:
- "2.7_with_system_site_packages"
- "3.7"

env:
- TOX_ENV=py27
- TOX_ENV=py37
- TOX_ENV=flake8

before_install:
- sudo apt-get update
- sudo apt-get install -y python-gi python-gst-1.0 gir1.2-gstreamer-1.0 gir1.2-gst-plugins-base-1.0 gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-tools
# Mock Python gi package
- export PYUSRSITEDIR=$(python -m site --user-site)
- mkdir -p $PYUSRSITEDIR
- "echo \"import sys; import mock; sys.modules['gi'] = mock.Mock(); sys.modules['gi.repository'] = mock.Mock(); sys.modules['gi.repository'].Gst.version.side_effect = lambda: (1, 14, 0)\" > ${PYUSRSITEDIR}/usercustomize.py"

install:
- "pip install tox"
Expand All @@ -19,4 +22,4 @@ script:
- "tox -e $TOX_ENV"

after_success:
- "if [ $TOX_ENV == 'py27' ]; then pip install coveralls requests==2.2.1; coveralls; fi"
- "if [ $TOX_ENV == 'py37' ]; then pip install coveralls requests; coveralls; fi"
7 changes: 6 additions & 1 deletion README.rst
Expand Up @@ -62,7 +62,7 @@ License
::

Copyright 2014 Mathieu Xhonneux
Copyright 2015-2018 Davis Mosenkovs
Copyright 2015-2020 Davis Mosenkovs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -88,6 +88,11 @@ Project resources
Changelog
=========

v0.1.8
----------------------------------------

- Upgraded to Mopidy 3.0+ and Python 3.7+.

v0.1.7
----------------------------------------

Expand Down
10 changes: 4 additions & 6 deletions mopidy_alarmclock/__init__.py
@@ -1,14 +1,12 @@
from __future__ import unicode_literals

import os
from http import MessageStore, factory_decorator

from alarm_manager import AlarmManager

from mopidy import config, ext

from .alarm_manager import AlarmManager
from .http import MessageStore, factory_decorator


__version__ = '0.1.7'
__version__ = '0.1.8'


class Extension(ext.Extension):
Expand Down
29 changes: 13 additions & 16 deletions mopidy_alarmclock/alarm_manager.py
@@ -1,6 +1,3 @@
from __future__ import division
from __future__ import unicode_literals

import datetime
import logging
import os
Expand Down Expand Up @@ -95,22 +92,22 @@ def play(self, fallback=False):
if fallback:
raise Exception('Fallback')
self.core.tracklist.add(self.get_playlist().tracks)
if self.core.tracklist.length.get() < 1:
if self.core.tracklist.get_length().get() < 1:
raise Exception('Tracklist empty')
except Exception as e:
self.logger.info("AlarmClock using backup alarm, reason: %s", e)
self.core.tracklist.add(None, 0, 'file://' + os.path.join(os.path.dirname(__file__), 'backup-alarm.mp3'))
self.core.tracklist.add(None, 0, ['file://' + os.path.join(os.path.dirname(__file__), 'backup-alarm.mp3')])

self.core.tracklist.consume = False
self.core.tracklist.single = False
self.core.tracklist.repeat = True
self.core.tracklist.set_consume(False)
self.core.tracklist.set_single(False)
self.core.tracklist.set_repeat(True)

self.core.tracklist.random = self.random_mode
if self.core.tracklist.random:
self.core.tracklist.set_random(self.random_mode)
if self.random_mode:
self.core.playback.next()

self.core.playback.mute = False
self.core.playback.volume = 0
self.core.mixer.set_mute(False)
self.core.mixer.set_volume(0)

self.core.playback.play()

Expand All @@ -121,7 +118,7 @@ def play(self, fallback=False):
try:
starttime = monotonic.monotonic()
time.sleep(0.5)
while self.core.playback.state.get() != PlaybackState.PLAYING or self.core.playback.time_position.get() < 100: # in some cases this check will cause a notable delay
while self.core.playback.get_state().get() != PlaybackState.PLAYING or self.core.playback.get_time_position().get() < 100: # in some cases this check will cause a notable delay
self.logger.info("AlarmClock has been waiting for %.2f seconds (waited inside AlarmClock %.2f sec)", monotonic.monotonic() - starttime, waited)
if waited > 30 or (waited > 0.5 and monotonic.monotonic() - starttime > 30): # ensure EITHER delay is more than 30 seconds OR at least 2 times above line has been executed
raise Exception("Timeout")
Expand Down Expand Up @@ -151,15 +148,15 @@ def adjust_volume(self, target_volume, increase_duration, step_no):
number_of_steps = min(target_volume, increase_duration)
current_volume = None
try:
current_volume = self.core.playback.volume.get()
current_volume = self.core.mixer.get_volume().get()
except Exception:
pass
if step_no == 0 or not isinstance(current_volume, int) or current_volume == int(round(target_volume * (step_no) / (number_of_steps + 1))):
if step_no >= number_of_steps: # this design should prevent floating-point edge-case bugs (in case such bugs could be possible here)
self.logger.info("AlarmClock increasing volume to target volume %d", target_volume)
self.core.playback.volume = target_volume
self.core.mixer.set_volume(target_volume)
else:
self.logger.info("AlarmClock increasing volume to %d", int(round(target_volume * (step_no + 1) / (number_of_steps + 1))))
self.core.playback.volume = int(round(target_volume * (step_no + 1) / (number_of_steps + 1)))
self.core.mixer.set_volume(int(round(target_volume * (step_no + 1) / (number_of_steps + 1))))
t = Timer(increase_duration / number_of_steps, self.adjust_volume, [target_volume, increase_duration, step_no + 1])
t.start()
12 changes: 5 additions & 7 deletions mopidy_alarmclock/http.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import datetime
import os
import re
Expand All @@ -12,9 +10,9 @@
template_loader = tornado.template.Loader(template_directory)

MESSAGES = {
'ok': (u'Alarm has been properly set.', 'success'),
'format': (u'The date\'s format you specified is incorrect.', 'danger'),
'cancel': (u'Alarm has been canceled.', 'success'),
'ok': ('Alarm has been properly set.', 'success'),
'format': ('The date\'s format you specified is incorrect.', 'danger'),
'cancel': ('Alarm has been canceled.', 'success'),
}


Expand All @@ -37,7 +35,7 @@ def get(self):
message = MESSAGES[self.msg_store.msg_code]
self.msg_store.msg_code = None

playlists = self.core.playlists.playlists.get()
playlists = self.core.playlists.as_list().get()

self.write(template_loader.load('index.html').generate(
playlists=playlists,
Expand Down Expand Up @@ -65,7 +63,7 @@ def post(self):
volume_increase_seconds = 30

if matched:
time_comp = map(lambda x: int(x), matched.groups())
time_comp = [int(x) for x in matched.groups()]
time = datetime.time(hour=time_comp[0], minute=time_comp[1])

dt = datetime.datetime.combine(datetime.datetime.now(), time)
Expand Down
7 changes: 3 additions & 4 deletions setup.py
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import re

from setuptools import find_packages, setup
Expand All @@ -25,9 +23,10 @@ def get_version(filename):
packages=find_packages(exclude=['tests', 'tests.*']),
zip_safe=False,
include_package_data=True,
python_requires='>= 3.7',
install_requires=[
'setuptools',
'Mopidy >= 0.19',
'Mopidy >= 3.0',
'Pykka >= 1.1',
'monotonic >= 1.4',
],
Expand All @@ -46,7 +45,7 @@ def get_version(filename):
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Multimedia :: Sound/Audio :: Players',
],
)

0 comments on commit ca7fe9a

Please sign in to comment.