mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fixes imports, styles and other misstates
This commit is contained in:
parent
bd475f5db1
commit
2dab815f90
@ -8,7 +8,6 @@ https://home-assistant.io/components/media_player.samsungtv/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
from samsungctl import Remote
|
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerDevice, SUPPORT_PAUSE, SUPPORT_VOLUME_STEP,
|
MediaPlayerDevice, SUPPORT_PAUSE, SUPPORT_VOLUME_STEP,
|
||||||
@ -16,11 +15,16 @@ from homeassistant.components.media_player import (
|
|||||||
SUPPORT_NEXT_TRACK, SUPPORT_TURN_OFF,
|
SUPPORT_NEXT_TRACK, SUPPORT_TURN_OFF,
|
||||||
DOMAIN)
|
DOMAIN)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, STATE_OFF,
|
CONF_HOST, CONF_NAME, STATE_OFF,
|
||||||
STATE_ON, STATE_UNKNOWN)
|
STATE_ON, STATE_UNKNOWN)
|
||||||
|
|
||||||
|
CONF_PORT = "port"
|
||||||
|
CONF_TIMEOUT = "timeout"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
REQUIREMENTS = ['samsungctl==0.5.1']
|
||||||
|
|
||||||
SUPPORT_SAMSUNGTV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
SUPPORT_SAMSUNGTV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
||||||
SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | \
|
SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | \
|
||||||
SUPPORT_NEXT_TRACK | SUPPORT_TURN_OFF
|
SUPPORT_NEXT_TRACK | SUPPORT_TURN_OFF
|
||||||
@ -28,7 +32,8 @@ SUPPORT_SAMSUNGTV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Sets up the Denon platform. """
|
""" Sets up the Samsung TV platform. """
|
||||||
|
|
||||||
if not config.get(CONF_HOST):
|
if not config.get(CONF_HOST):
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Missing required configuration items in %s: %s",
|
"Missing required configuration items in %s: %s",
|
||||||
@ -39,26 +44,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
# Generate a config for the Samsung lib
|
# Generate a config for the Samsung lib
|
||||||
remote_config = {
|
remote_config = {
|
||||||
"name": "HomeAssistant",
|
"name": "HomeAssistant",
|
||||||
"description": config.get("name", ''),
|
"description": config.get(CONF_NAME, ''),
|
||||||
"id": "ha.component.samsung",
|
"id": "ha.component.samsung",
|
||||||
"port": config.get("port", 55000),
|
"port": config.get(CONF_PORT, 55000),
|
||||||
"host": config.get("host"),
|
"host": config.get(CONF_HOST),
|
||||||
"timeout": config.get("timeout", 0),
|
"timeout": config.get(CONF_TIMEOUT, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
add_devices([SamsungTVDevice(name, remote_config)])
|
add_devices([SamsungTVDevice(name, remote_config)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=abstract-method
|
||||||
class SamsungTVDevice(MediaPlayerDevice):
|
class SamsungTVDevice(MediaPlayerDevice):
|
||||||
""" Represents a Denon device. """
|
""" Represents a Samsung TV. """
|
||||||
|
|
||||||
def set_volume_level(self, volume):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
|
|
||||||
def __init__(self, name, config):
|
def __init__(self, name, config):
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
# Assume that the TV is not muted
|
# Assume that the TV is not muted
|
||||||
self._muted = False
|
self._muted = False
|
||||||
@ -74,6 +76,8 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def get_remote(self):
|
def get_remote(self):
|
||||||
""" Creates or Returns a remote control instance """
|
""" Creates or Returns a remote control instance """
|
||||||
|
from samsungctl import Remote
|
||||||
|
|
||||||
if self._remote is None:
|
if self._remote is None:
|
||||||
# We need to create a new instance to reconnect.
|
# We need to create a new instance to reconnect.
|
||||||
self._remote = Remote(self._config)
|
self._remote = Remote(self._config)
|
||||||
@ -82,6 +86,7 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def send_key(self, key):
|
def send_key(self, key):
|
||||||
""" Sends a key to the tv and handles exceptions """
|
""" Sends a key to the tv and handles exceptions """
|
||||||
|
from samsungctl import Remote
|
||||||
try:
|
try:
|
||||||
self.get_remote().control(key)
|
self.get_remote().control(key)
|
||||||
self._state = STATE_ON
|
self._state = STATE_ON
|
||||||
@ -92,14 +97,11 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
self._state = STATE_ON
|
self._state = STATE_ON
|
||||||
self._remote = None
|
self._remote = None
|
||||||
return False
|
return False
|
||||||
except (Remote.ConnectionClosed, Remote.ConnectionClosed,
|
except (Remote.ConnectionClosed, socket.timeout,
|
||||||
socket.timeout, TimeoutError, OSError):
|
TimeoutError, OSError):
|
||||||
self._state = STATE_OFF
|
self._state = STATE_OFF
|
||||||
self._remote = None
|
self._remote = None
|
||||||
return False
|
return False
|
||||||
except Remote.AccessDenied:
|
|
||||||
self._state = STATE_ON
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -161,15 +163,6 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
self.send_key("KEY_REWIND")
|
self.send_key("KEY_REWIND")
|
||||||
|
|
||||||
def media_seek(self, position):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
""" turn the media player on. """
|
""" turn the media player on. """
|
||||||
self.send_key("KEY_POWERON")
|
self.send_key("KEY_POWERON")
|
||||||
|
|
||||||
def play_media(self, media_type, media_id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def play_youtube(self, media_id):
|
|
||||||
pass
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user