diff --git a/homeassistant/components/hdmi_cec.py b/homeassistant/components/hdmi_cec.py index 44b205993b6ed..23c3fc011069e 100644 --- a/homeassistant/components/hdmi_cec.py +++ b/homeassistant/components/hdmi_cec.py @@ -26,12 +26,14 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['pyCEC==0.4.6'] +REQUIREMENTS = ['pyCEC==0.4.9'] DOMAIN = 'hdmi_cec' _LOGGER = logging.getLogger(__name__) +DEFAULT_DISPLAY_NAME = "HomeAssistant" + ICON_UNKNOWN = 'mdi:help' ICON_AUDIO = 'mdi:speaker' ICON_PLAYER = 'mdi:play' @@ -76,6 +78,9 @@ ATTR_DIR = 'dir' ATTR_ABT = 'abt' ATTR_NEW = 'new' +ATTR_ON = 'on' +ATTR_OFF = 'off' +ATTR_TOGGLE = 'toggle' _VOL_HEX = vol.Any(vol.Coerce(int), lambda x: int(x, 16)) @@ -92,9 +97,7 @@ SERVICE_VOLUME_SCHEMA = vol.Schema({ vol.Optional(CMD_UP): vol.Any(CMD_PRESS, CMD_RELEASE, vol.Coerce(int)), vol.Optional(CMD_DOWN): vol.Any(CMD_PRESS, CMD_RELEASE, vol.Coerce(int)), - vol.Optional(CMD_MUTE): None, - vol.Optional(CMD_UNMUTE): None, - vol.Optional(CMD_MUTE_TOGGLE): None + vol.Optional(CMD_MUTE): vol.Any(ATTR_ON, ATTR_OFF, ATTR_TOGGLE), }, extra=vol.PREVENT_EXTRA) SERVICE_UPDATE_DEVICES = 'update' @@ -118,6 +121,7 @@ SWITCH) }) +CONF_DISPLAY_NAME = 'osd_name' CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ vol.Optional(CONF_DEVICES): vol.Any(DEVICE_SCHEMA, @@ -127,6 +131,7 @@ })), vol.Optional(CONF_PLATFORM): vol.Any(SWITCH, MEDIA_PLAYER), vol.Optional(CONF_HOST): cv.string, + vol.Optional(CONF_DISPLAY_NAME): cv.string, }) }, extra=vol.ALLOW_EXTRA) @@ -156,8 +161,9 @@ def setup(hass: HomeAssistant, base_config): """Setup CEC capability.""" from pycec.network import HDMINetwork from pycec.commands import CecCommand, KeyReleaseCommand, KeyPressCommand - from pycec.const import KEY_VOLUME_UP, KEY_VOLUME_DOWN, KEY_MUTE, \ - ADDR_AUDIOSYSTEM, ADDR_BROADCAST, ADDR_UNREGISTERED + from pycec.const import KEY_VOLUME_UP, KEY_VOLUME_DOWN, KEY_MUTE_ON, \ + KEY_MUTE_OFF, KEY_MUTE_TOGGLE, ADDR_AUDIOSYSTEM, ADDR_BROADCAST, \ + ADDR_UNREGISTERED from pycec.cec import CecAdapter from pycec.tcp import TcpAdapter @@ -175,14 +181,18 @@ def setup(hass: HomeAssistant, base_config): # Create own thread if more than 1 CPU hass.loop if multiprocessing.cpu_count() < 2 else None) host = base_config[DOMAIN].get(CONF_HOST, None) + display_name = base_config[DOMAIN].get(CONF_DISPLAY_NAME, + DEFAULT_DISPLAY_NAME) if host: - adapter = TcpAdapter(host, name="HASS", activate_source=False) + adapter = TcpAdapter(host, name=display_name, activate_source=False) else: - adapter = CecAdapter(name="HASS", activate_source=False) + adapter = CecAdapter(name=display_name, activate_source=False) hdmi_network = HDMINetwork(adapter, loop=loop) def _volume(call): """Increase/decrease volume and mute/unmute system.""" + mute_key_mapping = {ATTR_TOGGLE: KEY_MUTE_TOGGLE, ATTR_ON: KEY_MUTE_ON, + ATTR_OFF: KEY_MUTE_OFF} for cmd, att in call.data.items(): if cmd == CMD_UP: _process_volume(KEY_VOLUME_UP, att) @@ -190,7 +200,8 @@ def _volume(call): _process_volume(KEY_VOLUME_DOWN, att) elif cmd == CMD_MUTE: hdmi_network.send_command( - KeyPressCommand(KEY_MUTE, dst=ADDR_AUDIOSYSTEM)) + KeyPressCommand(mute_key_mapping[att], + dst=ADDR_AUDIOSYSTEM)) hdmi_network.send_command( KeyReleaseCommand(dst=ADDR_AUDIOSYSTEM)) _LOGGER.info("Audio muted") @@ -207,7 +218,7 @@ def _process_volume(cmd, att): hdmi_network.send_command(KeyReleaseCommand(dst=ADDR_AUDIOSYSTEM)) else: att = 1 if att == "" else int(att) - for _ in range(1, att): + for _ in range(0, att): hdmi_network.send_command( KeyPressCommand(cmd, dst=ADDR_AUDIOSYSTEM)) hdmi_network.send_command( diff --git a/homeassistant/components/media_player/hdmi_cec.py b/homeassistant/components/media_player/hdmi_cec.py index 4998072018ed1..c7e9be562cc45 100644 --- a/homeassistant/components/media_player/hdmi_cec.py +++ b/homeassistant/components/media_player/hdmi_cec.py @@ -59,8 +59,8 @@ def send_playback(self, key): def mute_volume(self, mute): """Mute volume.""" - from pycec.const import KEY_MUTE - self.send_keypress(KEY_MUTE) + from pycec.const import KEY_MUTE_TOGGLE + self.send_keypress(KEY_MUTE_TOGGLE) def media_previous_track(self): """Go to previous track.""" diff --git a/homeassistant/components/services.yaml b/homeassistant/components/services.yaml index 53f82d5c05931..e42cd56cd8c8e 100644 --- a/homeassistant/components/services.yaml +++ b/homeassistant/components/services.yaml @@ -192,9 +192,9 @@ hdmi_cec: down: description: Decreases volume x levels. example: 3 - mute: Mutes audio system. Value is ignored. - unmute: Unmutes audio system. Value is ignored. - toggle mute: Toggles mute of audio system. Value is ignored. + mute: + description: Mutes audio system. Value should be on, off or toggle. + example: "toggle" select_device: description: Select HDMI device. diff --git a/requirements_all.txt b/requirements_all.txt index f97d00952602e..1b92e6b81c48c 100755 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -378,7 +378,7 @@ pwaqi==1.3 py-cpuinfo==0.2.3 # homeassistant.components.hdmi_cec -pyCEC==0.4.6 +pyCEC==0.4.9 # homeassistant.components.switch.tplink pyHS100==0.2.3