mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Support eco mode option on Ziggo Mediabox XL (#17990)
* Added eco mode option to Ziggo Mediabox XL * Changed eco_mode_on to eco_mode * Removed eco_mode option, the player is unavailable when offline * Timeout on connection, on/off states are handled via update * Improved state detection and added available property
This commit is contained in:
parent
c6f3c239bb
commit
114bc8ec18
@ -14,10 +14,10 @@ from homeassistant.components.media_player import (
|
|||||||
SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE, SUPPORT_TURN_OFF,
|
SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE, SUPPORT_TURN_OFF,
|
||||||
SUPPORT_TURN_ON, MediaPlayerDevice)
|
SUPPORT_TURN_ON, MediaPlayerDevice)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_PAUSED, STATE_PLAYING)
|
CONF_HOST, CONF_NAME, STATE_OFF, STATE_PAUSED, STATE_PLAYING)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['ziggo-mediabox-xl==1.0.0']
|
REQUIREMENTS = ['ziggo-mediabox-xl==1.1.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -43,9 +43,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
if config.get(CONF_HOST) is not None:
|
if config.get(CONF_HOST) is not None:
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
manual_config = True
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
host = discovery_info.get('host')
|
host = discovery_info.get('host')
|
||||||
name = discovery_info.get('name')
|
name = discovery_info.get('name')
|
||||||
|
manual_config = False
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Cannot determine device")
|
_LOGGER.error("Cannot determine device")
|
||||||
return
|
return
|
||||||
@ -53,15 +55,26 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
# Only add a device once, so discovered devices do not override manual
|
# Only add a device once, so discovered devices do not override manual
|
||||||
# config.
|
# config.
|
||||||
hosts = []
|
hosts = []
|
||||||
|
connection_successful = False
|
||||||
ip_addr = socket.gethostbyname(host)
|
ip_addr = socket.gethostbyname(host)
|
||||||
if ip_addr not in known_devices:
|
if ip_addr not in known_devices:
|
||||||
try:
|
try:
|
||||||
mediabox = ZiggoMediaboxXL(ip_addr)
|
# Mediabox instance with a timeout of 3 seconds.
|
||||||
|
mediabox = ZiggoMediaboxXL(ip_addr, 3)
|
||||||
|
# Check if a connection can be established to the device.
|
||||||
if mediabox.test_connection():
|
if mediabox.test_connection():
|
||||||
hosts.append(ZiggoMediaboxXLDevice(mediabox, host, name))
|
connection_successful = True
|
||||||
known_devices.add(ip_addr)
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Can't connect to %s", host)
|
if manual_config:
|
||||||
|
_LOGGER.info("Can't connect to %s", host)
|
||||||
|
else:
|
||||||
|
_LOGGER.error("Can't connect to %s", host)
|
||||||
|
# When the device is in eco mode it's not connected to the network
|
||||||
|
# so it needs to be added anyway if it's configured manually.
|
||||||
|
if manual_config or connection_successful:
|
||||||
|
hosts.append(ZiggoMediaboxXLDevice(mediabox, host, name,
|
||||||
|
connection_successful))
|
||||||
|
known_devices.add(ip_addr)
|
||||||
except socket.error as error:
|
except socket.error as error:
|
||||||
_LOGGER.error("Can't connect to %s: %s", host, error)
|
_LOGGER.error("Can't connect to %s: %s", host, error)
|
||||||
else:
|
else:
|
||||||
@ -72,24 +85,29 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
||||||
"""Representation of a Ziggo Mediabox XL Device."""
|
"""Representation of a Ziggo Mediabox XL Device."""
|
||||||
|
|
||||||
def __init__(self, mediabox, host, name):
|
def __init__(self, mediabox, host, name, available):
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
# Generate a configuration for the Samsung library
|
|
||||||
self._mediabox = mediabox
|
self._mediabox = mediabox
|
||||||
self._host = host
|
self._host = host
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._available = available
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Retrieve the state of the device."""
|
"""Retrieve the state of the device."""
|
||||||
try:
|
try:
|
||||||
if self._mediabox.turned_on():
|
if self._mediabox.test_connection():
|
||||||
if self._state != STATE_PAUSED:
|
if self._mediabox.turned_on():
|
||||||
self._state = STATE_PLAYING
|
if self._state != STATE_PAUSED:
|
||||||
|
self._state = STATE_PLAYING
|
||||||
|
else:
|
||||||
|
self._state = STATE_OFF
|
||||||
|
self._available = True
|
||||||
else:
|
else:
|
||||||
self._state = STATE_OFF
|
self._available = False
|
||||||
except socket.error:
|
except socket.error:
|
||||||
_LOGGER.error("Couldn't fetch state from %s", self._host)
|
_LOGGER.error("Couldn't fetch state from %s", self._host)
|
||||||
|
self._available = False
|
||||||
|
|
||||||
def send_keys(self, keys):
|
def send_keys(self, keys):
|
||||||
"""Send keys to the device and handle exceptions."""
|
"""Send keys to the device and handle exceptions."""
|
||||||
@ -108,6 +126,11 @@ class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
|||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if the device is available."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_list(self):
|
def source_list(self):
|
||||||
"""List of available sources (channels)."""
|
"""List of available sources (channels)."""
|
||||||
@ -122,12 +145,10 @@ class ZiggoMediaboxXLDevice(MediaPlayerDevice):
|
|||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
self.send_keys(['POWER'])
|
self.send_keys(['POWER'])
|
||||||
self._state = STATE_ON
|
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
self.send_keys(['POWER'])
|
self.send_keys(['POWER'])
|
||||||
self._state = STATE_OFF
|
|
||||||
|
|
||||||
def media_play(self):
|
def media_play(self):
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
|
@ -1617,7 +1617,7 @@ zeroconf==0.21.3
|
|||||||
zhong_hong_hvac==1.0.9
|
zhong_hong_hvac==1.0.9
|
||||||
|
|
||||||
# homeassistant.components.media_player.ziggo_mediabox_xl
|
# homeassistant.components.media_player.ziggo_mediabox_xl
|
||||||
ziggo-mediabox-xl==1.0.0
|
ziggo-mediabox-xl==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.zha
|
# homeassistant.components.zha
|
||||||
zigpy-xbee==0.1.1
|
zigpy-xbee==0.1.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user