Skip to content

Commit

Permalink
implementing users remarks (home-assistant#5481)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
konikvranik authored and balloob committed Jan 21, 2017
1 parent a89a4f3 commit 06361b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
31 changes: 21 additions & 10 deletions homeassistant/components/hdmi_cec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))

Expand All @@ -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'
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -175,22 +181,27 @@ 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)
elif cmd == CMD_DOWN:
_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")
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/media_player/hdmi_cec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06361b1

Please sign in to comment.