<s> """<STR_LIT>""" <EOL> import logging <EOL> import homeassistant . util . dt as dt_util <EOL> from homeassistant . helpers . entity import Entity <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> OPTION_TYPES = { <EOL> '<STR_LIT:time>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> TIME_STR_FORMAT = "<STR_LIT>" <EOL> def setup_platform ( hass , config , add_devices , discovery_info = None ) : <EOL> """<STR_LIT>""" <EOL> if hass . config . time_zone is None : <EOL> _LOGGER . error ( "<STR_LIT>" ) <EOL> return False <EOL> dev = [ ] <EOL> for variable in config [ '<STR_LIT>' ] : <EOL> if variable not in OPTION_TYPES : <EOL> _LOGGER . error ( '<STR_LIT>' , variable ) <EOL> else : <EOL> dev . append ( TimeDateSensor ( variable ) ) <EOL> add_devices ( dev ) <EOL> class TimeDateSensor ( Entity ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , option_type ) : <EOL> """<STR_LIT>""" <EOL> self . _name = OPTION_TYPES [ option_type ] <EOL> self . type = option_type <EOL> self . _state = None <EOL> self . update ( ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _state <EOL> @ property <EOL> def icon ( self ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:date>" in self . type and "<STR_LIT:time>" in self . type : <EOL> return "<STR_LIT>" <EOL> elif "<STR_LIT:date>" in self . type : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> time_date = dt_util . utcnow ( ) <EOL> time = dt_util . as_local ( time_date ) . strftime ( TIME_STR_FORMAT ) <EOL> time_utc = time_date . strftime ( TIME_STR_FORMAT ) <EOL> date = dt_util . as_local ( time_date ) . date ( ) . isoformat ( ) <EOL> hours , minutes , seconds = time_date . strftime ( '<STR_LIT>' ) . split ( '<STR_LIT::>' ) <EOL> beat = ( ( int ( seconds ) + ( int ( minutes ) * <NUM_LIT> ) + ( ( int ( hours ) + <NUM_LIT:1> ) * <EOL> <NUM_LIT> ) ) / <NUM_LIT> ) <EOL> if self . type == '<STR_LIT:time>' : <EOL> self . _state = time <EOL> elif self . type == '<STR_LIT:date>' : <EOL> self . _state = date <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _state = date + '<STR_LIT:U+002CU+0020>' + time <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _state = time + '<STR_LIT:U+002CU+0020>' + date <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _state = time_utc <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _state = '<STR_LIT>' . format ( beat ) </s>
