'Create object from a state_changed event.'

@staticmethod
def from_event(event):

    entity_id = event.data['entity_id']
    state = event.data.get('new_state')
    dbstate = States(entity_id=entity_id)
    if (state is None):
        dbstate.state = ''
        dbstate.domain = split_entity_id(entity_id)[0]
        dbstate.attributes = '{}'
        dbstate.last_changed = event.time_fired
        dbstate.last_updated = event.time_fired
    else:
        dbstate.domain = state.domain
        dbstate.state = state.state
        dbstate.attributes = json.dumps(dict(state.attributes), cls=JSONEncoder)
        dbstate.last_changed = state.last_changed
        dbstate.last_updated = state.last_updated
    return dbstate
