-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Adding enigma2 media player #15799
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
Adding enigma2 media player #15799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
| }) | ||
|
|
||
|
|
||
| # pylint: disable=unused-argument | ||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Setup the Enigma2 TV platform.""" | ||
| name = config.get(CONF_NAME) | ||
|
Member
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. Don't use |
||
|
|
||
| # 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 | ||
|
Member
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. This is already globally disabled. |
||
| class Enigma2Device(MediaPlayerDevice): | ||
| """Representation of a Enigma2 box.""" | ||
|
Member
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. "of an" |
||
|
|
||
| # pylint: disable=too-many-public-methods | ||
|
Member
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. Same as above. |
||
| def __init__(self, name, config): | ||
| """Initialize the Enigma2 device.""" | ||
| import openwebif.api | ||
| self._state = STATE_UNKNOWN | ||
|
Member
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. Init state to |
||
| # self.config = config | ||
|
Member
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. 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 | ||
|
Member
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.
|
||
| self.muted = False | ||
| self.picon_url = None | ||
|
|
||
| self.update() | ||
|
Member
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 and instead call |
||
|
|
||
| @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( | ||
|
Member
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. Supported features should not change during the lifetime of an entity. |
||
| 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: | ||
|
Member
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. 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() | ||
|
Member
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. 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] - " + \ | ||
|
Member
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. 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) | ||
|
Member
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. 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() | ||
|
Member
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. The |
||
|
|
||
| def update(self): | ||
| """Update state of the media_player.""" | ||
| _LOGGER.info("Updating...") | ||
|
Member
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. 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) | ||
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.
Is it necessary to have this configurable? We prefer to set a hardcoded sensible timeout, if possible.