I have no other custom_component.
This is my code:
import logging
import voluptuous as vol
# Import the device class from the component that you want to support
from homeassistant.components.light import ATTR_BRIGHTNESS, Light, PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv
import pyCIP.CIP as cip
_LOGGER = logging.getLogger(__name__)
CONF_SENDER_ID = 'sender_id'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_SENDER_ID): vol.All(cv.ensure_list, [vol.Coerce(int)]),
vol.Required(CONF_NAME): cv.string,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Crestron Light platform."""
sender_id = config.get(CONF_SENDER_ID)
lightname = config.get(CONF_NAME)
# Add devices
add_devices([CrestronLight(sender_id, lightname)])
class CrestronLight(cip.CIPHandler, Light):
"""Representation of a Crestron Light."""
def __init__(self, sender_id, lightname):
"""Initialize an CrestronLight."""
cip.CIPHandler.__init__(self)
self._on_state = False
self._sender_id = sender_id
self._lightname = lightname
@property
def name(self):
"""Return the display name of this light."""
return self._lightname
@property
def is_on(self):
"""Return true if light is on."""
return self._on_state
def turn_on(self, **kwargs):
"""Instruct the light to turn on.
"""
cip.CIPHandler.send_buttonpress(0x80ac)
#self._light.turn_on()
def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
cip.CIPHandler.send_buttonpress(0x80ac)
#self._light.turn_off()
def update(self):
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
"""
#self._light.update()
#self._state = self._light.is_on()