hass-core/homeassistant/components/switch/hdmi_cec.py
Petr Vraník 900868708e check cec message length when asking physical address ()
* 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 ()

* Preparation for merge to upstream ()

* 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 ()

* reordered
* sending nonserialized data through hass.data
* code formatting
* code formatting
* import order

* Dev ()

* 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 ()

* services:
power_on
standby
active_source

* new version of pyCEC ()

* newer version of pyCEC

* devices config ()

* getting device name from config

* shutdown fix ()


* correct call on shutdown

* remove misplaced annotations ()

* Preparation for merge to upstream ()

* 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 ()

* 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 ()
* volume press and release support ()

* support for media_player ()

* accept hexadecimal format of commands
* support for media player
* platform customization
* type constants

* Dev ()

* accept hexadecimal format of commands
* support for media player
* platform customization

* TCP CEC support ()

* accept hexadecimal format of commands
* support for media player
* platform customization
* preparing tcp support

* volume handling ()

* Incorporated CR remarks ()

* cleanup imports
* cleanup and enhance services description
* removed unwanted file

* implemented CR remarks ()

* pyCEC v0.4.6
* pined dependency version
* tighten service schemas

* requirements ()

* incorporate remarks from users ()

* home-assistant-31 make mute schema better ()

* pycec-30 pyCEC version up ()

* pycec-30 pyCEC version up ()

* home-assistant-30 OSD display name from configuration () ()

* Home assistant 29 ()

* home-assistant-29 counting from 0 ()

* Home assistant 31 ()

* home-assistant-31 add support for mute-on and mute-off ()

* home-assistant-31 pyCEC version up ()

* Home assistant 31 ()

* home-assistant-31 Limit OSD name to 13 chars ()

* home-assistant-31 Limit OSD name to 13 chars moved to CEC adapter ()

* home-assistant-31 version up ()

* home-assistant-31 formatting ()

* formatting

* service description

* service description

* single attribute for volume

* fixed mute on -> mute off

* moved config constant from core into component

* check cec message length when asking physical address () ()

* cec turn on/turn off commands instead of power

* cec turn on/turn off commands instead of power
2017-01-23 13:22:39 -08:00

71 lines
2.2 KiB
Python

"""
Support for HDMI CEC devices as switches.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/hdmi_cec/
"""
import logging
from homeassistant.components.hdmi_cec import CecDevice, ATTR_NEW
from homeassistant.components.switch import SwitchDevice, DOMAIN
from homeassistant.const import STATE_OFF, STATE_STANDBY, STATE_ON
from homeassistant.core import HomeAssistant
DEPENDENCIES = ['hdmi_cec']
_LOGGER = logging.getLogger(__name__)
ENTITY_ID_FORMAT = DOMAIN + '.{}'
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Find and return HDMI devices as switches."""
if ATTR_NEW in discovery_info:
_LOGGER.info("Setting up HDMI devices %s", discovery_info[ATTR_NEW])
add_devices(CecSwitchDevice(hass, hass.data.get(device),
hass.data.get(device).logical_address) for
device in discovery_info[ATTR_NEW])
class CecSwitchDevice(CecDevice, SwitchDevice):
"""Representation of a HDMI device as a Switch."""
def __init__(self, hass: HomeAssistant, device, logical):
"""Initialize the HDMI device."""
CecDevice.__init__(self, hass, device, logical)
self.entity_id = "%s.%s_%s" % (
DOMAIN, 'hdmi', hex(self._logical_address)[2:])
self.update()
def turn_on(self, **kwargs) -> None:
"""Turn device on."""
self._device.turn_on()
self._state = STATE_ON
def turn_off(self, **kwargs) -> None:
"""Turn device off."""
self._device.turn_off()
self._state = STATE_ON
def toggle(self):
"""Toggle the entity."""
self._device.toggle()
if self._state == STATE_ON:
self._state = STATE_OFF
else:
self._state = STATE_ON
@property
def is_on(self) -> bool:
"""Return True if entity is on."""
return self._state == STATE_ON
@property
def is_standby(self):
"""Return true if device is in standby."""
return self._state == STATE_OFF or self._state == STATE_STANDBY
@property
def state(self) -> str:
"""Cached state of device."""
return self._state