From 06361b1ed15443dc211c3b5bfc313967a678f14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Vran=C3=ADk?= Date: Sat, 21 Jan 2017 23:13:46 +0100 Subject: [PATCH] implementing users remarks (#5481) * cec client object * cec command structure * autodetect source * volume support and native source select * switch device * media player device * detecting of state * friendly names * hdmi cec properties * presence detection * simplified callbacks * stable names * renamed methods * code cleanup * name with vendor * fixed standby call name * fake standby/poweron * domain switch * domain switch * async updating * update separated * cec -> hass event bridge * fixed name generation * code cleanup * code cleanup * icon constants * code cleanup * do not register unavailable devices * discovery of deevices * code cleanup * cec device discovery * moved method implementation into child * service descriptions * service descriptions * service descriptions * changed entity init sequence * logging cleanup * add remove as job * closing cec, no service schemas * correct iterate over dictionary * Volume by commands * threading * logging minimized * get load out of main thread * naming cleanup * get load out of main thread * optimized discovery * async where possible * cleanup logging, constructors first * pydoc * formatting * no async_update from out of loop no hiding entities removed redundant device_state_attributes async updating presence * no async * working async cec * cec in thirdparty lib * cec initialized oudsice * working without SIGSEGV * rollbacked file changed by mistake * sending of commands * working with ha * using hass loop and device driven updates * version up * version up * Command types in pycec, cleanup for HA integration * Removed media player, state moved to switch * service descriptions * requirements: pyCEC * line width to 79 * doc * doc * overindentation solved * HDMI to uppercase * minimal dependency on cec * removed unwanted line * doc wording * margin 79 * line continuation indent * imperative doc * lint: indentation * fixed overindented * fixed overindented * fixed overindented * fixed overindented * order of imports * PEP8 * keep signature of overriding * removed redundant blank line * fixed update call method (#4) * Preparation for merge to upstream (#5) * newer version of pyCEC * updated services.yaml * fixed lint scrpt to operate only on python files * pycec version up * update services * no coverage report * exclude non python files from lint * lint only on python files * Dev (#6) * reordered * sending nonserialized data through hass.data * code formatting * code formatting * import order * Dev (#7) * newer version of pyCEC * updated services.yaml * fixed lint scrpt to operate only on python files * pycec version up * update services * no coverage report * exclude non python files from lint * lint only on python files * reordered * sending nonserialized data through hass.data * import order * fixed object handling * code formatting * Backwards compatibility of hdmi_cec (#10) * services: power_on standby active_source * new version of pyCEC (#12) * newer version of pyCEC * devices config (#13) * getting device name from config * shutdown fix (#14) * correct call on shutdown * remove misplaced annotations (#15) * Preparation for merge to upstream (#5) * newer version of pyCEC * updated services.yaml * reordered * sending nonserialized data through hass.data * services: power_on standby active_source * code formatting * getting device name from config * correct call on shutdown * pyCEC version 0.3.6 (#18) * newer version of pyCEC * updated services.yaml * sending nonserialized data through hass.data * services: ** power_on ** standby ** active_source * getting device name from config * correct call on shutdown * fork new thread on multicore machines * support both config schemas: original and new (#16) * volume press and release support (#17) * support for media_player (#21) * accept hexadecimal format of commands * support for media player * platform customization * type constants * Dev (#23) * accept hexadecimal format of commands * support for media player * platform customization * TCP CEC support (#24) * accept hexadecimal format of commands * support for media player * platform customization * preparing tcp support * volume handling (#25) * Incorporated CR remarks (#26) * cleanup imports * cleanup and enhance services description * removed unwanted file * implemented CR remarks (#27) * pyCEC v0.4.6 * pined dependency version * tighten service schemas * requirements (#28) * incorporate remarks from users (#32) * home-assistant-31 make mute schema better (#31) * pycec-30 pyCEC version up (#30) * pycec-30 pyCEC version up (#30) * home-assistant-30 OSD display name from configuration (#30) (#33) * Home assistant 29 (#34) * home-assistant-29 counting from 0 (#29) * Home assistant 31 (#35) * home-assistant-31 add support for mute-on and mute-off (#31) * home-assistant-31 pyCEC version up (#31) * Home assistant 31 (#36) * home-assistant-31 Limit OSD name to 13 chars (#31) * home-assistant-31 Limit OSD name to 13 chars moved to CEC adapter (#31) * home-assistant-31 version up (#31) * home-assistant-31 formatting (#31) * formatting * service description * service description * single attribute for volume * fixed mute on -> mute off * moved config constant from core into component --- homeassistant/components/hdmi_cec.py | 31 +++++++++++++------ .../components/media_player/hdmi_cec.py | 4 +-- homeassistant/components/services.yaml | 6 ++-- requirements_all.txt | 2 +- 4 files changed, 27 insertions(+), 16 deletions(-) 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