Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ omit =
homeassistant/components/media_player/directv.py
homeassistant/components/media_player/dunehd.py
homeassistant/components/media_player/emby.py
homeassistant/components/media_player/enigma2.py
homeassistant/components/media_player/epson.py
homeassistant/components/media_player/firetv.py
homeassistant/components/media_player/frontier_silicon.py
Expand Down
220 changes: 220 additions & 0 deletions homeassistant/components/media_player/enigma2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
"""
Support for Enigma2 based media players.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.enigma2/
"""
import logging

import voluptuous as vol

from homeassistant.components.media_player import (
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_TURN_ON,
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
MediaPlayerDevice, PLATFORM_SCHEMA, MEDIA_TYPE_TVSHOW)
from homeassistant.const import (
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['openwebif.py==0.9']

_LOGGER = logging.getLogger(__name__)

CONF_TIMEOUT = 'timeout'

DEFAULT_NAME = 'Enigma2 Media Player'
DEFAULT_PORT = 80
DEFAULT_TIMEOUT = 0

# Support different items when watching recording playback
SUPPORT_ENIGMA2_RECORDING_PLAYBACK = SUPPORT_VOLUME_SET | \
SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_OFF | SUPPORT_PAUSE

SUPPORT_ENIGMA2_LIVE_TV = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_OFF | SUPPORT_NEXT_TRACK | \
SUPPORT_PREVIOUS_TRACK | SUPPORT_TURN_ON

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to have this configurable? We prefer to set a hardcoded sensible timeout, if possible.

})


# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Enigma2 TV platform."""
name = config.get(CONF_NAME)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use dict.get(key) on required config keys or keys that have default values. Use dict[key].


# Generate a configuration for the Enigma2 library
remote_config = {
'name': 'HomeAssistant',
'description': config.get(CONF_NAME),
'port': config.get(CONF_PORT),
'host': config.get(CONF_HOST),
'timeout': config.get(CONF_TIMEOUT),
}

add_devices([Enigma2Device(name, remote_config)])


# pylint: disable=abstract-method

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already globally disabled.

class Enigma2Device(MediaPlayerDevice):
"""Representation of a Enigma2 box."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"of an"


# pylint: disable=too-many-public-methods

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

def __init__(self, name, config):
"""Initialize the Enigma2 device."""
import openwebif.api
self._state = STATE_UNKNOWN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init state to None. The base entity class will handle unknown state.

# self.config = config

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale code?


self._name = name
self.e2_box = openwebif.api.CreateDevice(config['host'],
port=config['port'])

self.volume = 20
self.current_service_channel_name = None
self.current_programme_name = None
self.currservice_serviceref = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.current_service_ref

self.muted = False
self.picon_url = None

self.update()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and instead call add_devices with second argument True. That will call update during entity addition.


@property
def name(self):
"""Return the name of the device."""
return self._name

@property
def state(self):
"""Return the state of the device."""
return self._state

@property
def supported_features(self):
"""Flag of media commands that are supported."""
from openwebif.api import PlaybackType

if self.e2_box.get_current_playback_type(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supported features should not change during the lifetime of an entity.

See home-assistant/architecture#1.

self.currservice_serviceref) == PlaybackType.recording:
return SUPPORT_ENIGMA2_RECORDING_PLAYBACK

return SUPPORT_ENIGMA2_LIVE_TV

def turn_off(self):
"""Turn off media player."""
if self.state is STATE_ON:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String comparison is done using ==.

self.e2_box.toggle_standby()

def turn_on(self):
"""Turn the media player on."""
if self.state is STATE_OFF:
self.e2_box.toggle_standby()
self.update()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be called directly after the method call in the service handler. So we can remove this here.


@property
def media_title(self):
"""Title of current playing media."""
if self.currservice_serviceref.startswith('1:0:0'):
return "[Recording Playback] - " + \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use new style string formatting instead of string concatenation.

self.current_programme_name
if self.current_service_channel_name:
return self.current_programme_name + " - " + \
self.current_service_channel_name

return self.current_programme_name

@property
def media_channel(self):
"""Channel of current playing media."""
return self.current_service_channel_name

@property
def media_content_id(self):
"""Service Ref of current playing media."""
return self.currservice_serviceref

@property
def media_content_type(self):
"""Type of video currently playing."""
return MEDIA_TYPE_TVSHOW

@property
def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self.muted

@property
def media_image_url(self):
"""Picon url for the channel."""
return self.picon_url

def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
self.e2_box.set_volume(int(volume * 100))
self.volume = volume * 100

def volume_up(self):
"""Volume up the media player."""
self.volume += 5
self.e2_box.set_volume(self.volume)

def volume_down(self):
"""Volume down media player."""
self.volume -= 5
self.e2_box.set_volume(self.volume)

@property
def volume_level(self):
"""Volume level of the media player (0..1)."""
_LOGGER.info('self.volume : %s', self.volume)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug max. Please move this to a volume method instead, if it's really needed.

return self.volume / 100

def media_play_pause(self):
"""Pause media on media player."""
self.e2_box.toggle_play_pause()

def media_play(self):
"""Play media."""
self.e2_box.toggle_play_pause()

def media_pause(self):
"""Pause the media player."""
self.e2_box.toggle_play_pause()

def media_next_track(self):
"""Send next track command."""
self.e2_box.set_channel_up()

def media_previous_track(self):
"""Send next track command."""
self.e2_box.set_channel_down()

def mute_volume(self, mute):
"""Send mute command."""
self.e2_box.mute_volume()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mute parameter is a boolean saying if the muting should be true/on or false/off. Please implement that.


def update(self):
"""Update state of the media_player."""
_LOGGER.info("Updating...")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

status_info = self.e2_box.refresh_status_info()

if self.e2_box.is_box_in_standby():
self._state = STATE_OFF
else:
self._state = STATE_ON
self.current_service_channel_name = \
status_info['currservice_station']
pname = status_info['currservice_name']
self.current_programme_name = pname if pname != "N/A" else ""
self.currservice_serviceref = status_info['currservice_serviceref']
self.muted = status_info['muted']
self.volume = status_info['volume']
self.picon_url = \
self.e2_box.get_current_playing_picon_url(
channel_name=self.current_service_channel_name,
currservice_serviceref=self.currservice_serviceref)
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ openevsewifi==0.4
# homeassistant.components.media_player.openhome
openhomedevice==0.4.2

# homeassistant.components.media_player.enigma2
openwebif.py==0.9

# homeassistant.components.switch.orvibo
orvibo==1.1.1

Expand Down