<s> """<STR_LIT>""" <EOL> import logging <EOL> import homeassistant . util . dt as dt_util <EOL> from homeassistant . components . light import ATTR_BRIGHTNESS , Light <EOL> from homeassistant . const import ( <EOL> ATTR_ARMED , ATTR_BATTERY_LEVEL , ATTR_LAST_TRIP_TIME , ATTR_TRIPPED , <EOL> STATE_OFF , STATE_ON ) <EOL> from homeassistant . components . vera import ( <EOL> VeraDevice , VERA_DEVICES , VERA_CONTROLLER ) <EOL> DEPENDENCIES = [ '<STR_LIT>' ] <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> def setup_platform ( hass , config , add_devices_callback , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> add_devices_callback ( <EOL> VeraLight ( device , VERA_CONTROLLER ) for device in VERA_DEVICES [ '<STR_LIT>' ] ) <EOL> class VeraLight ( VeraDevice , Light ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , vera_device , controller ) : <EOL> """<STR_LIT>""" <EOL> self . _state = False <EOL> VeraDevice . __init__ ( self , vera_device , controller ) <EOL> @ property <EOL> def brightness ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . vera_device . is_dimmable : <EOL> return self . vera_device . get_brightness ( ) <EOL> def turn_on ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if ATTR_BRIGHTNESS in kwargs and self . vera_device . is_dimmable : <EOL> self . vera_device . set_brightness ( kwargs [ ATTR_BRIGHTNESS ] ) <EOL> else : <EOL> self . vera_device . switch_on ( ) <EOL> self . _state = STATE_ON <EOL> self . update_ha_state ( True ) <EOL> def turn_off ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . vera_device . switch_off ( ) <EOL> self . _state = STATE_OFF <EOL> self . update_ha_state ( ) <EOL> @ property <EOL> def device_state_attributes ( self ) : <EOL> """<STR_LIT>""" <EOL> attr = { } <EOL> if self . vera_device . has_battery : <EOL> attr [ ATTR_BATTERY_LEVEL ] = self . vera_device . battery_level + '<STR_LIT:%>' <EOL> if self . vera_device . is_armable : <EOL> armed = self . vera_device . is_armed <EOL> attr [ ATTR_ARMED ] = '<STR_LIT:True>' if armed else '<STR_LIT:False>' <EOL> if self . vera_device . is_trippable : <EOL> last_tripped = self . vera_device . last_trip <EOL> if last_tripped is not None : <EOL> utc_time = dt_util . utc_from_timestamp ( int ( last_tripped ) ) <EOL> attr [ ATTR_LAST_TRIP_TIME ] = utc_time . isoformat ( ) <EOL> else : <EOL> attr [ ATTR_LAST_TRIP_TIME ] = None <EOL> tripped = self . vera_device . is_tripped <EOL> attr [ ATTR_TRIPPED ] = '<STR_LIT:True>' if tripped else '<STR_LIT:False>' <EOL> attr [ '<STR_LIT>' ] = self . vera_device . vera_device_id <EOL> return attr <EOL> @ property <EOL> def is_on ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _state <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _state = self . vera_device . is_switched_on ( ) </s>
