-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Frontier silicon async #12503
Merged
Merged
Frontier silicon async #12503
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f0166bf
Moving frontier_silicon platform to afspai(async fsapi)
zhelev 182ef88
updated requirements_all.txt
zhelev 8abdcce
uses afsapi 0.0.2, which supports timeout
zhelev c524e80
uses afsapi 0.0.3, forward(before next) and rewind(before prev) renamed
zhelev 9d3a7a7
Moving frontier_silicon platform to afspai(async fsapi)
zhelev bd06861
updated requirements_all.txt
zhelev d356718
uses afsapi 0.0.2, which supports timeout
zhelev 329780f
uses afsapi 0.0.3, forward(before next) and rewind(before prev) renamed
zhelev 96ad3d1
Merge branch 'frontier_silicon_async' of https://github.com/zhelev/ho…
zhelev 4127594
Removing debug message
zhelev eff27d6
removed time import
zhelev 4725b30
Update frontier_silicon.py
pvizeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
""" | ||
import logging | ||
|
||
import asyncio | ||
import time | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.components.media_player import ( | ||
|
@@ -19,7 +22,7 @@ | |
CONF_HOST, CONF_PORT, CONF_PASSWORD) | ||
import homeassistant.helpers.config_validation as cv | ||
|
||
REQUIREMENTS = ['fsapi==0.0.7'] | ||
REQUIREMENTS = ['afsapi==0.0.3'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
@@ -41,14 +44,15 @@ | |
|
||
|
||
# pylint: disable=unused-argument | ||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
@asyncio.coroutine | ||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | ||
"""Set up the Frontier Silicon platform.""" | ||
import requests | ||
|
||
if discovery_info is not None: | ||
add_devices( | ||
[FSAPIDevice(discovery_info['ssdp_description'], | ||
DEFAULT_PASSWORD)], | ||
async_add_devices( | ||
[AFSAPIDevice(discovery_info['ssdp_description'], | ||
DEFAULT_PASSWORD)], | ||
update_before_add=True) | ||
return True | ||
|
||
|
@@ -57,8 +61,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): | |
password = config.get(CONF_PASSWORD) | ||
|
||
try: | ||
add_devices( | ||
[FSAPIDevice(DEVICE_URL.format(host, port), password)], | ||
async_add_devices( | ||
[AFSAPIDevice(DEVICE_URL.format(host, port), password)], | ||
update_before_add=True) | ||
_LOGGER.debug("FSAPI device %s:%s -> %s", host, port, password) | ||
return True | ||
|
@@ -69,7 +73,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): | |
return False | ||
|
||
|
||
class FSAPIDevice(MediaPlayerDevice): | ||
class AFSAPIDevice(MediaPlayerDevice): | ||
"""Representation of a Frontier Silicon device on the network.""" | ||
|
||
def __init__(self, device_url, password): | ||
|
@@ -97,9 +101,9 @@ def fs_device(self): | |
connected to the device in between the updates and invalidated the | ||
existing session (i.e UNDOK). | ||
""" | ||
from fsapi import FSAPI | ||
from afsapi import AFSAPI | ||
|
||
return FSAPI(self._device_url, self._password) | ||
return AFSAPI(self._device_url, self._password) | ||
|
||
@property | ||
def should_poll(self): | ||
|
@@ -157,17 +161,19 @@ def media_image_url(self): | |
"""Image url of current playing media.""" | ||
return self._media_image_url | ||
|
||
def update(self): | ||
@asyncio.coroutine | ||
def async_update(self): | ||
"""Get the latest date and update device state.""" | ||
start = time.time() | ||
fs_device = self.fs_device | ||
|
||
if not self._name: | ||
self._name = fs_device.friendly_name | ||
self._name = yield from fs_device.get_friendly_name() | ||
|
||
if not self._source_list: | ||
self._source_list = fs_device.mode_list | ||
self._source_list = yield from fs_device.get_mode_list() | ||
|
||
status = fs_device.play_status | ||
status = yield from fs_device.get_play_status() | ||
self._state = { | ||
'playing': STATE_PLAYING, | ||
'paused': STATE_PAUSED, | ||
|
@@ -176,78 +182,105 @@ def update(self): | |
None: STATE_OFF, | ||
}.get(status, STATE_UNKNOWN) | ||
|
||
info_name = fs_device.play_info_name | ||
info_text = fs_device.play_info_text | ||
if self._state != STATE_OFF: | ||
info_name = yield from fs_device.get_play_name() | ||
info_text = yield from fs_device.get_play_text() | ||
|
||
self._title = ' - '.join(filter(None, [info_name, info_text])) | ||
self._artist = yield from fs_device.get_play_artist() | ||
self._album_name = yield from fs_device.get_play_album() | ||
|
||
self._source = yield from fs_device.get_mode() | ||
self._mute = yield from fs_device.get_mute() | ||
self._media_image_url = yield from fs_device.get_play_graphic() | ||
else: | ||
self._title = None | ||
self._artist = None | ||
self._album_name = None | ||
|
||
self._title = ' - '.join(filter(None, [info_name, info_text])) | ||
self._artist = fs_device.play_info_artist | ||
self._album_name = fs_device.play_info_album | ||
self._source = None | ||
self._mute = None | ||
self._media_image_url = None | ||
|
||
self._source = fs_device.mode | ||
self._mute = fs_device.mute | ||
self._media_image_url = fs_device.play_info_graphics | ||
end = time.time() | ||
_LOGGER.debug('Frontier Silicon device update took: %s', (end-start)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this debug time handling stuff |
||
|
||
# Management actions | ||
|
||
# power control | ||
def turn_on(self): | ||
@asyncio.coroutine | ||
def async_turn_on(self): | ||
"""Turn on the device.""" | ||
self.fs_device.power = True | ||
yield from self.fs_device.set_power(True) | ||
|
||
def turn_off(self): | ||
@asyncio.coroutine | ||
def async_turn_off(self): | ||
"""Turn off the device.""" | ||
self.fs_device.power = False | ||
yield from self.fs_device.set_power(False) | ||
|
||
def media_play(self): | ||
@asyncio.coroutine | ||
def async_media_play(self): | ||
"""Send play command.""" | ||
self.fs_device.play() | ||
yield from self.fs_device.play() | ||
|
||
def media_pause(self): | ||
@asyncio.coroutine | ||
def async_media_pause(self): | ||
"""Send pause command.""" | ||
self.fs_device.pause() | ||
yield from self.fs_device.pause() | ||
|
||
def media_play_pause(self): | ||
@asyncio.coroutine | ||
def async_media_play_pause(self): | ||
"""Send play/pause command.""" | ||
if 'playing' in self._state: | ||
self.fs_device.pause() | ||
yield from self.fs_device.pause() | ||
else: | ||
self.fs_device.play() | ||
yield from self.fs_device.play() | ||
|
||
def media_stop(self): | ||
@asyncio.coroutine | ||
def async_media_stop(self): | ||
"""Send play/pause command.""" | ||
self.fs_device.pause() | ||
yield from self.fs_device.pause() | ||
|
||
def media_previous_track(self): | ||
@asyncio.coroutine | ||
def async_media_previous_track(self): | ||
"""Send previous track command (results in rewind).""" | ||
self.fs_device.prev() | ||
yield from self.fs_device.rewind() | ||
|
||
def media_next_track(self): | ||
@asyncio.coroutine | ||
def async_media_next_track(self): | ||
"""Send next track command (results in fast-forward).""" | ||
self.fs_device.next() | ||
yield from self.fs_device.forward() | ||
|
||
# mute | ||
@property | ||
def is_volume_muted(self): | ||
"""Boolean if volume is currently muted.""" | ||
return self._mute | ||
|
||
def mute_volume(self, mute): | ||
@asyncio.coroutine | ||
def async_mute_volume(self, mute): | ||
"""Send mute command.""" | ||
self.fs_device.mute = mute | ||
yield from self.fs_device.set_mute(mute) | ||
|
||
# volume | ||
def volume_up(self): | ||
@asyncio.coroutine | ||
def async_volume_up(self): | ||
"""Send volume up command.""" | ||
self.fs_device.volume += 1 | ||
volume = yield from self.fs_device.get_volume() | ||
yield from self.fs_device.set_volume(volume+1) | ||
|
||
def volume_down(self): | ||
@asyncio.coroutine | ||
def async_volume_down(self): | ||
"""Send volume down command.""" | ||
self.fs_device.volume -= 1 | ||
volume = yield from self.fs_device.get_volume() | ||
yield from self.fs_device.set_volume(volume-1) | ||
|
||
def set_volume_level(self, volume): | ||
@asyncio.coroutine | ||
def async_set_volume_level(self, volume): | ||
"""Set volume command.""" | ||
self.fs_device.volume = volume | ||
yield from self.fs_device.set_volume(volume) | ||
|
||
def select_source(self, source): | ||
@asyncio.coroutine | ||
def async_select_source(self, source): | ||
"""Select input source.""" | ||
self.fs_device.mode = source | ||
yield from self.fs_device.set_mode(source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'time' imported but unused