def row_to_state(row): """ Convert a databsae row to a state. """ try: return State(row[1], row[2], json.loads(row[3]), datetime.fromtimestamp(row[4])) except ValueError: # When json.loads fails _LOGGER.exception("Error converting row to state: %s", row) return None
def _process_config(scene_config): """ Process passed in config into a format to work with. """ name = scene_config.get('name') states = {} c_entities = dict(scene_config.get(CONF_ENTITIES, {})) for entity_id in c_entities: if isinstance(c_entities[entity_id], dict): state = c_entities[entity_id].pop('state', None) attributes = c_entities[entity_id] else: state = c_entities[entity_id] attributes = {} # YAML translates 'on' to a boolean # http://yaml.org/type/bool.html if isinstance(state, bool): state = STATE_ON if state else STATE_OFF else: state = str(state) states[entity_id.lower()] = State(entity_id, state, attributes) return SceneConfig(name, states)